From: Jonathan B. <jbr...@ea...> - 2006-03-28 16:13:01
|
On Mon, 2006-03-27 at 23:20 +0000, Miles Jacobs wrote: > I've tried to make VPython work with PyODE (http://pyode.sourceforge.net). > The blocks seem to collide properly but they often settle on their edges. I > probably misunderstand the rotation matrix provided by PyODE or the "up" > method of VPython. Both up and axis define the orientation of a VPython body ("angle" is not used for anything). See src/prim.cpp for the full story (there are some corner cases that the code follows to avoid degeneration). The following is a reasonable approximation of what happens in there: # Returns the direction cosine matrix of a VPython renderable body # The result is a right-handed 3x3 orthonormal matrix def DCM( renderable): z_axis = renderable.axis.cross( renderable.up).norm() y_axis = z_axis.cross( renderable.axis).norm() x_axis = renderable.axis.norm() # Can probably use Tensor here... ret = Numeric.array( shape=(3,3), type=Numeric.Float64) ret[:,0] = x_axis ret[:,1] = y_axis ret[:,2] = z_axis return ret # Set the orientation of a renderable object from a 3x3 direction # cosine matrix, while retaining scaling information on the Visual # object. # renderable: A VPython renderable object # DCM: A right-handed 3x3 orthonormal matrix # returns: None def move_renderable_from_DCM( renderable, DCM): renderable.axis = vector(DCM[:,0]) * renderable.axis.mag renderable.up = vector(DCM[:,1]) > Any help would be appreciated. The VPython "cubes" get > their positional and angular information from the PyODE "bodies". HTH, -Jonathan |