[ODE] Naive Pitch/Roll/Yaw rotation questions

Matthew Hancher mdh at email.arc.nasa.gov
Wed Mar 16 09:08:36 MST 2005


> If you have a body-relative vector (your roll axis) and want to
> transform it into world coordinates, you want to do a matrix-vector
> multiply of the body's orientation matrix and the vector.

I think this may answer a slightly different question than the one John
was trying to ask:

>> Now - howabout the inverse problem, of sorts: given an object's
>> quaternion, how do I find which global axis is currently the object's
>> "local" roll axis?

It sounds like maybe what you're really asking is how to figure out what
rotation axis and angle would put an object into a known orientation.
This is straightforward: there is a close relationship between an
orientation's quaternion and the corresponding rotation's axis+angle
representation.  The real component of the quaternion, w, is just the
cosine of half the rotation angle, and the imaginary/vector part of the
quaternion, (x,y,z), is the unit axis vector scaled by the sine of half
the rotation angle.  Turning that around, noting that ODE stores its
quaternions in (w,x,y,z) order, yields:

	dReal angle = 2 * atan2( sqrt(q[1]*q[1]+q[2]*q[2]+q[3]*q[3]), q[0] );
	dVector3 axis = { q[1], q[2], q[3] };
	dNormalize3( axis );

Enjoy!

mdh

Matt Hancher
NASA Ames Research Center
mdh at email.arc.nasa.gov



More information about the ODE mailing list