#### Archived

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

# Getting the Matrix that transforms v1 to v2

This topic is 6799 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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 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 on other sites
Thanks

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

Lars

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 19
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633362
• Total Posts
3011531
• ### Who's Online (See full list)

There are no registered users currently online

×