API reference
API reference
Select your platform
No SDKs available
No versions available

Quaternion

Quaternion

data class Quaternion(var w: Float = 1.0f, var x: Float = 0.0f, var y: Float = 0.0f, var z: Float = 0.0f)
Quaternion class for representing 3D rotations.
This class provides methods for creating quaternions from various sources, such as pitch, yaw, and roll angles, rotation matrices, and random values. Provides operator overloading for unary minus and multiplication with other quaternions and vectors.

Constructors

NameSummary
Quaternion
constructor(pitch: Float, yaw: Float, roll: Float)
Constructor for creating a quaternion from pitch, yaw, and roll angles.
constructor(w: Float = 1.0f, x: Float = 0.0f, y: Float = 0.0f, z: Float = 0.0f)

Types

NameSummary
Companion
object Companion

Properties

NameSummary
w
var w: Float
x
var x: Float
y
var y: Float
z
var z: Float

Functions

NameSummary
conjugate
fun conjugate(): Quaternion
Calculates the conjugate of the quaternion.
dot
fun dot(other: Quaternion): Float
Calculates the dot product of two quaternions.
inverse
fun inverse(): Quaternion
Calculates the inverse of the quaternion.
nlerp
fun nlerp(dest: Quaternion, ratio: Float): Quaternion
Performs normalized linear interpolation between the current quaternion and the destination quaternion.
norm
fun norm(): Float
Calculates the squared magnitude (length) of the quaternion.
normalize
fun normalize(): Quaternion
Normalizes the quaternion to have a magnitude of 1.
removePitchAndRoll
fun removePitchAndRoll(): Quaternion
Removes the pitch and roll components from the quaternion, leaving only the yaw component.
slerp
fun slerp(dest: Quaternion, ratio: Float): Quaternion
Performs spherical linear interpolation between the current quaternion and the destination quaternion.
times
operator fun times(q: Quaternion): Quaternion
Multiplies this quaternion with another quaternion.
operator fun times(v: Vector3): Vector3
Multiplies this quaternion with a vector.
toEuler
fun toEuler(): Vector3
Converts the quaternion to Euler angles (pitch, yaw, roll).
toRotationMatrix44
fun toRotationMatrix44(): Matrix44
Converts the quaternion to a 4x4 rotation matrix.
toString
open override fun toString(): String
toVector4
fun toVector4(): Vector4
Converts the quaternion to a 4D vector.
unaryMinus
operator fun unaryMinus(): Quaternion
Negates the quaternion.

Companion

object Companion

Properties

NameSummary
rnd_
val rnd_: Random

Functions

NameSummary
fromRotationMatrix
fun fromRotationMatrix(matrix: Array<FloatArray>): Quaternion
Creates a quaternion from a rotation matrix.
getRandomQuat
fun getRandomQuat(): Quaternion
Formula using "Choosing a Point from the Surface of a Sphere" authored by George Marsaglia Generates uniform random quaternion. Code modified from https://stackoverflow.com/questions/31600717/how-to-generate-a-random-quaternion-quickly
lookRotation
fun lookRotation(forward: Vector3, lookUp: Vector3 = Vector3.Up): Quaternion
Creates a quaternion that represents a rotation from the forward vector to the look-up vector.
lookRotationAroundY
fun lookRotationAroundY(forward: Vector3): Quaternion
Creates a quaternion that represents a rotation around the Y-axis from the forward vector to the look-up vector.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon