Class Quaternion

java.lang.Object
com.irurueta.geometry.Rotation3D
com.irurueta.geometry.Quaternion
All Implemented Interfaces:
Serializable, Cloneable

public class Quaternion extends Rotation3D implements Serializable, Cloneable
Contains a representation of a 3D rotation in a more precise and compact way than in matrix notation. This implementation of a quaternion contains values in the basis 1, i, j, k expressed as (a, b, c, d). a value is related only to the rotation angle, while b, c, d values are related both to the rotation axis and the rotation angle.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private double
    Value corresponding to real numbers basis.
    static final double
    Threshold of axis norm to convert quaternions to axis and rotation angle.
    private double
    Value corresponding to basis i.
    private double
    Value corresponding to basis j.
    private double
    Value corresponding to basis k.
    static final double
    Large threshold of axis norm to convert quaternions to axis and rotation angle.
    static final int
    Number of euler angles.
    static final int
    Number of parameters contained in a quaternion.
    private boolean
    Indicates whether quaternion is normalized or not.
    static final double
    Trace threshold to convert rotation matrices into quaternions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    Quaternion(double[] values)
    Constructor.
    Quaternion(double[] axis, double theta)
    Constructor.
    Quaternion(double roll, double pitch, double yaw)
    Constructor from euler angles.
    Quaternion(double a, double b, double c, double d)
    Constructor.
    Quaternion(AxisRotation3D axisRotation)
    Constructor from and axis 3D rotation.
    Quaternion(MatrixRotation3D matrixRotation)
    Constructor from matrix rotation.
    Quaternion(Quaternion quaternion)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.irurueta.algebra.Matrix
    Returns this 3D rotation instance expressed as a 4x4 homogeneous matrix.
    void
    asHomogeneousMatrix(com.irurueta.algebra.Matrix result)
    Sets into provided Matrix instance this 3D rotation expressed as a 4x4 homogeneous matrix.
    com.irurueta.algebra.Matrix
    Returns this 3D rotation instance expressed as a 3x3 inhomogeneous matrix.
    void
    asInhomogeneousMatrix(com.irurueta.algebra.Matrix result)
    Sets into provided Matrix instance this 3D rotation expressed as a 3x3 inhomogeneous matrix.
    Returns a new quaternion instance containing the same data as this instance.
    void
    Combines provided quaternion into this quaternion, resulting in the multiplication of both quaternion representations.
    static void
    Combines provided quaternions q1 and q2 to produce a resulting quaternion equivalent to the combined rotation of both quaternions.
    void
    combine(Rotation3D rotation)
    Combines provided rotation into this quaternion, resulting in the multiplication of both quaternion representations.
    Combines provided quaternion with this quaternion and returns the result as a new quaternion instance.
    Combines provided rotation with this quaternion and returns the result as a new quaternion instance.
    void
    Computes the conjugate of this quaternion and stores the result into provided instance.
    void
    conjugate(Quaternion result, com.irurueta.algebra.Matrix jacobian)
    Computes the conjugate of this quaternion and stores the result into provided instance.
    Computes the conjugate of this quaternion.
    void
    Copies this instance data into provided quaternion instance.
    static void
    eulerToMatrixRotation(double[] angles, MatrixRotation3D result)
    Computes the rotation matrix body-to-world corresponding to the body orientation given by the Euler angles (roll, pitch, yaw).
    static void
    eulerToMatrixRotation(double[] angles, MatrixRotation3D result, com.irurueta.algebra.Matrix jacobian)
    Computes the rotation matrix body-to-world corresponding to the body orientation given by the Euler angles (roll, pitch, yaw).
    static void
    eulerToMatrixRotation(double roll, double pitch, double yaw, MatrixRotation3D result)
    Computes the rotation matrix body-to-world corresponding to the body orientation given by the Euler angles (roll, pitch, yaw).
    static void
    eulerToMatrixRotation(double roll, double pitch, double yaw, MatrixRotation3D result, com.irurueta.algebra.Matrix jacobian)
    Computes the rotation matrix body-to-world corresponding to the body orientation given by the Euler angles (roll, pitch, yaw).
    void
    fromHomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold)
    Sets amount of rotation from provided homogeneous rotation matrix.
    void
    fromInhomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold)
    Sets amount of rotation from provided inhomogeneous rotation matrix.
    final void
    Copies values from provided quaternion into this instance.
    void
    Sets values of this rotation from a 3D axis rotation.
    void
    Sets values of this rotation from a 3D matrix rotation.
    void
    Sets values of this rotation from a quaternion.
    double
    Gets value corresponding to real numbers basis.
    double
    Gets value corresponding to basis i.
    double
    Gets value corresponding to basis j.
    double
    Gets value corresponding to basis k.
    double
    Returns rotation amount or angle in radians around the rotation axis associated to this instance.
    Returns type of this rotation.
    double[]
    Gets values that parameterize this quaternion.
    private void
    internalNormalize(double norm)
    Normalizes this quaternion if not already normalized.
    void
    Inverts this quaternion.
    void
    Inverts this quaternion instance so that q * q^-1 = 1.
    static void
    Inverts a quaternion so that q * q^-1 = 1.
    Inverts this quaternion instance so that q * q^-1 = 1.
    static Quaternion
    Inverts a quaternion so that q * q^-1 = 1.
    void
    Reverses the rotation of this instance.
    void
    Inverts this quaternion instance so that q * q^-1 = 1.
    void
    Sets into provided Rotation3D instance a rotation inverse to this instance.
    Returns a 3D rotation which is inverse to this instance.
    boolean
    Indicates whether quaternion is already normalized or not.
    static void
    matrixRotationToQuaternion(com.irurueta.algebra.Matrix r, Quaternion result)
    Converts rotation matrix into a quaternion.
    static void
    Converts 3D matrix rotation into a quaternion.
    void
    Multiplies this quaternion with provided one and stores the result in this instance.
    void
    Multiplies this quaternion with provided one and stores the result into provided instance.
    Multiplies this quaternion with provided one and returns the result as a new quaternion instance.
    void
    Normalizes this quaternion if not already normalized.
    void
    normalize(com.irurueta.algebra.Matrix jacobian)
    Normalizes this quaternion if not already normalized and stores the corresponding jacobian into provided matrix (if provided).
    static void
    Multiplies quaternion q1 with quaternion q2 and stores the result into provided instance.
    static void
    product(Quaternion q1, Quaternion q2, Quaternion result, com.irurueta.algebra.Matrix jacobianQ1, com.irurueta.algebra.Matrix jacobianQ2)
    Multiplies quaternion q1 with quaternion q2 and stores the result into provided instance.
    void
    quaternionMatrix(com.irurueta.algebra.Matrix result)
    Converts this quaternion into a quaternion matrix so that the quaternion product q1 x q2 is equivalent to the matrix product: q1.toQuaternionMatrix().multiplyAndReturnNew(q2.toQuaternionMatrix())
    void
    quaternionMatrixN(com.irurueta.algebra.Matrix result)
    Converts this quaternion into a quaternion matrix so that the quaternion product q1 x q2 is equivalent to the matrix product: q2.toQuaternionMatrixN().multiplyAndReturnNew(q1.toQuaternionMatrixN()).
    rotate(Point3D point)
    Returns a 3D point containing a rotated version of provided point.
    void
    rotate(Point3D inputPoint, Point3D resultPoint)
    Rotates a 3D point using the origin of coordinates as the axis of rotation.
    void
    rotate(Point3D inputPoint, Point3D resultPoint, com.irurueta.algebra.Matrix jacobianPoint, com.irurueta.algebra.Matrix jacobianQuaternion)
    Rotates a 3D point using the origin of coordinates as the axis of rotation.
    static void
    rotate(Quaternion q, Point3D inputPoint, Point3D resultPoint, com.irurueta.algebra.Matrix jacobianPoint, com.irurueta.algebra.Matrix jacobianQuaternion)
    Rotates a 3D point using the origin of coordinates as the axis of rotation.
    void
    rotationAxis(double[] axis)
    Returns rotation axis corresponding to this instance.
    static void
    rotationVectorToMatrixRotation(double[] rotationVector, com.irurueta.algebra.Matrix result)
    Converts a rotation vector into a rotation matrix.
    static void
    rotationVectorToMatrixRotation(double[] rotationVector, MatrixRotation3D result)
    Converts a rotation vector into a rotation matrix.
    static void
    rotationVectorToQuaternion(double[] rotationVector, Quaternion result)
    Converts a rotation vector (rotation axis having a norm equal to the rotation angle) into a quaternion.
    static void
    rotationVectorToQuaternion(double[] rotationVector, Quaternion result, com.irurueta.algebra.Matrix jacobian)
    Converts a rotation vector (rotation axis having a norm equal to the rotation angle) into a quaternion, and stores the corresponding jacobian of the quaternion respect to the vector if provided.
    static double
    rotationVectorToRotationAxisAndAngle(double[] rotationVector, double[] axis)
    Converts a rotation vector (rotation axis having a norm equal to the rotation angle) into a normalized rotation axis and its corresponding rotation angle.
    static double
    rotationVectorToRotationAxisAndAngle(double[] rotationVector, double[] axis, com.irurueta.algebra.Matrix jacobianAlpha, com.irurueta.algebra.Matrix jacobianRotationVector)
    Converts a rotation vector (rotation axis having a norm equal to the rotation angle) into a normalized rotation axis and its corresponding rotation angle.
    void
    setA(double a)
    Sets value corresponding to real numbers basis.
    void
    setAxisAndRotation(double axisX, double axisY, double axisZ, double theta)
    Sets the axis and rotation of this instance.
    void
    setB(double b)
    Sets value corresponding to basis i.
    void
    setC(double c)
    Sets value corresponding to basis j.
    void
    setD(double d)
    Sets value corresponding to basis k.
    final void
    setFromAxisAndRotation(double[] axis, double theta)
    Sets quaternion parameters from axis and rotation values.
    void
    setFromAxisAndRotation(double[] axis, double theta, com.irurueta.algebra.Matrix jacobianOfTheta, com.irurueta.algebra.Matrix jacobianOfAxis)
    Sets quaternion parameters from axis and rotation values.
    final void
    setFromAxisAndRotation(double axisX, double axisY, double axisZ, double theta)
    Sets quaternion parameters from axis and rotation values.
    void
    setFromAxisAndRotation(double axisX, double axisY, double axisZ, double theta, com.irurueta.algebra.Matrix jacobianOfTheta, com.irurueta.algebra.Matrix jacobianOfAxis)
    Sets quaternion parameters from axis and rotation values.
    final void
    Sets quaternion parameters from an axis 3D rotation.
    void
    setFromAxisAndRotation(AxisRotation3D axisRotation, com.irurueta.algebra.Matrix jacobianOfTheta, com.irurueta.algebra.Matrix jacobianOfAxis)
    Sets quaternion parameters from an axis 3D rotation.
    void
    setFromEulerAngles(double[] angles)
    Sets quaternion from euler angles (roll, pitch and yaw).
    void
    setFromEulerAngles(double[] angles, com.irurueta.algebra.Matrix jacobian)
    Sets quaternion from euler angles.
    final void
    setFromEulerAngles(double roll, double pitch, double yaw)
    Sets quaternion from euler angles (roll, pitch and yaw).
    void
    setFromEulerAngles(double roll, double pitch, double yaw, com.irurueta.algebra.Matrix jacobian)
    Sets quaternion from euler angles (roll, pitch and yaw).
    void
    setFromMatrixRotation(com.irurueta.algebra.Matrix matrix)
    Sets quaternion values associated to provided rotation.
    final void
    Sets quaternion values associated to provided rotation.
    void
    setFromRotationVector(double[] rotationVector)
    Sets values of this quaternion from provided rotation vector.
    final void
    setValues(double[] values)
    Sets values that parameterize this quaternion in basis (1, i, j ,k).
    void
    slerp(Quaternion q, double t, Quaternion result)
    Computes a linear interpolation between this quaternion and provided quaternion using provided value as the interpolation ratio and stores the result into provided result quaternion.
    static void
    slerp(Quaternion q1, Quaternion q2, double t, Quaternion result)
    Computes a linear interpolation between provided quaternions using provided value as the interpolation ratio, and stores the result into provided result quaternion.
    Computes a linear interpolation between this quaternion and provided quaternion using provided value as the interpolation ratio.
    static Quaternion
    Computes a linear interpolation between provided quaternions using provided value as the interpolation ratio.
    double
    toAxisAndRotationAngle(double[] axis)
    Computes rotation angle and axis.
    double
    toAxisAndRotationAngle(double[] axis, com.irurueta.algebra.Matrix jacobianAngle, com.irurueta.algebra.Matrix jacobianAxis)
    Computes rotation angle and axis of this instance.
    Converts this quaternion into an axis 3D rotation.
    void
    Converts this quaternion into an axis 3D rotation and stores the result into provided rotation instance.
    double[]
    Computes the euler angles (roll, pitch, yaw) resulting in an equivalent rotation to this quaternion.
    void
    toEulerAngles(double[] angles)
    Computes the euler angles (roll, pitch, yaw) equivalent to this quaternion rotation and stores the result into provided array.
    void
    toEulerAngles(double[] angles, com.irurueta.algebra.Matrix jacobian)
    Computes the euler angles (roll, pitch, yaw) equivalent to this quaternion rotation and stores the result into provided array.
    Converts this quaternion into a 3D matrix rotation.
    void
    toMatrixRotation(com.irurueta.algebra.Matrix result)
    Computes the matrix representing this quaternion rotation.
    void
    toMatrixRotation(com.irurueta.algebra.Matrix result, com.irurueta.algebra.Matrix jacobian)
    Computes the matrix representing this quaternion rotation.
    void
    Converts this quaternion into a 3D matrix rotation.
    void
    Converts this 3D rotation into a quaternion storing the result into provided instance.
    com.irurueta.algebra.Matrix
    Converts this quaternion into a quaternion matrix so that quaternion product q1 x q2 is equivalent to the matrix product: q1.toQuaternionMatrix().multiplyAndReturnNew(q2.toQuaternionMatrix())
    com.irurueta.algebra.Matrix
    Converts this quaternion into a quaternion matrix so that quaternion product q1 x q2 is equivalent to the matrix product: q2.toQuaternionMatrixN().multiplyAndReturnNew(q1.toQuaternionMatrixN()).
    void
    toRotationVector(double[] result)
    Computes rotation vector, which is equivalent to the rotation axis but having a norm equal to the rotation angle.
    void
    toRotationVector(double[] result, com.irurueta.algebra.Matrix jacobian)
    Computes rotation vector, which is equivalent to the rotation axis but having a norm equal to the rotation angle.
    void
    values(double[] result)
    Stores values that parameterize this quaternion into provided array.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • N_PARAMS

      public static final int N_PARAMS
      Number of parameters contained in a quaternion.
      See Also:
    • N_ANGLES

      public static final int N_ANGLES
      Number of euler angles.
      See Also:
    • AXIS_NORM_THRESHOLD

      public static final double AXIS_NORM_THRESHOLD
      Threshold of axis norm to convert quaternions to axis and rotation angle.
      See Also:
    • LARGE_AXIS_NORM_THRESHOLD

      public static final double LARGE_AXIS_NORM_THRESHOLD
      Large threshold of axis norm to convert quaternions to axis and rotation angle.
      See Also:
    • TRACE_THRESHOLD

      public static final double TRACE_THRESHOLD
      Trace threshold to convert rotation matrices into quaternions.
      See Also:
    • a

      private double a
      Value corresponding to real numbers basis.
    • b

      private double b
      Value corresponding to basis i.
    • c

      private double c
      Value corresponding to basis j.
    • d

      private double d
      Value corresponding to basis k.
    • normalized

      private boolean normalized
      Indicates whether quaternion is normalized or not.
  • Constructor Details

    • Quaternion

      public Quaternion()
      Default constructor. Creates a quaternion containing no rotation.
    • Quaternion

      public Quaternion(double a, double b, double c, double d)
      Constructor.
      Parameters:
      a - value corresponding to real numbers basis.
      b - value corresponding to basis i.
      c - value corresponding to basis j.
      d - value corresponding to basis k.
    • Quaternion

      public Quaternion(Quaternion quaternion)
      Constructor.
      Parameters:
      quaternion - quaternion to be copied from.
    • Quaternion

      public Quaternion(double[] values)
      Constructor.
      Parameters:
      values - values to be stored in the quaternion expressed in the basis (1, i, j, k)
      Throws:
      IllegalArgumentException - if provided array does not have length 4.
    • Quaternion

      public Quaternion(double[] axis, double theta)
      Constructor.
      Parameters:
      axis - a rotation axis.
      theta - a rotation angle expressed in radians.
      Throws:
      IllegalArgumentException - if provided axis array does not have length 3.
    • Quaternion

      public Quaternion(AxisRotation3D axisRotation)
      Constructor from and axis 3D rotation.
      Parameters:
      axisRotation - an axis 3D rotation.
    • Quaternion

      public Quaternion(double roll, double pitch, double yaw)
      Constructor from euler angles.
      Parameters:
      roll - roll angle expressed in radians.
      pitch - pitch angle expressed in radians.
      yaw - yaw angle expressed in radians.
    • Quaternion

      public Quaternion(MatrixRotation3D matrixRotation)
      Constructor from matrix rotation.
      Parameters:
      matrixRotation - matrix rotation.
  • Method Details

    • getA

      public double getA()
      Gets value corresponding to real numbers basis.
      Returns:
      value corresponding to real numbers basis.
    • setA

      public void setA(double a)
      Sets value corresponding to real numbers basis.
      Parameters:
      a - value corresponding to real numbers basis.
    • getB

      public double getB()
      Gets value corresponding to basis i.
      Returns:
      value corresponding to basis i.
    • setB

      public void setB(double b)
      Sets value corresponding to basis i.
      Parameters:
      b - value corresponding to basis i.
    • getC

      public double getC()
      Gets value corresponding to basis j.
      Returns:
      value corresponding to basis j.
    • setC

      public void setC(double c)
      Sets value corresponding to basis j.
      Parameters:
      c - value corresponding to basis j.
    • getD

      public double getD()
      Gets value corresponding to basis k.
      Returns:
      value corresponding to basis k.
    • setD

      public void setD(double d)
      Sets value corresponding to basis k.
      Parameters:
      d - value corresponding to basis k.
    • getValues

      public double[] getValues()
      Gets values that parameterize this quaternion.
      Returns:
      values of this quaternion.
    • values

      public void values(double[] result)
      Stores values that parameterize this quaternion into provided array.
      Parameters:
      result - array where quaternion parameters will be stored.
      Throws:
      IllegalArgumentException - if length of provided array is not 4.
    • setValues

      public final void setValues(double[] values)
      Sets values that parameterize this quaternion in basis (1, i, j ,k).
      Parameters:
      values - values that parameterize this quaternion in basis (1, i, j, k).
      Throws:
      IllegalArgumentException - if provided array length is not 4.
    • fromQuaternion

      public final void fromQuaternion(Quaternion quaternion)
      Copies values from provided quaternion into this instance.
      Parameters:
      quaternion - quaternion to copy from.
    • clone

      public Quaternion clone() throws CloneNotSupportedException
      Returns a new quaternion instance containing the same data as this instance.
      Overrides:
      clone in class Object
      Returns:
      a copy of this quaternion instance.
      Throws:
      CloneNotSupportedException - if clone fails.
    • copyTo

      public void copyTo(Quaternion output)
      Copies this instance data into provided quaternion instance.
      Parameters:
      output - destination instance where data is copied to.
    • setFromAxisAndRotation

      public final void setFromAxisAndRotation(double axisX, double axisY, double axisZ, double theta)
      Sets quaternion parameters from axis and rotation values.
      Parameters:
      axisX - x coordinate of rotation axis.
      axisY - y coordinate of rotation axis.
      axisZ - z coordinate of rotation axis.
      theta - rotation angle expressed in radians.
    • setFromAxisAndRotation

      public void setFromAxisAndRotation(double axisX, double axisY, double axisZ, double theta, com.irurueta.algebra.Matrix jacobianOfTheta, com.irurueta.algebra.Matrix jacobianOfAxis)
      Sets quaternion parameters from axis and rotation values.
      Parameters:
      axisX - x coordinate of rotation axis.
      axisY - y coordinate of rotation axis.
      axisZ - z coordinate of rotation axis.
      theta - rotation angle expressed in radians.
      jacobianOfTheta - if provided, matrix where jacobian of rotation angle will be stored. Must be a 4x1 matrix.
      jacobianOfAxis - if provided, matrix where jacobian of rotation axis will be stored. Must be a 4x3 matrix.
      Throws:
      IllegalArgumentException - if any of the provided jacobian matrices does not have proper size.
      See Also:
    • setFromAxisAndRotation

      public final void setFromAxisAndRotation(double[] axis, double theta)
      Sets quaternion parameters from axis and rotation values.
      Parameters:
      axis - axis values.
      theta - rotation angle expressed in radians.
      Throws:
      IllegalArgumentException - if provided axis array does not have length 3.
    • setFromAxisAndRotation

      public void setFromAxisAndRotation(double[] axis, double theta, com.irurueta.algebra.Matrix jacobianOfTheta, com.irurueta.algebra.Matrix jacobianOfAxis)
      Sets quaternion parameters from axis and rotation values.
      Parameters:
      axis - axis values.
      theta - rotation angle expressed in radians.
      jacobianOfTheta - if provided, matrix where jacobian of rotation angle will be stored. Must be a 4x1 matrix.
      jacobianOfAxis - if provided, matrix where jacobian of rotation axis will be stored. Must be a 4x4 matrix.
      Throws:
      IllegalArgumentException - if provided axis array does not have length 3, or if any of the provided jacobian matrices does not have proper size.
    • setFromAxisAndRotation

      public final void setFromAxisAndRotation(AxisRotation3D axisRotation)
      Sets quaternion parameters from an axis 3D rotation.
      Parameters:
      axisRotation - an axis 3D rotation.
    • setFromAxisAndRotation

      public void setFromAxisAndRotation(AxisRotation3D axisRotation, com.irurueta.algebra.Matrix jacobianOfTheta, com.irurueta.algebra.Matrix jacobianOfAxis)
      Sets quaternion parameters from an axis 3D rotation.
      Parameters:
      axisRotation - an axis 3D rotation.
      jacobianOfTheta - if provided, matrix where jacobian of rotation angle will be stored. Must be a 4x1 matrix.
      jacobianOfAxis - if provided, matrix where jacobian of rotation axis will be stored. Must be a 4x4 matrix.
      Throws:
      IllegalArgumentException - if any of the provided jacobian matrices does not have proper size.
    • multiply

      public void multiply(Quaternion q)
      Multiplies this quaternion with provided one and stores the result in this instance.
      Parameters:
      q - quaternion to multiply with.
    • multiplyAndReturnNew

      public Quaternion multiplyAndReturnNew(Quaternion q)
      Multiplies this quaternion with provided one and returns the result as a new quaternion instance.
      Parameters:
      q - quaternion to multiply with.
      Returns:
      obtained result.
    • multiply

      public void multiply(Quaternion q, Quaternion result)
      Multiplies this quaternion with provided one and stores the result into provided instance.
      Parameters:
      q - quaternion to multiply with.
      result - instance where result is stored.
    • product

      public static void product(Quaternion q1, Quaternion q2, Quaternion result)
      Multiplies quaternion q1 with quaternion q2 and stores the result into provided instance.
      Parameters:
      q1 - 1st product operator of quaternions.
      q2 - 2nd product operator of quaternions.
      result - instance where result of product is stored.
    • product

      public static void product(Quaternion q1, Quaternion q2, Quaternion result, com.irurueta.algebra.Matrix jacobianQ1, com.irurueta.algebra.Matrix jacobianQ2)
      Multiplies quaternion q1 with quaternion q2 and stores the result into provided instance. This method also computes the Jacobians wrt of Q1 and Q2 if provided.
      Parameters:
      q1 - 1st product operator of quaternions.
      q2 - 2nd product operator of quaternions.
      result - instance where result of product is stored.
      jacobianQ1 - instance where jacobian of q1 is stored.
      jacobianQ2 - instance where jacobian of q2 is stored.
      Throws:
      IllegalArgumentException - if any of the provided jacobian matrices is not 4x4.
      See Also:
    • setFromEulerAngles

      public void setFromEulerAngles(double roll, double pitch, double yaw, com.irurueta.algebra.Matrix jacobian)
      Sets quaternion from euler angles (roll, pitch and yaw).
      Parameters:
      roll - roll angle expressed in radians. Rotation around x-axis.
      pitch - pitch angle expressed in radians. Rotation around y-axis.
      yaw - yaw angle expressed in radians. Rotation around z-axis.
      jacobian - matrix where jacobian will be stored if provided.
      Throws:
      IllegalArgumentException - if provided jacobian matrix does not have size 4x3
      See Also:
    • setFromEulerAngles

      public final void setFromEulerAngles(double roll, double pitch, double yaw)
      Sets quaternion from euler angles (roll, pitch and yaw).
      Parameters:
      roll - roll angle expressed in radians. Rotation around x-axis.
      pitch - pitch angle expressed in radians. Rotation around y-axis.
      yaw - yaw angle expressed in radians. Rotation around z-axis.
      See Also:
    • setFromEulerAngles

      public void setFromEulerAngles(double[] angles, com.irurueta.algebra.Matrix jacobian)
      Sets quaternion from euler angles.
      Parameters:
      angles - euler angles expressed in radians in the following order: roll, pitch and yaw.
      jacobian - matrix where jacobian will be stored if provided.
      Throws:
      IllegalArgumentException - if provided array does not have length 3.
    • setFromEulerAngles

      public void setFromEulerAngles(double[] angles)
      Sets quaternion from euler angles (roll, pitch and yaw).
      Parameters:
      angles - euler angles expressed in radians in the following order: roll, pitch and yaw.
      Throws:
      IllegalArgumentException - if provided array does not have length 3.
    • eulerToMatrixRotation

      public static void eulerToMatrixRotation(double roll, double pitch, double yaw, MatrixRotation3D result, com.irurueta.algebra.Matrix jacobian)
      Computes the rotation matrix body-to-world corresponding to the body orientation given by the Euler angles (roll, pitch, yaw).
      Parameters:
      roll - roll angle expressed in radians. Rotation around x-axis.
      pitch - pitch angle expressed in radians. Rotation around y-axis.
      yaw - yaw angle expressed in radians. Rotation around z-axis.
      result - instance where computed rotation will be stored.
      jacobian - jacobian of computed rotation (optional).
      Throws:
      IllegalArgumentException - if provided jacobian is not 9x3.
      See Also:
    • eulerToMatrixRotation

      public static void eulerToMatrixRotation(double roll, double pitch, double yaw, MatrixRotation3D result)
      Computes the rotation matrix body-to-world corresponding to the body orientation given by the Euler angles (roll, pitch, yaw).
      Parameters:
      roll - roll angle expressed in radians. Rotation around x-axis.
      pitch - pitch angle expressed in radians. Rotation around y-axis.
      yaw - yaw angle expressed in radians. Rotation around z-axis.
      result - instance where computed rotation will be stored.
      See Also:
    • eulerToMatrixRotation

      public static void eulerToMatrixRotation(double[] angles, MatrixRotation3D result, com.irurueta.algebra.Matrix jacobian)
      Computes the rotation matrix body-to-world corresponding to the body orientation given by the Euler angles (roll, pitch, yaw).
      Parameters:
      angles - array containing roll, pitch and yaw angles.
      result - instance where computed rotation will be stored.
      jacobian - jacobian of computed rotation (optional).
      Throws:
      IllegalArgumentException - if provided angles length is not 3, or if provided jacobian is not 9x3.
      See Also:
    • eulerToMatrixRotation

      public static void eulerToMatrixRotation(double[] angles, MatrixRotation3D result)
      Computes the rotation matrix body-to-world corresponding to the body orientation given by the Euler angles (roll, pitch, yaw).
      Parameters:
      angles - array containing roll, pitch and yaw angles.
      result - instance where computed rotation will be stored.
      Throws:
      IllegalArgumentException - if provided angles length is not 3.
      See Also:
    • toAxisAndRotationAngle

      public double toAxisAndRotationAngle(double[] axis, com.irurueta.algebra.Matrix jacobianAngle, com.irurueta.algebra.Matrix jacobianAxis)
      Computes rotation angle and axis of this instance.
      Parameters:
      axis - array where normalized rotation axis will be stored.
      jacobianAngle - matrix where jacobian of angle will be stored, if provided. Must be 1x4.
      jacobianAxis - matrix where jacobian of axis will be stored, if provided. Must be 3x4.
      Returns:
      rotation angle expressed in radians.
      Throws:
      IllegalArgumentException - if length of axis or size of provided jacobians is not correct.
      See Also:
    • toAxisAndRotationAngle

      public double toAxisAndRotationAngle(double[] axis)
      Computes rotation angle and axis.
      Parameters:
      axis - normalized rotation axis.
      Returns:
      rotation angle expressed in radians.
      Throws:
      IllegalArgumentException - if length of axis is not 3.
    • toAxisRotation

      public void toAxisRotation(AxisRotation3D result)
      Converts this quaternion into an axis 3D rotation and stores the result into provided rotation instance.
      Overrides:
      toAxisRotation in class Rotation3D
      Parameters:
      result - rotation instance where result will be stored.
    • toAxisRotation

      public AxisRotation3D toAxisRotation()
      Converts this quaternion into an axis 3D rotation.
      Overrides:
      toAxisRotation in class Rotation3D
      Returns:
      a new axis 3D rotation equivalent to this quaternion.
    • toRotationVector

      public void toRotationVector(double[] result, com.irurueta.algebra.Matrix jacobian)
      Computes rotation vector, which is equivalent to the rotation axis but having a norm equal to the rotation angle.
      Parameters:
      result - array where rotation vector is stored.
      jacobian - matrix where jacobian of vector will be stored, if provided.
      Throws:
      IllegalArgumentException - if length of result is not 3 or size of provided jacobian is not 3x4.
      See Also:
    • toRotationVector

      public void toRotationVector(double[] result)
      Computes rotation vector, which is equivalent to the rotation axis but having a norm equal to the rotation angle.
      Parameters:
      result - array where rotation vector is stored.
      Throws:
      IllegalArgumentException - if length of result is not 3.
    • toEulerAngles

      public void toEulerAngles(double[] angles, com.irurueta.algebra.Matrix jacobian)
      Computes the euler angles (roll, pitch, yaw) equivalent to this quaternion rotation and stores the result into provided array. If provided, this method also computes the jacobian matrix.
      Parameters:
      angles - euler angles (roll, pitch, yaw).
      jacobian - matrix where jacobian is stored, if provided.
      Throws:
      IllegalArgumentException - if provided angles array length is not 3 or if provided jacobian matrix is not 3x4.
      See Also:
    • toEulerAngles

      public void toEulerAngles(double[] angles)
      Computes the euler angles (roll, pitch, yaw) equivalent to this quaternion rotation and stores the result into provided array.
      Parameters:
      angles - euler angles (roll, pitch, yaw).
      Throws:
      IllegalArgumentException - if provided angles array length is not 3.
    • toEulerAngles

      public double[] toEulerAngles()
      Computes the euler angles (roll, pitch, yaw) resulting in an equivalent rotation to this quaternion.
      Returns:
      euler angles (roll, pitch, yaw)
    • quaternionMatrix

      public void quaternionMatrix(com.irurueta.algebra.Matrix result)
      Converts this quaternion into a quaternion matrix so that the quaternion product q1 x q2 is equivalent to the matrix product: q1.toQuaternionMatrix().multiplyAndReturnNew(q2.toQuaternionMatrix())
      Parameters:
      result - matrix where result will be stored.
      Throws:
      IllegalArgumentException - if provided matrix is not 4x4.
      See Also:
    • toQuaternionMatrix

      public com.irurueta.algebra.Matrix toQuaternionMatrix()
      Converts this quaternion into a quaternion matrix so that quaternion product q1 x q2 is equivalent to the matrix product: q1.toQuaternionMatrix().multiplyAndReturnNew(q2.toQuaternionMatrix())
      Returns:
      the quaternion matrix.
      See Also:
    • conjugate

      public void conjugate(Quaternion result, com.irurueta.algebra.Matrix jacobian)
      Computes the conjugate of this quaternion and stores the result into provided instance.
      Parameters:
      result - instance where result is stored.
      jacobian - matrix where jacobian is stored.
      Throws:
      IllegalArgumentException - if provided jacobian matrix is not 4x4.
      See Also:
    • conjugate

      public void conjugate(Quaternion result)
      Computes the conjugate of this quaternion and stores the result into provided instance.
      Parameters:
      result - instance where result is stored.
      See Also:
    • conjugateAndReturnNew

      public Quaternion conjugateAndReturnNew()
      Computes the conjugate of this quaternion.
      Returns:
      conjugate of this quaternion.
      See Also:
    • quaternionMatrixN

      public void quaternionMatrixN(com.irurueta.algebra.Matrix result)
      Converts this quaternion into a quaternion matrix so that the quaternion product q1 x q2 is equivalent to the matrix product: q2.toQuaternionMatrixN().multiplyAndReturnNew(q1.toQuaternionMatrixN()). Notice that matrix order in the product is the opposite as the order used when multiplying matrices obtained by method #toQuaternionMatrix().
      Parameters:
      result - matrix where result will be stored.
      Throws:
      IllegalArgumentException - if provided matrix is not 4x4.
      See Also:
    • toQuaternionMatrixN

      public com.irurueta.algebra.Matrix toQuaternionMatrixN()
      Converts this quaternion into a quaternion matrix so that quaternion product q1 x q2 is equivalent to the matrix product: q2.toQuaternionMatrixN().multiplyAndReturnNew(q1.toQuaternionMatrixN()). Notice that matrix order in the product is the opposite as the order used when multiplying matrices obtained by method #toQuaternionMatrix().
      Returns:
      the quaternion matrix.
      See Also:
    • toMatrixRotation

      public void toMatrixRotation(com.irurueta.algebra.Matrix result, com.irurueta.algebra.Matrix jacobian)
      Computes the matrix representing this quaternion rotation.
      Parameters:
      result - matrix where rotation data will be stored.
      jacobian - jacobian wrt of this quaternion.
      Throws:
      IllegalArgumentException - if provided result matrix is not 3x3 o jacobian matrix is not 9x4.
      See Also:
    • toMatrixRotation

      public void toMatrixRotation(com.irurueta.algebra.Matrix result)
      Computes the matrix representing this quaternion rotation.
      Parameters:
      result - matrix where rotation data will be stored.
      Throws:
      IllegalArgumentException - if provided result matrix is not 3x3.
      See Also:
    • toMatrixRotation

      public void toMatrixRotation(MatrixRotation3D result)
      Converts this quaternion into a 3D matrix rotation.
      Overrides:
      toMatrixRotation in class Rotation3D
      Parameters:
      result - matrix rotation instance where result will be stored.
      See Also:
    • toMatrixRotation

      public MatrixRotation3D toMatrixRotation()
      Converts this quaternion into a 3D matrix rotation.
      Overrides:
      toMatrixRotation in class Rotation3D
      Returns:
      a 3D matrix rotation.
      See Also:
    • rotate

      public static void rotate(Quaternion q, Point3D inputPoint, Point3D resultPoint, com.irurueta.algebra.Matrix jacobianPoint, com.irurueta.algebra.Matrix jacobianQuaternion)
      Rotates a 3D point using the origin of coordinates as the axis of rotation. Point will be rotated by the amount of rotation contained in provided quaternion.
      Parameters:
      q - a quaternion.
      inputPoint - input point to be rotated.
      resultPoint - rotated point.
      jacobianPoint - jacobian wrt of point.
      jacobianQuaternion - jacobian wrt of quaternion.
      Throws:
      IllegalArgumentException - if jacobian of point is not 3x3 or jacobian of quaternion is not 3x4.
      See Also:
    • rotate

      public void rotate(Point3D inputPoint, Point3D resultPoint, com.irurueta.algebra.Matrix jacobianPoint, com.irurueta.algebra.Matrix jacobianQuaternion)
      Rotates a 3D point using the origin of coordinates as the axis of rotation. Point will be rotated by the amount of rotation contained in this quaternion instance.
      Parameters:
      inputPoint - input point to be rotated.
      resultPoint - rotated point.
      jacobianPoint - jacobian wrt of point.
      jacobianQuaternion - jacobian wrt of quaternion.
      Throws:
      IllegalArgumentException - if jacobian of point is not 3x3 or jacobian of quaternion is no 3x4.
      See Also:
    • rotate

      public void rotate(Point3D inputPoint, Point3D resultPoint)
      Rotates a 3D point using the origin of coordinates as the axis of rotation. Point will be rotated by the amount of rotation contained in this quaternion instance.
      Specified by:
      rotate in class Rotation3D
      Parameters:
      inputPoint - Input point to be rotated.
      resultPoint - Rotated point.
      See Also:
    • rotate

      public Point3D rotate(Point3D point)
      Returns a 3D point containing a rotated version of provided point. Point will be rotated using the origin of the coordinates as the axis of rotation. Point will be rotated by the amount of rotation contained in this quaternion instance.
      Overrides:
      rotate in class Rotation3D
      Parameters:
      point - Point to be rotated.
      Returns:
      Rotated point.
      See Also:
    • matrixRotationToQuaternion

      public static void matrixRotationToQuaternion(com.irurueta.algebra.Matrix r, Quaternion result)
      Converts rotation matrix into a quaternion.
      Parameters:
      r - a rotation matrix to be converted from.
      result - quaternion where result is stored.
      Throws:
      IllegalArgumentException - if provided matrix is not 3x3
      See Also:
    • matrixRotationToQuaternion

      public static void matrixRotationToQuaternion(MatrixRotation3D rotation, Quaternion result)
      Converts 3D matrix rotation into a quaternion.
      Parameters:
      rotation - a 3D matrix rotation to be converted from.
      result - quaternion where result is stored.
      See Also:
    • setFromMatrixRotation

      public void setFromMatrixRotation(com.irurueta.algebra.Matrix matrix)
      Sets quaternion values associated to provided rotation.
      Parameters:
      matrix - a rotation matrix.
      Throws:
      IllegalArgumentException - if provided matrix is not 3x3.
      See Also:
    • setFromMatrixRotation

      public final void setFromMatrixRotation(MatrixRotation3D rotation)
      Sets quaternion values associated to provided rotation.
      Parameters:
      rotation - a rotation to be converted into a quaternion.
      See Also:
    • rotationVectorToRotationAxisAndAngle

      public static double rotationVectorToRotationAxisAndAngle(double[] rotationVector, double[] axis, com.irurueta.algebra.Matrix jacobianAlpha, com.irurueta.algebra.Matrix jacobianRotationVector)
      Converts a rotation vector (rotation axis having a norm equal to the rotation angle) into a normalized rotation axis and its corresponding rotation angle.
      Parameters:
      rotationVector - input rotation vector to be converted.
      axis - obtained normalized rotation axis.
      jacobianAlpha - jacobian wrt of angle.
      jacobianRotationVector - jacobian wrt of rotation vector.
      Returns:
      rotation angle.
      Throws:
      IllegalArgumentException - if provided rotation vector length is not 3, jacobian of angle is not 1x3 or jacobian of rotation vector is not 3x3.
      See Also:
    • rotationVectorToRotationAxisAndAngle

      public static double rotationVectorToRotationAxisAndAngle(double[] rotationVector, double[] axis)
      Converts a rotation vector (rotation axis having a norm equal to the rotation angle) into a normalized rotation axis and its corresponding rotation angle.
      Parameters:
      rotationVector - input rotation vector to be converted.
      axis - obtained normalized rotation axis.
      Returns:
      rotation angle.
      Throws:
      IllegalArgumentException - if provided rotation vector length is not 3.
      See Also:
    • rotationVectorToQuaternion

      public static void rotationVectorToQuaternion(double[] rotationVector, Quaternion result, com.irurueta.algebra.Matrix jacobian)
      Converts a rotation vector (rotation axis having a norm equal to the rotation angle) into a quaternion, and stores the corresponding jacobian of the quaternion respect to the vector if provided.
      Parameters:
      rotationVector - input rotation vector to be converted.
      result - quaternion where result will be stored.
      jacobian - if provided, matrix where jacobian of the quaternion respect to the vector will be stored. Must be 4x3.
      Throws:
      IllegalArgumentException - if provided rotation vector is not length 3 or if provided jacobian matrix is not 4x3.
      See Also:
    • rotationVectorToQuaternion

      public static void rotationVectorToQuaternion(double[] rotationVector, Quaternion result)
      Converts a rotation vector (rotation axis having a norm equal to the rotation angle) into a quaternion.
      Parameters:
      rotationVector - input rotation vector to be converted.
      result - quaternion where result will be stored.
      Throws:
      IllegalArgumentException - if provided rotation vector is not length 3.
      See Also:
    • setFromRotationVector

      public void setFromRotationVector(double[] rotationVector)
      Sets values of this quaternion from provided rotation vector. A rotation vector is a rotation axis having a norm equal to the rotation angle.
      Parameters:
      rotationVector - input rotation vector to obtain quaternion values from.
      Throws:
      IllegalArgumentException - if provided rotation vector does not have length 3.
      See Also:
    • rotationVectorToMatrixRotation

      public static void rotationVectorToMatrixRotation(double[] rotationVector, com.irurueta.algebra.Matrix result)
      Converts a rotation vector into a rotation matrix. A rotation vector is a rotation axis having a norm equal to the rotation angle.
      Parameters:
      rotationVector - a rotation vector to be converted into a 3D matrix rotation.
      result - matrix where result is stored.
      Throws:
      IllegalArgumentException - if provided rotation vector does not have length 3.
      See Also:
    • rotationVectorToMatrixRotation

      public static void rotationVectorToMatrixRotation(double[] rotationVector, MatrixRotation3D result)
      Converts a rotation vector into a rotation matrix. A rotation vector is a rotation axis having a norm equal to the rotation angle.
      Parameters:
      rotationVector - a rotation vector to be converted into a 3D matrix rotation.
      result - 3D matrix rotation where result is stored.
      Throws:
      IllegalArgumentException - if provided rotation vector does not have length 3.
      See Also:
    • getType

      public Rotation3DType getType()
      Returns type of this rotation.
      Specified by:
      getType in class Rotation3D
      Returns:
      Type of this rotation.
    • setAxisAndRotation

      public void setAxisAndRotation(double axisX, double axisY, double axisZ, double theta)
      Sets the axis and rotation of this instance. Once set, points will rotate around provided axis an amount equal to provided rotation angle in radians. Note: to avoid numerical instabilities and improve accuracy, axis coordinates should be normalized (e.g. norm equal to 1).
      Specified by:
      setAxisAndRotation in class Rotation3D
      Parameters:
      axisX - X coordinate of rotation axis.
      axisY - Y coordinate of rotation axis.
      axisZ - Z coordinate of rotation axis.
      theta - Amount of rotation in radians.
    • rotationAxis

      public void rotationAxis(double[] axis)
      Returns rotation axis corresponding to this instance. Result is stored in provided axis array, which must have length 3.
      Specified by:
      rotationAxis in class Rotation3D
      Parameters:
      axis - Array where axis coordinates will be stored.
      Throws:
      IllegalArgumentException - Raised if provided array does not have length 3.
    • getRotationAngle

      public double getRotationAngle()
      Returns rotation amount or angle in radians around the rotation axis associated to this instance.
      Specified by:
      getRotationAngle in class Rotation3D
      Returns:
      Rotation angle in radians.
    • asInhomogeneousMatrix

      public com.irurueta.algebra.Matrix asInhomogeneousMatrix()
      Returns this 3D rotation instance expressed as a 3x3 inhomogeneous matrix. This is equivalent to call getInternalMatrix().
      Specified by:
      asInhomogeneousMatrix in class Rotation3D
      Returns:
      Rotation matrix expressed in inhomogeneous coordinates.
    • asInhomogeneousMatrix

      public void asInhomogeneousMatrix(com.irurueta.algebra.Matrix result)
      Sets into provided Matrix instance this 3D rotation expressed as a 3x3 inhomogeneous matrix.
      Specified by:
      asInhomogeneousMatrix in class Rotation3D
      Parameters:
      result - Matrix where rotation will be set.
      Throws:
      IllegalArgumentException - Raised if provided instance does not have size 3x3.
    • asHomogeneousMatrix

      public com.irurueta.algebra.Matrix asHomogeneousMatrix()
      Returns this 3D rotation instance expressed as a 4x4 homogeneous matrix.
      Specified by:
      asHomogeneousMatrix in class Rotation3D
      Returns:
      Rotation matrix expressed in homogeneous coordinates.
    • asHomogeneousMatrix

      public void asHomogeneousMatrix(com.irurueta.algebra.Matrix result)
      Sets into provided Matrix instance this 3D rotation expressed as a 4x4 homogeneous matrix.
      Specified by:
      asHomogeneousMatrix in class Rotation3D
      Parameters:
      result - Matrix where rotation will be set.
      Throws:
      IllegalArgumentException - Raised if provided instance does not have size 4x4.
    • fromInhomogeneousMatrix

      public void fromInhomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold)
      Sets amount of rotation from provided inhomogeneous rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix must also have size 3x3.
      Specified by:
      fromInhomogeneousMatrix in class Rotation3D
      Parameters:
      m - Provided rotation matrix.
      threshold - Threshold to determine whether matrix is orthonormal.
      Throws:
      IllegalArgumentException - Raised if provided threshold is negative. Rotation3D.isValidRotationMatrix(Matrix)
    • fromHomogeneousMatrix

      public void fromHomogeneousMatrix(com.irurueta.algebra.Matrix m, double threshold)
      Sets amount of rotation from provided homogeneous rotation matrix. Provided matrix must be orthogonal (i.e. squared, non-singular, it's transpose must be its inverse) and must have determinant equal to 1. Provided matrix must also have size 4x4, and its last row and column must be zero, except for element in last row and column which must be 1.
      Specified by:
      fromHomogeneousMatrix in class Rotation3D
      Parameters:
      m - Provided rotation matrix.
      threshold - Threshold to determine whether matrix is orthonormal.
      Throws:
      IllegalArgumentException - Raised if provided threshold is negative. Rotation3D.isValidRotationMatrix(Matrix)
    • inverse

      public static void inverse(Quaternion q, Quaternion result)
      Inverts a quaternion so that q * q^-1 = 1.
      Parameters:
      q - quaternion to be inverted.
      result - quaternion instance where the result will be stored.
    • inverseAndReturnNew

      public static Quaternion inverseAndReturnNew(Quaternion q)
      Inverts a quaternion so that q * q^-1 = 1.
      Parameters:
      q - quaternion to be inverted.
      Returns:
      a new quaternion containing the inverse.
    • inverse

      public void inverse(Quaternion result)
      Inverts this quaternion instance so that q * q^-1 = 1.
      Parameters:
      result - instance where quaternion inverse is stored.
    • inverseAndReturnNew

      public Quaternion inverseAndReturnNew()
      Inverts this quaternion instance so that q * q^-1 = 1.
      Returns:
      a new quaternion containing the inverse of this quaternion.
    • inverse

      public void inverse()
      Inverts this quaternion.
    • inverseRotationAndReturnNew

      public Rotation3D inverseRotationAndReturnNew()
      Returns a 3D rotation which is inverse to this instance. In other words, the combination of this rotation with its inverse produces no change.
      Specified by:
      inverseRotationAndReturnNew in class Rotation3D
      Returns:
      Inverse 3D rotation.
    • inverseRotation

      public void inverseRotation(Quaternion result)
      Inverts this quaternion instance so that q * q^-1 = 1.
      Parameters:
      result - instance where quaternion inverse is stored.
    • inverseRotation

      public void inverseRotation(Rotation3D result)
      Sets into provided Rotation3D instance a rotation inverse to this instance. The combination of this rotation with its inverse produces no change.
      Specified by:
      inverseRotation in class Rotation3D
      Parameters:
      result - Instance where inverse rotation will be set.
    • inverseRotation

      public void inverseRotation()
      Reverses the rotation of this instance.
      Specified by:
      inverseRotation in class Rotation3D
    • combine

      public static void combine(Quaternion q1, Quaternion q2, Quaternion result)
      Combines provided quaternions q1 and q2 to produce a resulting quaternion equivalent to the combined rotation of both quaternions.
      Parameters:
      q1 - 1st quaternion.
      q2 - 2nd quaternion.
      result - combined quaternion where result is stored.
    • combineAndReturnNew

      public Quaternion combineAndReturnNew(Quaternion q)
      Combines provided quaternion with this quaternion and returns the result as a new quaternion instance.
      Parameters:
      q - input quaternion to be combined.
      Returns:
      combined quaternion, which is equal to the multiplication of quaternions.
    • combine

      public void combine(Quaternion q)
      Combines provided quaternion into this quaternion, resulting in the multiplication of both quaternion representations.
      Parameters:
      q - input quaternion to be combined.
    • combineAndReturnNew

      public Rotation3D combineAndReturnNew(Rotation3D rotation)
      Combines provided rotation with this quaternion and returns the result as a new quaternion instance.
      Specified by:
      combineAndReturnNew in class Rotation3D
      Parameters:
      rotation - input rotation to be combined.
      Returns:
      combined rotation, which is equal to the multiplication of the internal quaternion representations.
    • combine

      public void combine(Rotation3D rotation)
      Combines provided rotation into this quaternion, resulting in the multiplication of both quaternion representations.
      Specified by:
      combine in class Rotation3D
      Parameters:
      rotation - input rotation to be combined.
    • fromRotation

      public void fromRotation(MatrixRotation3D rot)
      Sets values of this rotation from a 3D matrix rotation.
      Overrides:
      fromRotation in class Rotation3D
      Parameters:
      rot - 3D matrix rotation to set values from.
    • fromRotation

      public void fromRotation(AxisRotation3D rot)
      Sets values of this rotation from a 3D axis rotation.
      Overrides:
      fromRotation in class Rotation3D
      Parameters:
      rot - an axis rotation to set values from.
    • fromRotation

      public void fromRotation(Quaternion q)
      Sets values of this rotation from a quaternion.
      Specified by:
      fromRotation in class Rotation3D
      Parameters:
      q - a quaternion to set values from.
    • toQuaternion

      public void toQuaternion(Quaternion result)
      Converts this 3D rotation into a quaternion storing the result into provided instance.
      Overrides:
      toQuaternion in class Rotation3D
      Parameters:
      result - instance where result will be stored.
    • isNormalized

      public boolean isNormalized()
      Indicates whether quaternion is already normalized or not.
      Returns:
      true if quaternion is normalized, false otherwise.
    • normalize

      public void normalize()
      Normalizes this quaternion if not already normalized.
    • normalize

      public void normalize(com.irurueta.algebra.Matrix jacobian)
      Normalizes this quaternion if not already normalized and stores the corresponding jacobian into provided matrix (if provided).
      Parameters:
      jacobian - matrix where jacobian will be stored (if provided). Must be 4x4.
      Throws:
      IllegalArgumentException - if provided jacobian is not 4x4.
    • slerpAndReturnNew

      public Quaternion slerpAndReturnNew(Quaternion q, double t)
      Computes a linear interpolation between this quaternion and provided quaternion using provided value as the interpolation ratio.
      Parameters:
      q - quaternion to interpolate.
      t - interpolation ratio. Must be a value between 0.0 and 1.0, both included. The closer the value is to 0.0, the more similar result will be to this instance. Conversely, the closer the value is to 1.0, the more similar result will be to q.
      Returns:
      a new interpolated quaternion instance.
      Throws:
      IllegalArgumentException - if provided interpolation ratio is not between 0.0 and 1.0, both included.
    • slerp

      public void slerp(Quaternion q, double t, Quaternion result)
      Computes a linear interpolation between this quaternion and provided quaternion using provided value as the interpolation ratio and stores the result into provided result quaternion.
      Parameters:
      q - quaternion to interpolate.
      t - interpolation ratio. Must be a value between 0.0 and 1.0, both included. The closer the value is to 0.0, the more similar result will be to this instance. Conversely, the closer the value is to 1.0, the more similar result will be to q.
      result - instance where interpolated quaternion will be stored.
      Throws:
      IllegalArgumentException - if provided interpolation ratio is not between 0.0 and 1.0, both included.
    • slerpAndReturnNew

      public static Quaternion slerpAndReturnNew(Quaternion q1, Quaternion q2, double t)
      Computes a linear interpolation between provided quaternions using provided value as the interpolation ratio.
      Parameters:
      q1 - 1st quaternion to interpolate.
      q2 - 2nd quaternion to interpolate.
      t - interpolation ratio. Must be a value between 0.0 and 1.0, both included. The closer the value is to 0.0, the more similar result will be to q1. Conversely, the closer the value is to 1.0, the more similar result will be to q2.
      Returns:
      a new interpolated quaternion instance.
      Throws:
      IllegalArgumentException - if provided interpolation ratio is not between 0.0 and 1.0, both included.
    • slerp

      public static void slerp(Quaternion q1, Quaternion q2, double t, Quaternion result)
      Computes a linear interpolation between provided quaternions using provided value as the interpolation ratio, and stores the result into provided result quaternion.
      Parameters:
      q1 - 1st quaternion to interpolate.
      q2 - 2nd quaternion to interpolate.
      t - interpolation ratio. Must be a value between 0.0 and 1.0, both included. The closer the value is to 0.0, the more similar result will be to q1. Conversely, the closer the value is to 1.0, the more similar result will be to q2.
      result - instance where interpolated quaternion will be stored.
      Throws:
      IllegalArgumentException - if provided interpolation ratio is not between 0.0 and 1.0, both included.
    • internalNormalize

      private void internalNormalize(double norm)
      Normalizes this quaternion if not already normalized.
      Parameters:
      norm - norm to normalize this quaternion with.