Archived

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

hansi pirman

how to find the tree rotation angles to get one vector out of another ? (please help)

Recommended Posts

hi there ! I'm searching the net sience many hours, but i havent found the solution for my problem. I have the following problem: I have two 3D Vectors.. let's say v1 and v2. now i want to find the x,y and z rotation angles i need get v2 out of v1. so i can do a v1.rotateX(x); v1.rotateY(y); v1.rotateZ(z); and get v2. both vectors are nomalized.. i know i can get the angle between 2 vectors with acos(v1 dot v2/|v1|*|v2|) but I want the 3 rotation angles for the x,y and z axis and not only one. i also tried to drop one component to get the paricular rotation angle, i.e. to get y rotation: v1.y=0; v1.normalize(); v2.y=0; v2.normalize(); v1.getAngleBetween(v2); this did work, but only in some very limeted cases i hope somebody can help me ! thanks in advance ! regards hansi pirman [edited by - hansi pirman on November 4, 2002 12:41:13 PM]

Share this post


Link to post
Share on other sites
no, it''s definitely possible. one way is to use quaternions and spherical linear interpolation - SLERP http://www.gamedev.net/reference/articles/article1199.asp
that''ll give you a really pretty parametric equation which you can then use to smoothly transition between the 2 vectors.

otherwise google around using ''interpolation'' as one of your keywords. i have no other reference boiling off the top of my head at the moment

-me

Share this post


Link to post
Share on other sites
oh, and also remember that the order of your rotations is MASSIVELY important in 3D space. xyz rotation angles of 30, 40 & 50 degrees, respectively, can result in several different vectors depending on the order in which you apply the rotations.

um. another way that i''ve given about 10sec of thought towards is to just figure out the xyz rotations necessary to get each of the 2 vectors from say the positive x-axis. then do a subtraction to get the difference in the various angles between the vectors. but my first paragraph of info is going to have some kind of bearing on using this method (perhaps even invalidating it). so play around

-me

Share this post


Link to post
Share on other sites
Thanks very much for your answer !!
but it sound''s somewhat complicated
maybe i''ll try it with this "quaterniton" and "slerp" stuff at the weekend!

but i''ll be happy too if someone could post some other (maybe simpler way) of doing this..
thanks

Share this post


Link to post
Share on other sites

Here''s another way:

You can convert x y and z coords to polar coordinates (longitude and latitude) using the following equations:

r = sqrt(x*x + y*y + z*z) ( which = 1 if normalised)
a1 = atan(z/sqrt(x*x+y*y))
a2 = atan(y / x)

Reference:
http://itc.utk.edu/itc/grants/twt2000/modules/mbreinig/3dcoordinates.htm

Here a2 is the rotation around the z axis, and a1 is the rotation around the y. It is important to rotate around the y axis first.

Therefore, to find the z and y angles between vectors, convert to polar first and then find the difference between the two.

Rotation around the x axis (roll) is not needed, unless you want to shift a 3d dimensional object instead a vector (a vector is a point and therefore has no "up" direction). For that you will need a normal vector at the two points.

If you are using this for interpolation though, you probably should check out quaternions as Palidine suggested.

Hopes this helps.


Share this post


Link to post
Share on other sites
hi psylent !

thank you very much for the answer !

but there''s something i do not understand...
you write:
"Rotation around the x axis (roll) is not needed, unless you want to shift a 3d dimensional object instead a vector (a vector is a point and therefore has no "up" direction). For that you will need a normal vector at the two points. "

isn''t roll a rotation about the z axis ?
i want to use this equation for my camera code, so at least the x and y axis rotations are requied, z would be usefull to maybe..


Share this post


Link to post
Share on other sites
ah....
the axes on the url you submitted where organized in another way i have it.
so i swapped some variables and it works now...
expect in one case:

if the rotation gets >90° or <90° strange things happen. its just "flickering" at the same rotation position..
i know i have to check some signs and change the rotation angle depending on it, but i have tried some, but it dosn''t alway work as expected..
here some parts my camera code:

void Camera::lookAt(Vector vPoint) {
Vector vFacingNew = vPoint - m_vPosition;
vFacingNew.normalize();

// update rotation angle Member Vars
m_xRot = rad2grad(atan(vFacingNew.y/sqrt(vFacingNew.z*vFacingNew.z+vFacingNew.x*vFacingNew.x)));
m_yRot = rad2grad(atan(vFacingNew.x / vFacingNew.z));


/* here is some code needed, that m_xRot and m_yRot have working values on rotations > or < 90° */

}

can anybode help me with this problem please ?

thanks in advance !



Share this post


Link to post
Share on other sites
quote:
Original post by hansi pirman
isn''t roll a rotation about the z axis ?


There are probably different conventions. "Roll" for an airplane is defined about the x axis, and "Yaw" is defined about the z axis.



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
quote:
Original post by hansi pirman
if the rotation gets >90° or <90° strange things happen. its just "flickering" at the same rotation position..



There is a mathematical discontinuity at pi/2 when you use roll/pitch/yaw, which causes the flicker.

You should go ahead and explore Palidine''s solution of quaternions and slerp in order to avoid this flicker problem.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thanks for all answers again!

@StarGamer_Nick:

dosn''t the dot product return the length of a vector ??
how can i get angles with this ?

please post some code, formulas, thanks !

Share this post


Link to post
Share on other sites
thanks for all answers again!

@StarGamer_Nick:

dosn''t the dot product return the length of a vector ??
how can i get angles with this ?

please post some code, formulas, thanks !



(ops double post, something went wrong..)

Share this post


Link to post
Share on other sites