PDA

View Full Version : Finding rotation vector and angle



Run-E
12-05-2003, 03:28 AM
Hi!
I'm using spherical coordinates to move an object that looks like an arrow around the origo. I want to rotate the arrow so that it always points to the origo.

How do I find the vector to rotate the arrow-object about and how do I calculate the angle of rotation?

Thanks in advance!

sebh
12-05-2003, 02:18 PM
hello,

v1(x1,y1,z1)
v2(x2,y2,z2)

here is the calcul for the angle between this two vector :

axz= acos( ( x1*x2 + y1*y2 + z1*z2) )
( ------------------------ )
( norm(v1) * norm(v2) )

where norm(v1)=sqrt(x1^2 + y1^2 + z1^2 )
where norm(v2)=sqrt(x2^2 + y2^2 + z2^2 )

You can get the angle in the xz plane by delete all references to the y component.

I hope it will help you.....

Run-E
12-06-2003, 03:25 AM
Thanks!
Now I can calculate the angle, but i still need to know the axis to rotate about... Any suggestions?

sebh
12-06-2003, 03:34 AM
If i were you, i would calculate the angle in the xz and yz and plane and then launch these opengl command:

glRotatef(axz,0,1,0);
glRotatef(ayz,1,0,0);

2 plane rotation are enought to rotae in space.
After these rotate the model to his position.