Run-E
December 5, 2003, 2:28am
1
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
December 5, 2003, 1:18pm
2
hello,
v1(x1,y1,z1)
v2(x2,y2,z2)
here is the calcul for the angle between this two vector :
axz= acos( ( x1x2 + 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
December 6, 2003, 2:25am
3
Thanks!
Now I can calculate the angle, but i still need to know the axis to rotate about… Any suggestions?
sebh
December 6, 2003, 2:34am
4
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.