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);

**0**

# quaternion to axis-angle and back

Started by Apr 01 2005 02:34 AM

,
7 replies to this topic

###
#1
Members - Reputation: **133**

Posted 01 April 2005 - 02:34 AM

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.
thx!
RC

###
#4
Members - Reputation: **133**

Posted 01 April 2005 - 11:15 AM

hi!

i thot the angle calculated is known as the 'angular velocity'

i took from this webpage:

Martin Baker's Angular Velocity webpage

is there something wrong when using it?

thx!

RC

i thot the angle calculated is known as the 'angular velocity'

i took from this webpage:

Martin Baker's Angular Velocity webpage

is there something wrong when using it?

thx!

RC

###
#5
Senior Moderators - Reputation: **1788**

Posted 01 April 2005 - 11:36 AM

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.

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.

###
#7
Members - Reputation: **1207**

Posted 01 April 2005 - 04:39 PM

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