Axiom.Math.Quaternion.FromAngleAxis C# (CSharp) Method

FromAngleAxis() public static method

Creates a Quaternion from a supplied angle and axis.
public static FromAngleAxis ( Real angle, Vector3 axis ) : Quaternion
angle Real Value of an angle in radians.
axis Vector3 Arbitrary axis vector.
return Quaternion
		public static Quaternion FromAngleAxis( Real angle, Vector3 axis )
		{
			Quaternion quat = new Quaternion();

			Real halfAngle = 0.5f * angle;
			Real sin = Utility.Sin( halfAngle );

			quat.w = Utility.Cos( halfAngle );
			quat.x = sin * axis.x;
			quat.y = sin * axis.y;
			quat.z = sin * axis.z;

			return quat;
		}

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Combines the euler angles in the order yaw, pitch, roll to create a rotation quaternion
        /// </summary>
        /// <param name="pitch"></param>
        /// <param name="yaw"></param>
        /// <param name="roll"></param>
        /// <returns></returns>
        public static Quaternion FromEulerAngles(Real pitch, Real yaw, Real roll)
        {
            return(Quaternion.FromAngleAxis(yaw, Vector3.UnitY)
                   * Quaternion.FromAngleAxis(pitch, Vector3.UnitX)
                   * Quaternion.FromAngleAxis(roll, Vector3.UnitZ));

            /*TODO: Debug
             * //Equation from http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm
             * //heading
             *
             * Real c1 = (Real)Math.Cos(yaw/2);
             * Real s1 = (Real)Math.Sin(yaw/2);
             * //attitude
             * Real c2 = (Real)Math.Cos(roll/2);
             * Real s2 = (Real)Math.Sin(roll/2);
             * //bank
             * Real c3 = (Real)Math.Cos(pitch/2);
             * Real s3 = (Real)Math.Sin(pitch/2);
             * Real c1c2 = c1*c2;
             * Real s1s2 = s1*s2;
             *
             * Real w =c1c2*c3 - s1s2*s3;
             * Real x =c1c2*s3 + s1s2*c3;
             * Real y =s1*c2*c3 + c1*s2*s3;
             * Real z =c1*s2*c3 - s1*c2*s3;
             * return new Quaternion(w,x,y,z);*/
        }
All Usage Examples Of Axiom.Math.Quaternion::FromAngleAxis