Quaternion

data class Quaternion(var x: Float = 0.0f, var y: Float = 0.0f, var z: Float = 0.0f, var w: Float = 1.0f)

A quaternion of single-precision floats used for 3D rotations and orientations. The quaternion is normalized during construction if no parameters are specified.

Constructors

Link copied to clipboard
constructor(x: Float = 0.0f, y: Float = 0.0f, z: Float = 0.0f, w: Float = 1.0f)

Creates a new quaternion with the specified components.

constructor(v: Float3, w: Float = 1.0f)

Creates a Quaternion from a Float3 for the imaginary part and a Float for the real part.

constructor(v: Float4)

Creates a Quaternion from a Float4 representing (x, y, z, w).

constructor(q: Quaternion)

Creates a new quaternion from the specified quaternion q.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The imaginary part (x, y, z) of this quaternion as a Float3.

Link copied to clipboard
var real: Float

The real part (w) of this quaternion.

Link copied to clipboard
var w: Float

The W (real) component of the quaternion.

Link copied to clipboard
var x: Float

The X (imaginary) component of the quaternion.

Link copied to clipboard
var xyz: Float3

The imaginary part (x, y, z) of this quaternion as a Float3.

Link copied to clipboard

This quaternion as a Float4 representing (x, y, z, w).

Link copied to clipboard
var y: Float

The Y (imaginary) component of the quaternion.

Link copied to clipboard
var z: Float

The Z (imaginary) component of the quaternion.

Functions

Link copied to clipboard
inline fun compareTo(v: Float4, delta: Float = 0.0f): Float4

Compares two quaternions.

inline fun compareTo(v: Float, delta: Float = 0.0f): Float4

Compares this quaternion to a scalar.

Link copied to clipboard
inline operator fun div(v: Float): Quaternion

Divides all components of this quaternion by a scalar.

Link copied to clipboard
infix inline fun Quaternion.eq(b: Float4): Bool4

Returns a Bool4 indicating if each component of this quaternion is equal to the corresponding component of b.

infix inline fun Quaternion.eq(b: Float): Bool4

Returns a Bool4 indicating if each component of this quaternion is equal to b.

Link copied to clipboard
inline fun equals(v: Float4, delta: Float = 0.0f): Bool4

Returns true if two quaternions are equal.

inline fun equals(v: Float, delta: Float = 0.0f): Bool4

Returns true if all components are equal to the scalar.

Link copied to clipboard
operator fun get(index: QuaternionComponent): Float

Returns the component at the specified index.

operator fun get(index: Int): Float

Returns the component at the specified index (0 to 3).

operator fun get(index1: QuaternionComponent, index2: QuaternionComponent, index3: QuaternionComponent): Float3
operator fun get(index1: Int, index2: Int, index3: Int): Float3

Returns three components at the specified indices as a Float3.

operator fun get(index1: Int, index2: Int, index3: Int, index4: Int): Quaternion

Returns four components at the specified indices as a Quaternion.

Link copied to clipboard
infix inline fun Quaternion.gt(b: Float4): Bool4

Returns a Bool4 indicating if each component of this quaternion is greater than the corresponding component of b.

infix inline fun Quaternion.gt(b: Float): Bool4

Returns a Bool4 indicating if each component of this quaternion is greater than b.

Link copied to clipboard
infix inline fun Quaternion.gte(b: Float4): Bool4

Returns a Bool4 indicating if each component of this quaternion is greater than or equal to the corresponding component of b.

infix inline fun Quaternion.gte(b: Float): Bool4

Returns a Bool4 indicating if each component of this quaternion is greater than or equal to b.

Link copied to clipboard
inline operator fun invoke(index: Int): Float

Returns the component at the specified index (1 to 4).

Link copied to clipboard
infix inline fun Quaternion.lt(b: Float4): Bool4

Returns a Bool4 indicating if each component of this quaternion is less than the corresponding component of b.

infix inline fun Quaternion.lt(b: Float): Bool4

Returns a Bool4 indicating if each component of this quaternion is less than b.

Link copied to clipboard
infix inline fun Quaternion.lte(b: Float4): Bool4

Returns a Bool4 indicating if each component of this quaternion is less than or equal to the corresponding component of b.

infix inline fun Quaternion.lte(b: Float): Bool4

Returns a Bool4 indicating if each component of this quaternion is less than or equal to b.

Link copied to clipboard
inline operator fun minus(q: Quaternion): Quaternion

Subtracts two quaternions.

inline operator fun minus(v: Float): Quaternion

Subtracts a scalar from all components of this quaternion.

Link copied to clipboard
infix inline fun Quaternion.neq(b: Float4): Bool4

Returns a Bool4 indicating if each component of this quaternion is not equal to the corresponding component of b.

infix inline fun Quaternion.neq(b: Float): Bool4

Returns a Bool4 indicating if each component of this quaternion is not equal to b.

Link copied to clipboard
inline operator fun plus(q: Quaternion): Quaternion

Adds two quaternions.

inline operator fun plus(v: Float): Quaternion

Adds a scalar to all components of this quaternion.

Link copied to clipboard
operator fun set(index: QuaternionComponent, v: Float)

Sets the component at the specified index.

operator fun set(index: Int, v: Float)

Sets the component at the specified index (0 to 3).

operator fun set(index1: QuaternionComponent, index2: QuaternionComponent, v: Float)
operator fun set(index1: Int, index2: Int, v: Float)
operator fun set(index1: QuaternionComponent, index2: QuaternionComponent, index3: QuaternionComponent, v: Float)
operator fun set(index1: Int, index2: Int, index3: Int, v: Float)
operator fun set(index1: QuaternionComponent, index2: QuaternionComponent, index3: QuaternionComponent, index4: QuaternionComponent, v: Float)
operator fun set(index1: Int, index2: Int, index3: Int, index4: Int, v: Float)

Sets the components at the specified indices.

Link copied to clipboard
inline operator fun times(v: Float3): Float3

Rotates a vector by this quaternion.

inline operator fun times(q: Quaternion): Quaternion

Multiplies two quaternions.

inline operator fun times(v: Float): Quaternion

Multiplies all components of this quaternion by a scalar.

Link copied to clipboard

Converts this quaternion to Euler angles (in degrees).

Link copied to clipboard

Returns the components of this quaternion as a FloatArray.

Link copied to clipboard
fun toMatrix(): Mat4

Converts this quaternion to a rotation matrix.

Link copied to clipboard
inline fun transform(block: (Float) -> Float): Quaternion

Transforms each component of this quaternion using the provided block.

Link copied to clipboard
operator fun unaryMinus(): Quaternion

Negates all components of this quaternion.