Class Quaternion

java.lang.Object
com.victorvalentim.zividomelive.render.Quaternion

public final class Quaternion extends Object
Immutable quaternion value for representing three-dimensional rotations.

Operations never mutate either operand. Methods that require a unit quaternion normalize their inputs or account for magnitude explicitly, and all components must be finite.

API stability: Advanced Stable.

Since:
2.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Quaternion(float x, float y, float z, float w)
    Constructs a quaternion with the given components.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Quaternion
    fromAxisAngle(float ax, float ay, float az, float angle)
    Creates a quaternion from an axis and angle.
    static Quaternion
    fromAxisAngle(processing.core.PVector axis, float angle)
    Creates a quaternion from a Processing axis vector and angle.
    Multiplies this quaternion by another quaternion and returns the result.
    Returns this rotation normalized to unit length without mutating this value.
    slerp(Quaternion q2, float t)
    Spherical linear interpolation (SLERP) between this quaternion and q2.
    processing.core.PMatrix3D
    Converts this quaternion to a 3x3 rotation matrix stored in a PMatrix3D.
    void
    toMatrix(processing.core.PMatrix3D m)
    Writes this quaternion's rotation matrix into a caller-owned matrix.
    float
    w()
     
    float
    x()
     
    float
    y()
     
    float
    z()
     

    Methods inherited from class java.lang.Object

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

    • Quaternion

      public Quaternion(float x, float y, float z, float w)
      Constructs a quaternion with the given components.
      Parameters:
      x - the X component (vector part)
      y - the Y component (vector part)
      z - the Z component (vector part)
      w - the W component (scalar part)
  • Method Details

    • x

      public float x()
      Returns:
      X component of the vector part
    • y

      public float y()
      Returns:
      Y component of the vector part
    • z

      public float z()
      Returns:
      Z component of the vector part
    • w

      public float w()
      Returns:
      scalar component
    • fromAxisAngle

      public static Quaternion fromAxisAngle(float ax, float ay, float az, float angle)
      Creates a quaternion from an axis and angle.
      Parameters:
      ax - axis x component
      ay - axis y component
      az - axis z component
      angle - rotation angle in radians
      Returns:
      quaternion representing the rotation
    • fromAxisAngle

      public static Quaternion fromAxisAngle(processing.core.PVector axis, float angle)
      Creates a quaternion from a Processing axis vector and angle.
      Parameters:
      axis - rotation axis; must not be null
      angle - rotation angle in radians
      Returns:
      quaternion representing the rotation
    • multiply

      public Quaternion multiply(Quaternion other)
      Multiplies this quaternion by another quaternion and returns the result.
      Parameters:
      other - the quaternion to multiply with
      Returns:
      the product quaternion
    • toMatrix

      public processing.core.PMatrix3D toMatrix()
      Converts this quaternion to a 3x3 rotation matrix stored in a PMatrix3D. The resulting matrix can be used for 3D transformations.
      Returns:
      a PMatrix3D representing the rotation of this quaternion
    • toMatrix

      public void toMatrix(processing.core.PMatrix3D m)
      Writes this quaternion's rotation matrix into a caller-owned matrix.

      This allocation-free overload preserves the exact qualified orientation math used by toMatrix().

      Parameters:
      m - destination matrix; must not be null
    • normalized

      public Quaternion normalized()
      Returns this rotation normalized to unit length without mutating this value.
      Returns:
      a unit quaternion; this instance may be returned when it is already normalized
      Throws:
      IllegalStateException - when all four components are zero
    • slerp

      public Quaternion slerp(Quaternion q2, float t)
      Spherical linear interpolation (SLERP) between this quaternion and q2.
      Parameters:
      q2 - target quaternion
      t - interpolation factor in [0,1]
      Returns:
      interpolated quaternion