Jump to content
  • Advertisement
Sign in to follow this  
alta

use of quaternions

This topic is 3610 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

If you have an object that has a location defined by a 3-vector and an orientation defined by a quaternion, how do you change the quanternion so as to rotate the object about an arbitrary axis by some angle? It seems like a staight forward question but I am having a hard time finding an answer. I am not too familiar with quaternions so maybe I am trying to do something that is not possible? Anyone know?

Share this post


Link to post
Share on other sites
Advertisement
Here is a method that worked for me:

Create a quaternion from the axis of rotation and the angle of rotation. Note that this angle should indicate "how much to rotate", not the "total" rotation from the origin.

If this axis represents an axis in world space, you would do:

objectOrientation = rotationQuat * objectOrientation;

If the axis is in object space, you would do:

objectOrientation *= rotationQuat;

Remember that quaternion multiplication is "reversed" - q1 * q2 is the transformation represented by q2 followed by the transformation represented by q1.

This thread (starting roughly from that post) explains the reasoning behind this entire procedure.

Share this post


Link to post
Share on other sites
Assuming your arbitrary axis is normalized, the corresponding quaternion for the rotation about the axis for an angle theta is:

w = cos(theta / 2)
x = sin(theta / 2) * axis.x
y = sin(theta / 2) * axis.y
z = sin(theta / 2) * axis.z

Share this post


Link to post
Share on other sites
So if my object is at the origin with orientation (p1,p2,p3,p4)and I want to rotate it about the vector (x,y,z) an angle theta then I would calculate the following:

q1=cos(theta/2);
q2=sin(theta/2)*x;
q3=sin(theta/2)*y;
q4=sin(theta/2)*z;

p1=p1*q1-p2*q2-p3*q3-p4*q4;
p2=p1*q2+p2*q1+p3*q4-p4*q3;
p3=p1*q3-p2*q4+p3*q1+p4*q2;
p4=p1*q4+p2*q3-p3*q2+p4*q1;


Is that correct??

Share this post


Link to post
Share on other sites
Quote:
p1=p1*q1-p2*q2-p3*q3-p4*q4;
p2=p1*q2+p2*q1+p3*q4-p4*q3;
p3=p1*q3-p2*q4+p3*q1+p4*q2;
p4=p1*q4+p2*q3-p3*q2+p4*q1;
Assuming you've implemented quaternion multiplication correctly and that you're multiplying in the right order, then that should work. (I didn't check your multiplication code for correctness.)

Oh, and I'm guessing the above is just an example, but in your actual code, be sure not to overwrite the values of the original quaternion ('p', in this case) as you go :)

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!