Archived

This topic is now archived and is closed to further replies.

Lars W.

Getting the Matrix that transforms v1 to v2

Recommended Posts

Any particular API in mind? In OpenGL, at least (I''m sure D3D has something similar to this), you could compute the cross product of the two and rotate v1 around that vector by the angle between v1 and v2 (computed through the dot product). Technically this isn''t the fastest way, because you already have access to the sine and cosine of the angle, and OpenGL will go ahead and crunch the trig calls on the supplied angle, but it''s a lot simpler than deriving the transformation.

Share this post


Link to post
Share on other sites
Loqi has got it right but it sounds like he was saying you would end up with Euler angles at the end. That won''t be easy as the axis of rotation can be arbitrary.

But you can go directly to a matrix or quaternion instead. As was suggested, use the cross product to get a perpendicular axis. Use the dot product to get the angle to rotate around that axis. This is an axis-angle rep for a transformation. This can be easily changed to a quaternion or a matrix with some simple trig.

If you need to go to the euler angles from there, you will have to decompose the matrix into eulers based on whatever order of rotations you want.

I''ve got code on my website that does all these conversions. Email if you need it since it is buried in sample demos. jeffl@darwin3d.com

-Jeff

Share this post


Link to post
Share on other sites