public static Vector3d Transform(Vector3d vector, Quaterniond rotation) { var v = rotation * new Quaterniond(vector.X, vector.Y, vector.Z, 0) * Conjugate(rotation); return(new Vector3d(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 double Argument(Quaterniond 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 double Dot(Quaterniond left, Quaterniond 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 double Absolute(Quaterniond 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 Quaterniond Conjugate(Quaterniond value) { return(new Quaterniond(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 Quaterniond Imaginary(Quaterniond value) { return(new Quaterniond(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 double AbsoluteSquared(Quaterniond 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(Quaterniond value, Predicate <double> 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 Quaterniond Real(Quaterniond value) { return(new Quaterniond(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(Quaterniond value, Predicate <double> 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(Quaterniond 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(Quaterniond 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(Quaterniond left, Quaterniond 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 Quaterniond Subtract(Quaterniond left, Quaterniond right) { return(new Quaterniond(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 Quaterniond Add(Quaterniond left, Quaterniond right) { return(new Quaterniond(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 Quaterniond Negative(Quaterniond value) { return(new Quaterniond(-value.A, -value.B, -value.C, -value.D)); }