Package com.github.stephengold.joltjni
Class Quat
java.lang.Object
com.github.stephengold.joltjni.Quat
- All Implemented Interfaces:
QuatArg
A math object used to represent rotations and orientations in 3-dimensional
space, without risk of gimbal lock. Each quaternion has 4 single-precision
components: 3 imaginary ones (X, Y, and Z) and a real one (W).
Mathematically speaking, quaternions are an extension of complex numbers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn the conjugate.floatgetW()Return the real (W) component in single precision.floatgetX()Return the first imaginary (X) component in single precision.floatgetY()Return the 2nd imaginary (Y) component in single precision.floatgetZ()Return the 3rd imaginary (Z) component in single precision.booleanTest whether the quaternion is normalized to within a tolerance of 10^-5.booleanisNormalized(float tolerance) Test whether the quaternion is normalized to within the specified tolerance.floatlength()Return the length.floatlengthSq()Return the squared length.Generate a normalized quaternion that represents the same rotation.voidset(float x, float y, float z, float w) Set all 4 components to specified values.static QuatCreate a rotation quaternion that rotatesfromtoto.static QuatCreate an identity quaternion (0,0,0,1).static QuatsRandom(DefaultRandomEngine engine) Generate a pseudo-random unit quaternion.static QuatCreate a rotation quaternion from a normalized rotation axis.toString()Return a string representation of the quaternion, which is unaffected.
-
Constructor Details
-
Quat
public Quat()Instantiate an identity quaternion (0,0,0,1). -
Quat
public Quat(float x, float y, float z, float w) Instantiate a quaternion with specified components.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z componentw- the desired W component
-
Quat
Instantiate a quaternion based on aVec3Arg.- Parameters:
v- the desired XYZ componentsw- the desired W component
-
-
Method Details
-
set
public void set(float x, float y, float z, float w) Set all 4 components to specified values.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z componentw- the desired W component
-
sFromTo
Create a rotation quaternion that rotatesfromtoto.- Parameters:
from- the first direction vector (not null, unaffected)to- the 2nd direction vector (not null, unaffected)- Returns:
- a new quaternion
-
sIdentity
Create an identity quaternion (0,0,0,1).- Returns:
- a new quaternion
-
sRandom
Generate a pseudo-random unit quaternion.- Parameters:
engine- the generator to use (not null)- Returns:
- a new unit quaternion
-
sRotation
Create a rotation quaternion from a normalized rotation axis.- Parameters:
axis- the desired rotation axis (not null, normalized)angle- the desired rotation angle (in radians)- Returns:
- a new quaternion
-
conjugated
Return the conjugate. The current object is unaffected.- Specified by:
conjugatedin interfaceQuatArg- Returns:
- a new object
-
getW
public float getW()Return the real (W) component in single precision. The quaternion is unaffected. -
getX
public float getX()Return the first imaginary (X) component in single precision. The quaternion is unaffected. -
getY
public float getY()Return the 2nd imaginary (Y) component in single precision. The quaternion is unaffected. -
getZ
public float getZ()Return the 3rd imaginary (Z) component in single precision. The quaternion is unaffected. -
isNormalized
public boolean isNormalized()Test whether the quaternion is normalized to within a tolerance of 10^-5. The quaternion is unaffected.- Specified by:
isNormalizedin interfaceQuatArg- Returns:
- true if normalized, otherwise false
-
isNormalized
public boolean isNormalized(float tolerance) Test whether the quaternion is normalized to within the specified tolerance. The quaternion is unaffected.- Specified by:
isNormalizedin interfaceQuatArg- Parameters:
tolerance- the desired tolerance (default=1e-5)- Returns:
- true if normalized, otherwise false
-
length
public float length()Return the length. The quaternion is unaffected. -
lengthSq
public float lengthSq()Return the squared length. The quaternion is unaffected. -
normalized
Generate a normalized quaternion that represents the same rotation. The current object is unaffected.- Specified by:
normalizedin interfaceQuatArg- Returns:
- a new quaternion
-
toString
Return a string representation of the quaternion, which is unaffected. For example, an identity quaternion is represented by:Quat(0.0 0.0 0.0 1.0)
-