public static Vector3f Transform(Vector3f vector, Quaternionf rotation) { var v = rotation * new Quaternionf(vector.X, vector.Y, vector.Z, 0) * Conjugate(rotation); return(new Vector3f(v.A, v.B, v.C)); }
/// <summary> /// Computes the argument of a quaternion and returns the result. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>The argument of value.</returns> public static float Argument(Quaternionf value) { return(Functions.Atan2(Absolute(Imaginary(value)), value.A)); }
/// <summary> /// Calculates the dot product (inner product) of two quaternions. /// </summary> /// <param name="left">First source quaternion.</param> /// <param name="right">Second source quaternion.</param> /// <returns>The dot product of the two quaternions.</returns> public static float Dot(Quaternionf left, Quaternionf right) { return(left.A * right.A + left.B * right.B + left.C * right.C + left.D * right.D); }
/// <summary> /// Computes the absolute value (or modulus or magnitude) of a quaternion and returns the result. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>The absolute value of value.</returns> public static float Absolute(Quaternionf value) { return(Functions.Sqrt(value.A * value.A + value.B * value.B + value.C * value.C + value.D * value.D)); }
/// <summary> /// Computes the conjugate of a quaternion and returns the result. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>The conjugate of value.</returns> public static Quaternionf Conjugate(Quaternionf value) { return(new Quaternionf(value.A, -value.B, -value.C, -value.D)); }
/// <summary> /// Return imaginary part of a quaternion. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>The imaginary part of a quaternion.</returns> public static Quaternionf Imaginary(Quaternionf value) { return(new Quaternionf(0, value.B, value.C, value.D)); }
/// <summary> /// Computes the absolute squared value of a quaternion and returns the result. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>The absolute squared value of value.</returns> public static float AbsoluteSquared(Quaternionf value) { return(value.A * value.A + value.B * value.B + value.C * value.C + value.D * value.D); }
/// <summary> /// Determines whether any components of a quaternion satisfy a condition. /// </summary> /// <param name="value">A quaternion.</param> /// <param name="predicate">A function to test each component for a condition.</param> /// <returns>true if any component of the quaternion passes the test in the specified /// predicate; otherwise, false.</returns> public static bool Any(Quaternionf value, Predicate <float> predicate) { return(predicate(value.A) || predicate(value.B) || predicate(value.C) || predicate(value.D)); }
/// <summary> /// Return real part of a quaternion. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>The real part of a quaternion.</returns> public static Quaternionf Real(Quaternionf value) { return(new Quaternionf(value.A, 0, 0, 0)); }
/// <summary> /// Determines whether all components of a quaternion satisfy a condition. /// </summary> /// <param name="value">A quaternion.</param> /// <param name="predicate">A function to test each component for a condition.</param> /// <returns>true if every component of the quaternion passes the test in the specified /// predicate; otherwise, false.</returns> public static bool All(Quaternionf value, Predicate <float> predicate) { return(predicate(value.A) && predicate(value.B) && predicate(value.C) && predicate(value.D)); }
/// <summary> /// Determines whether any component of a quaternion is non-zero. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>true if any components are non-zero; false otherwise.</returns> public static bool Any(Quaternionf value) { return(value.A != 0 || value.B != 0 || value.C != 0 || value.D != 0); }
/// <summary> /// Determines whether all components of a quaternion are non-zero. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>true if all components are non-zero; false otherwise.</returns> public static bool All(Quaternionf value) { return(value.A != 0 && value.B != 0 && value.C != 0 && value.D != 0); }
/// <summary> /// Returns a value that indicates whether two quaternions are equal. /// </summary> /// <param name="left">The first quaternion to compare.</param> /// <param name="right">The second quaternion to compare.</param> /// <returns>true if the left and right are equal; otherwise, false.</returns> public static bool Equals(Quaternionf left, Quaternionf right) { return(left == right); }
/// <summary> /// Subtracts one quaternion from another and returns the result. /// </summary> /// <param name="left">The value to subtract from (the minuend).</param> /// <param name="right">The value to subtract (the subtrahend).</param> /// <returns>The result of subtracting right from left (the difference).</returns> public static Quaternionf Subtract(Quaternionf left, Quaternionf right) { return(new Quaternionf(left.A - right.A, left.B - right.B, left.C - right.C, left.D - right.D)); }
/// <summary> /// Adds two quaternions and returns the result. /// </summary> /// <param name="left">The first value to add.</param> /// <param name="right">The second value to add.</param> /// <returns>The sum of left and right.</returns> public static Quaternionf Add(Quaternionf left, Quaternionf right) { return(new Quaternionf(left.A + right.A, left.B + right.B, left.C + right.C, left.D + right.D)); }
/// <summary> /// Returns the additive inverse of a quaternion. /// </summary> /// <param name="value">A quaternion.</param> /// <returns>The negative of value.</returns> public static Quaternionf Negative(Quaternionf value) { return(new Quaternionf(-value.A, -value.B, -value.C, -value.D)); }