Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Rotation matrix from 2 vectors Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Marmakoide

May 30, 2005, 07:16 AM

Problem :
I have two 3D normalised vectors U and V, with the same magnitude. How the I can deduce the rotation matrix R that transform V to U ? The rotation axis could be UxV.

Any idea ? (My previous idea doesn't work, a sign problem or such)

 
Rui Martins

May 30, 2005, 09:24 AM

Google for "Cross Product".

It gives you de vector which is perpendicular two two other vectors.
Which in your case will be the axis used for rotation.

To find the Rotation matrix, you have to know:
- the angle which you can extract from the Cross Product definition.
- how to build a rotation matrix from a generic vector, check the formula or implementation used in OpenGL glRotate() function (take a look at the Mesa source code).

 
Marmakoide

May 30, 2005, 09:48 AM

I finally solve the problem this way :

N = VxU
matrix FROM = [V, N, VxN]
matrix TO = [U, N, UxN]
matrix ROT = TO * transpose(FROM)

It's okay if norm(N) != 0.
When V and U are colinear, norm(N) = 0.
if V=U, nothing to do
if V=-U, just a central point symetry

 
juhnu

May 30, 2005, 10:00 AM

I think he knows the cross-product already as he stated "The rotation axis could be UxV.".

Marmakoide, you can get the matrix quite easily by creating orthogonal bases for both vectors U and V and then getting the final matrix by finalRotationMatrix = Vbase-1 * Ubase. I think of it as first translating points from the world space into the Vbase then reinterpreting it as a UBase and transforming back to the world space.

....Or did I misunderstood the question?

You can create the orthogonal bases by using cross product two times. Something like Xvbase = VxU, Yvbase = V and Zvbase = XvbasexYvbase. Might be the signs are wrong.



juhani

 
Marmakoide

May 30, 2005, 10:02 AM

Yes, that is my final solution ;)

 
juhnu

May 30, 2005, 10:18 AM

Oh I was writing the reply for long too I guess :) Good you got it working.


 
This thread contains 6 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.