BEPUutilities.Quaternion.GetAxisAngleFromQuaternion C# (CSharp) Method

GetAxisAngleFromQuaternion() public static method

Computes the axis angle representation of a normalized quaternion.
public static GetAxisAngleFromQuaternion ( &q, BEPUutilities.Vector3 &axis, float &angle ) : void
q Quaternion to be converted.
axis BEPUutilities.Vector3 Axis represented by the quaternion.
angle float Angle around the axis represented by the quaternion.
return void
        public static void GetAxisAngleFromQuaternion(ref Quaternion q, out Vector3 axis, out float angle)
        {
#if !WINDOWS
            axis = new Vector3();
#endif
            float qx = q.X;
            float qy = q.Y;
            float qz = q.Z;
            float qw = q.W;
            if (qw < 0)
            {
                qx = -qx;
                qy = -qy;
                qz = -qz;
                qw = -qw;
            }
            if (qw > 1 - 1e-6)
            {
                axis = Toolbox.UpVector;
                angle = 0;
            }
            else
            {
                angle = 2 * (float)Math.Acos(qw);
                float denominator = 1 / (float)Math.Sqrt(1 - qw * qw);
                axis.X = qx * denominator;
                axis.Y = qy * denominator;
                axis.Z = qz * denominator;
            }
        }