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

Inverse() public method

Computes the inverse of a Quaternion.
public Inverse ( ) : Quaternion
return Quaternion
		public Quaternion Inverse()
		{
			Real norm = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
			if ( norm > 0.0f )
			{
				Real inverseNorm = 1.0f / norm;
				return new Quaternion( this.w * inverseNorm, -this.x * inverseNorm, -this.y * inverseNorm, -this.z * inverseNorm );
			}
			else
			{
				// return an invalid result to flag the error
				return Quaternion.Zero;
			}
		}

Usage Example

Example #1
0
		/// <summary>
		/// Creates an inverse translation Matrix
		/// </summary>
		/// <param name="translation"></param>
		/// <param name="scale"></param>
		/// <param name="orientation"></param>
		/// <returns></returns>
		public static Matrix4 ComposeInverse( Vector3 translation, Vector3 scale, Quaternion orientation )
		{
			// Invert the parameters
			Vector3 invTranslate = -translation;
			Vector3 invScale = new Vector3( 1f / scale.x, 1f / scale.y, 1f / scale.z );
			Quaternion invRot = orientation.Inverse();

			// Because we're inverting, order is translation, rotation, scale
			// So make translation relative to scale & rotation
			invTranslate *= invScale; // scale
			invTranslate = invRot * invTranslate; // rotate

			// Next, make a 3x3 rotation matrix and apply inverse scale
			Matrix3 rot3x3, scale3x3;
			rot3x3 = invRot.ToRotationMatrix();
			scale3x3 = Matrix3.Zero;
			scale3x3.m00 = invScale.x;
			scale3x3.m11 = invScale.y;
			scale3x3.m22 = invScale.z;

			// Set up final matrix with scale, rotation and translation
			Matrix4 result = scale3x3 * rot3x3;
			result.Translation = invTranslate;

			return result;
		}
All Usage Examples Of Axiom.Math.Quaternion::Inverse