• Create Account

## quaternion to axis-angle and back

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1RenderCache  Members

133
Like
0Likes
Like

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.
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

### #2Dmytry  Members

1150
Like
0Likes
Like

Posted 01 April 2005 - 07:02 AM

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.

### #3Daerax  Members

1207
Like
0Likes
Like

Posted 01 April 2005 - 07:45 AM

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

### #4RenderCache  Members

133
Like
0Likes
Like

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

### #5Sneftel  Senior Moderators

1788
Like
0Likes
Like

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.

### #6JohnBolton  Members

1372
Like
0Likes
Like

Posted 01 April 2005 - 01:04 PM

You need to check for if the length of the vector is 0.

John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

### #7Daerax  Members

1207
Like
0Likes
Like

Posted 01 April 2005 - 04:39 PM

Quote:
 Original post by JohnBoltonYou 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);//hardcodedfloat 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 backfloat angle2;D3DXVECTOR3 axis2;D3DXQuaternionToAxisAngle(&quat,&axis2,&angle2);D3DXVec3Normalize(&axis2,&axis2); //Now they are equal in all ways

### #8RenderCache  Members

133
Like
0Likes
Like

Posted 01 April 2005 - 11:55 PM

hi!
thx so much!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.