#### Archived

This topic is now archived and is closed to further replies.

# Angle around an Axis from Quaternion

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

## Recommended Posts

Hi, Does anyone know how to get an angle around an abitrary axis from a quaternion? (Does anyone know if this is possible?) Cheers Fleejay

##### Share on other sites
It is practically the easiest thing to do with a quaternion.

Angle: acos(w * 2);
Axis = q[x y z] / sqrt(1 - w*w)

##### Share on other sites

What I want to be able to do is pass in a vector and get the angle around that vector.

For example to get the angle a character is facing in the world I''d want to pass in the Y-axis, (0, 1, 0), and get out the angle.

I know this can be done for all the primary axis(es?) by converting the quaternion into a matrix and then getting the rotation from that matrix, but I''d like to be able to do it for any given vector.

Fleejay

##### Share on other sites
The simplest method is probably to convert the quaternion to an axis/angle, find the dot product of the axis and your target axis, and multiply the resultant scalar by the angle. But it''s fairly late, so I could be talking out of my ass. Anyone with some lucidity wanna chime in?

How appropriate. You fight like a cow.

##### Share on other sites
I''ve finally had chance to test this method and unfortunately it doesn''t give the correct results. I tested it against a GetAngleAroundYFromQuat() function which I know provides the right angle and although most of the values where close none of them were exactly right.

Any other ideas would be greatfully received!

Fleejay

##### Share on other sites
Every thing that you need is descreaben in the Ken Shoemake tutorial availible on the net:

ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z

There in the end of tutorial provided the calculation of rotation about arbitrary axis.

1. 1
2. 2
3. 3
Rutin
16
4. 4
JoeJ
13
5. 5

• 10
• 9
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632646
• Total Posts
3007637
• ### Who's Online (See full list)

There are no registered users currently online

×