Rotation matrix to unit direction vector

5,372 views
Skip to first unread message

Marc "Foddex" Oude Kotte

unread,
Sep 13, 2008, 4:03:59 AM9/13/08
to ode-...@googlegroups.com
Hello,

My application works with unit direction vectors internally. Now that
I'm trying to integrate ODE, I have to convert rotation matrices back to
direction vectors after every frame. I am definitely not a math major so
I'm having some troubles with this.

Converting a rotation matrix for a single rotation of "a" degrees around
the Z-axis is easy enough, as this becomes:

cos(a) -sin(a) 0
sin(a) cos(a) 0
0 0 1

And working your way from there to get a direction vector isn't too
hard. However, obviously ODE's rotation matrices are combinations of
multiple rotations around multiple axes. I'm really lost on how to
convert such a 'complex' rotation matrix back to a unit direction
vector.

Can anyone on this list help me out? Couldn't find the answer using
google :(

Thanks a lot in advance!

Cheers,
Marc


Mikko Rasa

unread,
Sep 13, 2008, 5:49:36 AM9/13/08
to ode-...@googlegroups.com

It's rather simple actually. You just need to perform a matrix-vector
multiplication. With a unit vector oriented along a coordinate axis,
this is reduced to extracting a single column from the matrix. In fact,
the columns of the matrix can be viewed as the unit X, Y and Z vectors
of the rotated space.

ODE provides an even simpler solution though. You can use the
dBodyVectorToWorld function, as documented here:

http://opende.sourceforge.net/mediawiki-1.6.10/index.php/Manual_%28Rigid_Body_Functions%29#Utility

--
Mikko Rasa "The DataBeaver"

Peter Newman

unread,
Sep 13, 2008, 5:56:19 AM9/13/08
to ode-...@googlegroups.com
By a direction vector, you mean a vector pointing "forward", right?

I think the process you are looking for is converting a rotation
matrix to a "angle axis", although you may not be using the angle
portion, just the axis (the forward). A good reference site is:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
, which will provide you with both an explanation of the maths, and
reference code (in Java).

Just a note that you will be missing one form of possible rotation by
only using the axis. But if your system is pseudo-2d (all things use a
constant "up") then I imagine it would be ok.

Peter N

Jon Watte

unread,
Sep 13, 2008, 1:08:57 PM9/13/08
to ode-...@googlegroups.com

Check out the "matrix and quaternion FAQ"

However, a single "rotation vector" is not enough to fully determine the
rotation of an object in 3D; at a minimum you also need an assumed "up"
vector. However, in ODE, "up" for the object will change as it tumbles,
so there is no conversion between a single rotation vector and a full
rotation. You will have to change your system to use full rotations
(quaternions or matrices).

Sincerely,

jw


Marc "Foddex" Oude Kotte wrote:

Reply all
Reply to author
Forward
0 new messages