Afterglow.Math.Quaternion.ToAxisAngle C# (CSharp) Method

ToAxisAngle() public method

Returns the axis angle representation in a Vector4. The x, y and z componentes are the axis and w is the angle.
public ToAxisAngle ( ) : Vector4
return Vector4
        public Vector4 ToAxisAngle()
        {
            var angle = 2 * Functions.Acos(mValues.W);
            var length = Functions.Sqrt(1 - mValues.W * mValues.W);

            return new Vector4(mValues.ToVector3() / length, angle);
        }

Usage Example

Example #1
0
        public void ToAxisAngle()
        {
            Vector3 rotationAxis = Vector3.ZAxis;
            var angle = Constants.HALF_PI;

            var quaternion = new Quaternion(rotationAxis, angle);

            Vector4 axisAngle = quaternion.ToAxisAngle();

            axisAngle.X.ShouldEqual(rotationAxis.X);
            axisAngle.Y.ShouldEqual(rotationAxis.Y);
            axisAngle.Z.ShouldEqual(rotationAxis.Z);
            axisAngle.W.ShouldEqual(angle);
        }