Jump to content
  • Advertisement
Sign in to follow this  
RenderCache

quaternion to axis-angle and back

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

ok! i was playing ard with the conversions and i wonder if converting from axis angle to quaternion and back will get back the original axis angle. below is the small source which i am working on, but i couldnt seem to see what was wrong. I jus dun get back the original values. would be grateful if someone help to look at it.
D3DXQUATERNION quat;
D3DXQuaternionIdentity(&quat);

D3DXVECTOR3 rot_axis(0.5f,1.2f,0.3f);//hardcoded
float angle = D3DXVec3Length(&rot_axis);
float halfangle = angle/2.0f;
D3DXVec3Normalize(&rot_axis,&rot_axis);

float sine_halfangle = sin(halfangle);
quat.x = sine_halfangle * rot_axis.x;
quat.y = sine_halfangle * rot_axis.y;
quat.z = sine_halfangle * rot_axis.z;
quat.w = cos(halfangle);
D3DXQuaternionNormalize(&quat,&quat);

//try to convert it back
float angle2;
D3DXVECTOR3 axis2;
D3DXQuaternionToAxisAngle(&quat,&axis2,&angle2);

thx! RC

Share this post


Link to post
Share on other sites
Advertisement
you could get back -angle and -axis. (opposite axis and opposite angle). That's exactly same turn. Also, if your angle is bigger than pi, you'll get back different angle, as angle (pi+something ) is the same as angle -pi-something.

Share this post


Link to post
Share on other sites
Your code seems correct from over here. Except, I dont understand why the angle of the vector is equal to its Magnitude or length.

Share this post


Link to post
Share on other sites
Angular velocity can be expressed in axis-angle notation and quaternion notation (and matrix notation and euler notation and that other weird magnitude-based notation) just like angle, but that doesn't mean that you take a quaternion representing an angle and turn it into an axis/angle representing angular velocity. It still represents an angle.

Angular velocity specifies velocity of rotation. If my bike wheel is revolving at one rotation per second, its angular velocity is 2π radians per second.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBolton
You need to check for if the length of the vector is 0.

That was something I checked first, the || rot_axis || = 1.334 or something, so regardless of the [or lack of] physical relevance of the way the angle is set, the angle given seems fine.

Anyway I plugged your code into my engine real quick and looked at the output. It worked. What was wrong was one of those silly mistakes that catches us all. The angle returned by D3DXQuaternionToAxisAngle() was equal to that of rot_axis implying that they were parallel to each other, rot_axis || axis2. The only thing wrong was that D3DXQuaternionToAxisAngle() did not return a unit vector. Renormalizing axis2 will make it equal to rot_axis.

This should fix it:

D3DXQUATERNION quat;
D3DXQuaternionIdentity(&quat);

D3DXVECTOR3 rot_axis(0.5f,1.2f,0.3f);//hardcoded
float angle = D3DXVec3Length(&rot_axis);
float halfangle = angle/2.0f;
D3DXVec3Normalize(&rot_axis,&rot_axis);

float sine_halfangle = sin(halfangle);
quat.x = sine_halfangle * rot_axis.x;
quat.y = sine_halfangle * rot_axis.y;
quat.z = sine_halfangle * rot_axis.z;
quat.w = cos(halfangle);
D3DXQuaternionNormalize(&quat,&quat);

//try to convert it back
float angle2;
D3DXVECTOR3 axis2;
D3DXQuaternionToAxisAngle(&quat,&axis2,&angle2);
D3DXVec3Normalize(&axis2,&axis2); //Now they are equal in all ways

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!