[Math] Extracting the Axis a Quaternion is rotating around from the Quaternion itself Directly

3dquaternionsrotationsvectors

Quaternion has components X, Y, Z, and W.
If you created a Quaternion with input being a 3D Vector representing the axis (X,Y,Z) and a floating point number representing the amount to rotate around that axis(W). Can you extract the X,Y, and Z components used to construct the Quaternion from the Quaternion itself.

I'm looking for a solution that would allow me to extract the original axis from the Quaternion which has already been multiplied by itself several times. (So the axis internally never changes from the input axis actually) As in, the amount I want to rotate around the axis that I initially stored in the Quaternion is no longer inside but the axis remains.

I am not looking for any solution that requires converting the Quaternion itself to a different representation first, like a Rotation Matrix.

Can this be done or does the 4D nature of Quaternions not allow this?

If this helps…

When creating the Quaternion you would do…

QUATERNION( const VECTOR<Q> &axis, const Q &angle )
{       
     Q a = angle / 2;
     Q sin_a = sin( a );
     this->w = cos( a );
     this->x = axis.x * sin_a;
     this->y = axis.y * sin_a;
     this->z = axis.z * sin_a;
     this->Normalize(); 
}

 void Normalize()
 {  
     Q m = ( x *x + y * y + z * z + w * w );

      if( m < 0.991 || m > 1.001 )
      {
          m = sqrt( m );
          x = x / m;
          y = y / m;
          z = z / m;
          w = w / m;
      }
 }

Best Answer

You can just read it directly. The pure quaternion part of the unit rotation quaternion is of the form $\sin(\theta/2)u$ where $u$ has unit length as a 3-vector and is the axis of rotation. Just normalize the pure quaternion part and you have it.