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
ConstructorsConstructorDescriptionQuat()
Instantiate an identity quaternion (0,0,0,1).Quat
(float[] array) Instantiate a quaternion from the specified array.Quat
(float x, float y, float z, float w) Instantiate a quaternion with specified components.Instantiate a copy of the argument.Instantiate a quaternion based on aVec3Arg
.Quat
(FloatBuffer buffer) Instantiate from a buffer. -
Method Summary
Modifier and TypeMethodDescriptionReturn the conjugate.float
getW()
Return the real (W) component in single precision.float
getX()
Return the first imaginary (X) component in single precision.float
getY()
Return the 2nd imaginary (Y) component in single precision.float
getZ()
Return the 3rd imaginary (Z) component in single precision.boolean
isFinite()
Test whether the quaternion contains infinities or NaNs.boolean
Test whether the quaternion is normalized to within a tolerance of 10^-5.boolean
isNormalized
(float tolerance) Test whether the quaternion is normalized to within the specified tolerance.boolean
Test whether the quaternion represents an identity rotation.boolean
isZero()
Test whether the quaternion is zero.float
length()
Return the length.float
lengthSq()
Return the squared length.void
Set the current quaternion to identity.Generate a normalized quaternion that represents the same rotation.void
put
(FloatBuffer storeBuffer) Write all 4 components to the specified buffer in XYZW order and advance the buffer's position by 4.Apply the rotation to (1,0,0).Apply the rotation to (0,1,0).Apply the rotation to (0,0,1).void
set
(float[] array) Set all 4 components from the specified array.void
set
(float x, float y, float z, float w) Set all 4 components to specified values.void
Copy all 4 components from the argument.static Quat
sEulerAngles
(float x, float y, float z) Create a rotation quaternion from the specified Tait-Bryan angles, applying the rotations in x-y-z extrinsic order or z-y'-x" intrinsic order.static Quat
sEulerAngles
(Vec3Arg angles) Create a rotation quaternion from the specified Tait-Bryan angles, applying the rotations in x-y-z extrinsic order or z-y'-x" intrinsic order.static Quat
Create a rotation quaternion that rotatesfrom
toto
.static Quat
Create an identity quaternion (0,0,0,1).static Quat
sRandom
(RandomNumberEngine engine) Generate a pseudo-random unit quaternion.static Quat
Create 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
public Quat(float[] array) Instantiate a quaternion from the specified array.- Parameters:
array
- the desired component values (in XYZW order, not null, length≥4, unaffected)
-
Quat
Instantiate from a buffer.- Parameters:
buffer
- the desired component values (not null, unaffected, capacity≥4)
-
Quat
Instantiate a copy of the argument.- Parameters:
original
- the quaternion to copy (not null, unaffected)
-
Quat
Instantiate a quaternion based on aVec3Arg
.- Parameters:
v
- the desired XYZ componentsw
- the desired W component
-
-
Method Details
-
loadIdentity
public void loadIdentity()Set the current quaternion to identity. -
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
-
set
public void set(float[] array) Set all 4 components from the specified array.- Parameters:
array
- the desired component values (in XYZW order, not null, length≥4, unaffected)
-
set
Copy all 4 components from the argument.- Parameters:
source
- the quaternion to copy (not null, unaffected)
-
sEulerAngles
Create a rotation quaternion from the specified Tait-Bryan angles, applying the rotations in x-y-z extrinsic order or z-y'-x" intrinsic order.- Parameters:
x
- the desired rotation around the X axis (in radians)y
- the desired rotation around the Y axis (in radians)z
- the desired rotation around the Z axis (in radians)- Returns:
- a new quaternion
-
sEulerAngles
Create a rotation quaternion from the specified Tait-Bryan angles, applying the rotations in x-y-z extrinsic order or z-y'-x" intrinsic order.- Parameters:
angles
- the desired rotation around each axis (in radians, not null, unaffected)- Returns:
- a new quaternion
-
sFromTo
Create a rotation quaternion that rotatesfrom
toto
.- 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:
conjugated
in 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. -
isFinite
public boolean isFinite()Test whether the quaternion contains infinities or NaNs. 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:
isNormalized
in interfaceQuatArg
- Returns:
true
if normalized, otherwisefalse
-
isNormalized
public boolean isNormalized(float tolerance) Test whether the quaternion is normalized to within the specified tolerance. The quaternion is unaffected.- Specified by:
isNormalized
in interfaceQuatArg
- Parameters:
tolerance
- the desired tolerance (default=1e-5)- Returns:
true
if normalized, otherwisefalse
-
isRotationIdentity
public boolean isRotationIdentity()Test whether the quaternion represents an identity rotation. The quaternion is unaffected.- Specified by:
isRotationIdentity
in interfaceQuatArg
- Returns:
true
if the real component is a non-zero number and the imaginary components are all zero, otherwisefalse
-
isZero
public boolean isZero()Test whether the quaternion is zero. The quaternion is unaffected. -
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:
normalized
in interfaceQuatArg
- Returns:
- a new quaternion
-
put
Write all 4 components to the specified buffer in XYZW order and advance the buffer's position by 4. The quaternion is unaffected. -
rotateAxisX
Apply the rotation to (1,0,0). The quaternion is assumed to be normalized and is unaffected.- Specified by:
rotateAxisX
in interfaceQuatArg
- Returns:
- a new vector
-
rotateAxisY
Apply the rotation to (0,1,0). The quaternion is assumed to be normalized and is unaffected.- Specified by:
rotateAxisY
in interfaceQuatArg
- Returns:
- a new vector
-
rotateAxisZ
Apply the rotation to (0,0,1). The quaternion is assumed to be normalized and is unaffected.- Specified by:
rotateAxisZ
in interfaceQuatArg
- Returns:
- a new vector
-
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)
-