Getting the Matrix that transforms v1 to v2

Started by
2 comments, last by Lars W. 24 years ago
hi I need way to compute the Matrix, that Transforms a given Vector v1 into another given Vector v2. (Would be good when it goes fast) Lars
--------> http://www.larswolter.de <---------
Advertisement
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.
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
Thanks

That was what i needed !
I think (hope) i don''t need the Euler Angles, the Matrix should be enough.

Lars
--------> http://www.larswolter.de <---------

This topic is closed to new replies.

Advertisement