BEPUutilities.Toolbox.GetAxisAngleFromQuaternion C# (CSharp) 메소드

GetAxisAngleFromQuaternion() 공개 정적인 메소드

Computes the axis angle representation of a normalized quaternion.
public static GetAxisAngleFromQuaternion ( Quaternion &q, System.Vector3 &axis, float &angle ) : void
q Quaternion Quaternion to be converted.
axis System.Vector3 Axis represented by the quaternion.
angle float Angle around the axis represented by the quaternion.
리턴 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-12)
            {
                axis = 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;
            }
        }