Class Quaternions

java.lang.Object
civitas.celestis.math.complex.Quaternions

public final class Quaternions extends Object
Contains utility methods related to quaternions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    Given a rotation quaternion q, this returns the angle of the rotation, in the context of axis/angle notation.
    static Vector3
    Given a rotation quaternion q, this returns the axis of the rotation.
    static Double4
    Given a rotation quaternion q, this returns an axis/angle pair denoting the rotation of the quaternion.
    static Double3
    Given a rotation quaternion q, this returns a tuple of doubles containing the pitch, yaw, and roll angles of the quaternion in pitch-yaw-roll order.
    static Quaternion
    from(double pitch, double yaw, double roll)
    Creates a new rotation quaternion from Euler angle representation.
    static Quaternion
    Creates a new quaternion from a 3x3 rotation matrix.
    static Quaternion
    from(Vector3 axis, double angle)
    Creates a new rotation quaternion from an axis/angle notation.
    static Quaternion
    Creates a new rotation quaternion from Euler angle representation.
    static Quaternion
    from(Double4 axisAngle)
    Creates a new rotation quaternion from an axis/angle notation.
    static Quaternion
    lerp(Quaternion s, Quaternion e, double t)
    Performs linear interpolation (LERP) between the starting value s and the ending value e.
    static Matrix
    Given a rotation quaternion q, this converts the rotation into a 3x3 rotation matrix.
    static double
    Given a rotation quaternion q, this returns the pitch of the rotation.
    static Quaternion
    Returns a random rotation quaternion.
    static double
    Given a rotation quaternion q, this returns the roll of this rotation.
    static Quaternion
    slerp(Quaternion start, Quaternion end, double t)
    Performs spherical linear interpolation (SLERP) between two quaternions.
    static double
    Given a rotation quaternion q, this returns the yaw of the rotation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • random

      @Nonnull public static Quaternion random()
      Returns a random rotation quaternion.
      Returns:
      A random rotation quaternion
    • lerp

      @Nonnull public static Quaternion lerp(@Nonnull Quaternion s, @Nonnull Quaternion e, double t)
      Performs linear interpolation (LERP) between the starting value s and the ending value e.
      Parameters:
      s - The starting value
      e - The ending value
      t - The interpolation parameter ([0, 1])
      Returns:
      The interpolated value between the starting and ending values s and e
    • slerp

      @Nonnull public static Quaternion slerp(@Nonnull Quaternion start, @Nonnull Quaternion end, double t)
      Performs spherical linear interpolation (SLERP) between two quaternions. This assumes that the input quaternions are already normalized.
      Parameters:
      start - The starting quaternion
      end - The end quaternion
      t - The interpolation parameter t (0-1)
      Returns:
      The interpolated quaternion
    • from

      @Nonnull public static Quaternion from(@Nonnull Double3 pyr)
      Creates a new rotation quaternion from Euler angle representation. This method uses the right-handed coordinate system.
      Parameters:
      pyr - A tuple of doubles containing the Euler angles in pitch-yaw-roll order
      Returns:
      The constructed quaternion
    • from

      @Nonnull public static Quaternion from(double pitch, double yaw, double roll)
      Creates a new rotation quaternion from Euler angle representation. This method uses the right-handed coordinate system.
      Parameters:
      pitch - The pitch of the rotation in radians (rotation along X axis)
      yaw - The yaw of the rotation in radians (rotation along Y axis)
      roll - The roll of the rotation in radians (rotation along Z axis)
      Returns:
      The constructed quaternion
    • eulerAngles

      @Nonnull public static Double3 eulerAngles(@Nonnull Quaternion q)
      Given a rotation quaternion q, this returns a tuple of doubles containing the pitch, yaw, and roll angles of the quaternion in pitch-yaw-roll order.
      Parameters:
      q - The quaternion of which to get the Euler angles of
      Returns:
      The Euler angles of the quaternion, denoted in radians
    • pitch

      public static double pitch(@Nonnull Quaternion q)
      Given a rotation quaternion q, this returns the pitch of the rotation. Pitch is defined as rotation along the X axis, and follows a right-handed coordinate system.
      Parameters:
      q - The quaternion of which to get the pitch of
      Returns:
      The pitch of the quaternion in radians
    • yaw

      public static double yaw(@Nonnull Quaternion q)
      Given a rotation quaternion q, this returns the yaw of the rotation. Yaw is defined as rotation along the Y axis, and follows a right-handed coordinate system.
      Parameters:
      q - The quaternion of which to get the yaw of
      Returns:
      The yaw of the quaternion in radians
    • roll

      public static double roll(@Nonnull Quaternion q)
      Given a rotation quaternion q, this returns the roll of this rotation. Roll is defined as rotation along the Z axis, and follows a right-handed coordinate system.
      Parameters:
      q - The quaternion of which to get the roll of
      Returns:
      The roll of the quaternion in radians
    • from

      @Nonnull public static Quaternion from(@Nonnull Double4 axisAngle)
      Creates a new rotation quaternion from an axis/angle notation. This method uses the right-handed coordinate system.
      Parameters:
      axisAngle - The axis/angle representation of the rotation
      Returns:
      The constructed quaternion
    • from

      @Nonnull public static Quaternion from(@Nonnull Vector3 axis, double angle)
      Creates a new rotation quaternion from an axis/angle notation. This method uses the right-handed coordinate system.
      Parameters:
      axis - The axis of rotation as a unit vector
      angle - The angle of rotation in radians
      Returns:
      The constructed quaternion
    • axisAngle

      @Nonnull public static Double4 axisAngle(@Nonnull Quaternion q)
      Given a rotation quaternion q, this returns an axis/angle pair denoting the rotation of the quaternion. Axis/angle notation follows the right-handed coordinate system. The W component represents the angle of rotation in radians, and the XYZ components represent the axis of rotation.
      Parameters:
      q - The quaternion of which to convert to axis/angle notation
      Returns:
      The axis/angle representation of the quaternion
    • angle

      public static double angle(@Nonnull Quaternion q)
      Given a rotation quaternion q, this returns the angle of the rotation, in the context of axis/angle notation. Axis/angle notation follows the right-handed coordinate system.
      Parameters:
      q - The quaternion of which to get the angle of
      Returns:
      The angle of rotation of the quaternion in radians
    • axis

      @Nonnull public static Vector3 axis(@Nonnull Quaternion q)
      Given a rotation quaternion q, this returns the axis of the rotation. If the quaternion represents no rotation (the Euclidean norm is nearly zero), this will return a fallback value Vector3.POSITIVE_Y.
      Parameters:
      q - The quaternion of which to get the axis of
      Returns:
      The axis of rotation of the quaternion as a unit vector
    • from

      @Nonnull public static Quaternion from(@Nonnull Matrix m) throws IllegalArgumentException
      Creates a new quaternion from a 3x3 rotation matrix.
      Parameters:
      m - The rotation matrix which represents the rotation
      Returns:
      The constructed quaternion
      Throws:
      IllegalArgumentException - When the matrix's dimensions is not 3x3
    • matrix

      @Nonnull public static Matrix matrix(@Nonnull Quaternion q)
      Given a rotation quaternion q, this converts the rotation into a 3x3 rotation matrix.
      Parameters:
      q - The quaternion of which to convert into a rotation matrix
      Returns:
      The matrix representation of the provided quaternion q