open class Quaternion(var w: Float = 1.0f, var x: Float = 0.0f, var y: Float = 0.0f, var z: Float = 0.0f)
Quaternion
(
pitch
, yaw
, roll
)
|
Constructor for creating a quaternion from pitch, yaw, and roll angles.
Signature
constructor(pitch: Float, yaw: Float, roll: Float) Parameters
pitch:
Float
yaw:
Float
roll:
Float
Returns |
Quaternion
(
w
, x
, y
, z
)
|
Signature
constructor(w: Float = 1.0f, x: Float = 0.0f, y: Float = 0.0f, z: Float = 0.0f) Parameters
w:
Float
x:
Float
y:
Float
z:
Float
Returns |
w
: Float
[Get][Set] |
w component of the quaternion.
Signature
open var w: Float |
x
: Float
[Get][Set] |
x component of the quaternion.
Signature
open var x: Float |
y
: Float
[Get][Set] |
y component of the quaternion.
Signature
open var y: Float |
z
: Float
[Get][Set] |
z component of the quaternion.
Signature
open var z: Float |
component1
()
|
Signature
operator fun component1(): Float Returns
Float
|
component2
()
|
Signature
operator fun component2(): Float Returns
Float
|
component3
()
|
Signature
operator fun component3(): Float Returns
Float
|
component4
()
|
Signature
operator fun component4(): Float Returns
Float
|
conjugate
()
|
Calculates the conjugate of the quaternion.
Signature
fun conjugate(): Quaternion |
copy
()
|
Returns a copy of this Quaternion.
Signature
fun copy(): Quaternion |
dot
(
other
)
|
Calculates the dot product of two quaternions.
Signature
fun dot(other: Quaternion): Float Parameters Returns
Float
|
equals
(
other
)
|
Signature
open operator override fun equals(other: Any?): Boolean Parameters
other:
Any?
Returns
Boolean
|
hashCode
()
|
Signature
open override fun hashCode(): Int Returns
Int
|
inverse
()
|
Calculates the inverse of the quaternion.
Signature
fun inverse(): Quaternion |
isWithinAngle
(
other
, angleRadians
)
|
Checks if the angular distance between this quaternion and another quaternion is within a specified tolerance in radians.
This method uses the industry-standard approach for comparing quaternion orientations: computing the angular distance between the two rotations using the dot product. It correctly handles the q vs -q equivalence (both represent the same rotation).
Note: This assumes both quaternions are normalized. For best results, normalize quaternions before comparison.
Signature
fun isWithinAngle(other: Quaternion, angleRadians: Float): Boolean Parameters
angleRadians:
Float
Returns
Boolean
|
isWithinAngleDegrees
(
other
, angleDegrees
)
|
Checks if the angular distance between this quaternion and another quaternion is within a specified tolerance in degrees.
This method uses the industry-standard approach for comparing quaternion orientations: computing the angular distance between the two rotations using the dot product. It correctly handles the q vs -q equivalence (both represent the same rotation).
Note: This assumes both quaternions are normalized. For best results, normalize quaternions before comparison.
Signature
fun isWithinAngleDegrees(other: Quaternion, angleDegrees: Float): Boolean Parameters
angleDegrees:
Float
Returns
Boolean
|
nlerp
(
dest
, ratio
)
|
Performs normalized linear interpolation between the current quaternion and the destination quaternion.
Signature
fun nlerp(dest: Quaternion, ratio: Float): Quaternion Parameters
ratio:
Float
Returns
A new quaternion that is the result of interpolating between the current quaternion and the destination quaternion by the given ratio.
|
norm
()
|
Calculates the squared magnitude (length) of the quaternion.
Signature
fun norm(): Float Returns
Float
|
normalize
()
|
Normalizes the quaternion to have a magnitude of 1.
Signature
fun normalize(): Quaternion |
removePitchAndRoll
()
|
Removes the pitch and roll components from the quaternion, leaving only the yaw component.
Signature
fun removePitchAndRoll(): Quaternion |
slerp
(
dest
, ratio
)
|
Performs spherical linear interpolation between the current quaternion and the destination quaternion.
Signature
fun slerp(dest: Quaternion, ratio: Float): Quaternion Parameters
ratio:
Float
Returns
A new quaternion that is the result of interpolating between the current quaternion and the destination quaternion by the given ratio.
|
times
(
q
)
|
Multiplies this quaternion with another quaternion.
Signature
inline operator fun times(q: Quaternion): Quaternion Parameters |
times
(
v
)
| |
toEuler
()
|
Converts the quaternion to Euler angles (pitch, yaw, roll).
Signature
fun toEuler(): Vector3 |
toRotationMatrix44
()
|
Converts the quaternion to a 4x4 rotation matrix.
Signature
fun toRotationMatrix44(): Matrix44 |
toString
()
|
Signature
open override fun toString(): String Returns
String
|
toVector4
()
|
Converts the quaternion to a 4D vector.
Signature
fun toVector4(): Vector4 |
unaryMinus
()
|
fromAxisAngle
(
axis
, angleDegrees
)
|
Creates a quaternion representing a rotation around an axis by a specified angle.
Signature
fun fromAxisAngle(axis: Vector3, angleDegrees: Float): Quaternion Parameters
angleDegrees:
Float
|
fromAxisAngleRadians
(
axis
, angleRadians
)
|
Creates a quaternion representing a rotation around an axis by a specified angle in radians.
Signature
fun fromAxisAngleRadians(axis: Vector3, angleRadians: Float): Quaternion Parameters
angleRadians:
Float
|
fromDirection
(
dirX
, dirY
, dirZ
, upX
, upY
, upZ
)
|
Creates a quaternion that rotates the +Z axis to point in the given direction.
Uses a lookAt-style approach consistent with GLM's quatLookAtLH. The resulting quaternion, when applied to a vector pointing in the +Z direction, will rotate it to align with the specified direction.
Signature
fun fromDirection(dirX: Float, dirY: Float, dirZ: Float, upX: Float = 0.0f, upY: Float = 1.0f, upZ: Float = 0.0f): Quaternion Parameters
dirX:
Float
dirY:
Float
dirZ:
Float
upX:
Float
upY:
Float
upZ:
Float
|
fromDirection
(
direction
, up
)
|
Creates a quaternion that rotates the +Z axis to point in the given direction.
Signature
fun fromDirection(direction: Vector3, up: Vector3 = Vector3.Up): Quaternion Parameters |
fromEuler
(
pitch
, yaw
, roll
)
|
Creates a quaternion from Euler angles (pitch, yaw, roll).
Signature
fun fromEuler(pitch: Float, yaw: Float, roll: Float): Quaternion Parameters
pitch:
Float
yaw:
Float
roll:
Float
|
fromEuler
(
euler
)
|
Creates a quaternion from a Vector3 containing Euler angles (pitch, yaw, roll).
Signature
fun fromEuler(euler: Vector3): Quaternion Parameters |
fromRotationMatrix
(
matrix
)
|
Creates a quaternion from a rotation matrix.
Signature
fun fromRotationMatrix(matrix: Array<FloatArray>): Quaternion Parameters
matrix:
Array
|
fromTwoVectors
(
from
, to
)
|
Creates a quaternion that rotates one vector to another.
Signature
fun fromTwoVectors(from: Vector3, to: Vector3): Quaternion Parameters |
getRandomQuat
()
|
Formula using "Choosing a Point from the Surface of a Sphere" authored by George Marsaglia Generates uniform random quaternion.
Signature
fun getRandomQuat(): Quaternion |
lookRotation
(
forward
, lookUp
)
|
Creates a quaternion that represents a rotation from the forward vector to the look-up vector.
Signature
fun lookRotation(forward: Vector3, lookUp: Vector3 = Vector3.Up): Quaternion Parameters Returns
A quaternion representing the rotation from the forward vector to the look-up vector.
|
lookRotationAroundY
(
forward
)
|
Creates a quaternion that represents a rotation around the Y-axis from the forward vector to the look-up vector.
Signature
fun lookRotationAroundY(forward: Vector3): Quaternion Parameters Returns
A quaternion representing the rotation around the Y-axis from the forward vector to the look-up vector.
|