Jump to content
  • Advertisement
Sign in to follow this  
DMINATOR

2 axis angles difference ?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well i just encountered following problem: For example I have base rotation of object (angle1 , x1 , y1 , z1). Then object is rotated to the new angle (angle2 , x2 , y2 , z2) , note that x1!=x2, y1 != y2 and z1 != z2 . What I need to find is the difference between angles , and move the object by this difference. How can I do that ? Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
I don't understand your problem. Please, describe it in more detail. What do you mean by "base rotation"? What do "angle1", "x1", "y1" and "z1" mean?

A particular example with concrete numbers might help too.

Share this post


Link to post
Share on other sites
This can be done using quaternions:
quaternion q represents the base rotation/current rotation
quaternion r is the new axis-angle, the one you wish to rotate to
quaternion d is the difference between them, so that
q·d = r
q-1·q·d = q-1·r
d = q-1·r
where q-1 is the inverse of q. You can then build a rotation matrix from this, or transform the point directly using
p' = d · p · d-1
p - vector before transformation
p' - vector after transformation
(note: to multiply a vector with a quaternion, you simply see it as a quaternion with a real component of 0)

For unit quaternions, calculating the inverse simplifies to the conjugate
d = q*·r
p' = d · p · d*

Another way of doing it would be to unrotate (angle1, x1, y1, z1) and then rotate by (angle2, x2, y2, z2). Or to just store the unrotated coordinates.

Share this post


Link to post
Share on other sites
There are multiple solutions to this problem, but here is one solution.

Calculate the normal to the plane formed by the two axis. That is the cross product of the unit vectors of (x1,y1,z1) and (x2,y2,z2). Then calculate the angle between the two vectors. The dot product of two unit vectors is the cosine of that angle. If you didn't know, the unit vector is a vector which has a length of 1.0.

Pseudocode:
v1 = (x1, y1, z1) and v2 = (x2, y2, z2) are assumed to have a length of 1.0
v = v1 x v2
( now v is (y1*z2 - z1*y2, z1*x2 - x1*z2, x1*y1 - y1*x2) )
a = acos(v1 - v2)
( a = acos(x1*x2+y1*y2+z1*z2) )
note that a is in radians, per default. OpenGL wants degrees as parameter.
now rotate a degrees around axis v

I did not double check all the formulas, but MathWorld is your friend.

As said above, Quaternions can be used to do the trick. So can many other methods. Quaternions are probably the most powerful, but they require some extra coding if you need just a simple rotation.

-Richardo

EDIT: I am sorry, this is not quite what you wanted. This is a rotation that maps a vector to another vector. Use quaternions. there are plenty of quaternion tutorials on the net. I particularly like the matrix&quaternion faq in the articles section of gamedev.net

Share this post


Link to post
Share on other sites
Thank you all for the help. Although I have found a different solution your comments helped me to get a better understanding about this problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!