Advertisement Jump to content
Sign in to follow this  

Quaternion - Axis/Angle

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

Is it possible to take a rotation defined as a quaternion and extract the equivalent axis/angle rotation definition? If so, how would you go about doing this?

Share this post

Link to post
Share on other sites
It is quite easy.

axis = quat.x, quat.y, quat.z
angle = 2 * arcos(quat.w)

You may want to normalize the axis, depending on your needs.

Share this post

Link to post
Share on other sites

create a unit quaternion rotating by axis angle representation
inline void unit_from_axis_angle(const vector3& axis, const float& angle){
vector3 v(axis);
float half_angle = angle*0.5f;
float sin_a = (float)sin(half_angle);
set(v.x*sin_a, v.y*sin_a, v.z*sin_a, (float)cos(half_angle));
convert a quaternion to axis angle representation,
preserve the axis direction and angle from -PI to +PI
inline void to_axis_angle(vector3& axis, float& angle)const {
float vl = (float)sqrt( x*x + y*y + z*z );
if( vl > TINY )
float ivl = 1.0f/vl;
axis.set( x*ivl, y*ivl, z*ivl );
if( w < 0 )
angle = 2.0f*(float)atan2(-vl, -w); //-PI,0
angle = 2.0f*(float)atan2( vl, w); //0,PI
axis = vector3(0,0,0);
angle = 0;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!