2

SHORT QUESTION: I'd like to draw different shapes using winged egde strucutre, so I have one class that actually draw any winged eged and another to define a cube and other shapes. Now I want to draw 2 cubes on the same figure but I can't and I always get one cube in each figure.

LONG QUESTION: I'd like to draw different shapes using winged egde strucutre, so I have:

class WEdge -> wedge_instance = WEdge(vertices, faces) 

and then I have one class for each shape that I need to draw for example:

class Box -> simplebox = Box(vertices, faces, translation, rotation)

In the WEdge class I actually plot the objects using the following code:

        ax = a3.Axes3D(pl.figure())
        for k in range(self.nFaces):
           currentColumn = self.faces[k,:]
           vtx = np.zeros([4,3])
           j = 0
           for i in currentColumn:
               vtx[j] = self.vertices[i-1]
               j = j +1
        tri = a3.art3d.Poly3DCollection([vtx])
        tri.set_color(colors.rgb2hex(sp.rand(3)))
        tri.set_edgecolor('b')
        ax.add_collection3d(tri)  

The problem is when I want to draw two cube in the same figure. I have tried many possible combinations of hold, gca and so on but in the end I get always one cube in Figure 1 and the other in Figure 2.

Example:

>>>Box(3,1,3, [0,1,0], np.eye(3))
>>> # hold, gca, timer...
>>>Box(3,1,3, [1,0,3], np.eye(3))

Box(3,1,3, [0,1,0], np.eye(3)Box(3,1,3, [1,0,3], np.eye(3)

1 Answer 1

2

Don't define a new axis for each "structure":

    ax = a3.Axes3D(pl.figure())

Pass ax into the WEdge class, so they can all draw on the same axis:

def init(self, ..., ax=None):
    self.ax = ax if ax else a3.Axes3D(pl.figure())

we1 = WEdge()
we2 = WEdge(ax=we1.ax)

or perhaps more egalitarian,

ax = a3.Axes3D(pl.figure())
we1 = WEdge(ax)
we2 = WEdge(ax)

You may need to also pass ax to your cube class too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.