Class Quaternion
java.lang.Object
com.victorvalentim.zividomelive.render.Quaternion
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
ConstructorsConstructorDescriptionQuaternion(float x, float y, float z, float w) Constructs a quaternion with the given components. -
Method Summary
Modifier and TypeMethodDescriptionstatic QuaternionfromAxisAngle(float ax, float ay, float az, float angle) Creates a quaternion from an axis and angle.static QuaternionfromAxisAngle(processing.core.PVector axis, float angle) Creates a quaternion from a Processing axis vector and angle.multiply(Quaternion other) 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.PMatrix3DtoMatrix()Converts this quaternion to a 3x3 rotation matrix stored in aPMatrix3D.voidtoMatrix(processing.core.PMatrix3D m) Writes this quaternion's rotation matrix into a caller-owned matrix.floatw()floatx()floaty()floatz()
-
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
Creates a quaternion from an axis and angle.- Parameters:
ax- axis x componentay- axis y componentaz- axis z componentangle- rotation angle in radians- Returns:
- quaternion representing the rotation
-
fromAxisAngle
Creates a quaternion from a Processing axis vector and angle.- Parameters:
axis- rotation axis; must not benullangle- rotation angle in radians- Returns:
- quaternion representing the rotation
-
multiply
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 aPMatrix3D. The resulting matrix can be used for 3D transformations.- Returns:
- a
PMatrix3Drepresenting 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 benull
-
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
Spherical linear interpolation (SLERP) between this quaternion and q2.- Parameters:
q2- target quaterniont- interpolation factor in [0,1]- Returns:
- interpolated quaternion
-