Quaternion


class Quaternion


Represents a rotation component in three-dimensional space. Any vector can be provided and the resulting quaternion will be normalized at construction time.

Summary

Public companion functions

Float
angle(start: Quaternion, end: Quaternion)

Returns the angle between start and end quaternion in degrees.

Float
dot(lhs: Quaternion, rhs: Quaternion)

Returns the dot product of two quaternions.

Quaternion
fromAxisAngle(axis: Vector3, degrees: Float)

Creates a new quaternion using an axis/angle to define the rotation.

Quaternion
fromEulerAngles(eulerAngles: Vector3)

Returns a new quaternion using Euler angles (in degrees) to define the rotation in YXZ (yaw, pitch, roll) order.

Quaternion
fromEulerAngles(pitch: Float, yaw: Float, roll: Float)

Returns a new quaternion using Euler angles (in degrees) to define the rotation in YXZ (yaw, pitch, roll) order.

Quaternion
fromLookTowards(forward: Vector3, up: Vector3)

Returns a new quaternion with the specified forward and upward directions.

Quaternion

Returns a new quaternion representing the rotation from one quaternion to another.

Quaternion
fromRotation(start: Vector3, end: Vector3)

Returns a new quaternion representing the rotation from one vector to another.

Quaternion
lerp(start: Quaternion, end: Quaternion, ratio: Float)

Returns a new quaternion that is linearly interpolated between start and end using the interpolation amount ratio.

Quaternion
slerp(start: Quaternion, end: Quaternion, ratio: Float)

Returns a new quaternion that is spherically interpolated between start and end using the interpolation amount ratio.

Public companion properties

Quaternion

Public constructors

Creates a new quaternion with the same values as the other quaternion.

Quaternion(x: Float, y: Float, z: Float, w: Float)

Public functions

Quaternion
copy(x: Float, y: Float, z: Float, w: Float)

Returns a copy of the quaternion.

operator Quaternion
div(c: Float)

Returns a new quaternion with this quaternion divided by a scalar amount.

inline infix Float
dot(other: Quaternion)

Returns the dot product of this quaternion and the other quaternion.

open operator Boolean
equals(other: Any?)

Returns true if this quaternion is equal to the other.

open Int
inline operator Quaternion
minus(other: Quaternion)

Returns a new quaternion with the difference of this quaternion and the other quaternion.

inline operator Quaternion
plus(other: Quaternion)

Returns a new quaternion with the sum of this quaternion and other quaternion.

operator Quaternion

Returns a new quaternion with the product of this quaternion and a scalar amount.

inline operator Quaternion
times(other: Quaternion)

Returns a new quaternion with the product of this quaternion and the other quaternion.

inline operator Vector3
times(src: Vector3)

Rotates a Vector3 by this quaternion.

Quaternion

Returns a new quaternion with a normalized rotation.

open String
inline operator Quaternion

Flips the sign of the quaternion, but represents the same rotation.

Public properties

Pair<Vector3Float>

Returns this quaternion as an axis/angle (in degrees) pair.

Vector3

Returns this quaternion as Euler angles (in degrees) applied in YXZ (yaw, pitch, roll) order.

Quaternion

Returns a new quaternion with the inverse rotation.

Float

The normalized w component of the quaternion.

Float

The normalized x component of the quaternion.

Float

The normalized y component of the quaternion.

Float

The normalized z component of the quaternion.

Public companion functions

angle

Added in 1.0.0-alpha01
fun angle(start: Quaternion, end: Quaternion): Float

Returns the angle between start and end quaternion in degrees.

dot

Added in 1.0.0-alpha01
fun dot(lhs: Quaternion, rhs: Quaternion): Float

Returns the dot product of two quaternions.

fromAxisAngle

Added in 1.0.0-alpha01
fun fromAxisAngle(axis: Vector3, degrees: Float): Quaternion

Creates a new quaternion using an axis/angle to define the rotation.

fromEulerAngles

Added in 1.0.0-alpha01
fun fromEulerAngles(eulerAngles: Vector3): Quaternion

Returns a new quaternion using Euler angles (in degrees) to define the rotation in YXZ (yaw, pitch, roll) order.

fromEulerAngles

Added in 1.0.0-alpha01
fun fromEulerAngles(pitch: Float, yaw: Float, roll: Float): Quaternion

Returns a new quaternion using Euler angles (in degrees) to define the rotation in YXZ (yaw, pitch, roll) order.

fromLookTowards

Added in 1.0.0-alpha01
fun fromLookTowards(forward: Vector3, up: Vector3): Quaternion

Returns a new quaternion with the specified forward and upward directions.

fromRotation

Added in 1.0.0-alpha01
fun fromRotation(start: Quaternion, end: Quaternion): Quaternion

Returns a new quaternion representing the rotation from one quaternion to another.

fromRotation

Added in 1.0.0-alpha01
fun fromRotation(start: Vector3, end: Vector3): Quaternion

Returns a new quaternion representing the rotation from one vector to another.

lerp

Added in 1.0.0-alpha01
fun lerp(start: Quaternion, end: Quaternion, ratio: Float): Quaternion

Returns a new quaternion that is linearly interpolated between start and end using the interpolation amount ratio.

If ratio is outside of the range [0, 1], the returned quaternion will be extrapolated.

slerp

Added in 1.0.0-alpha01
fun slerp(start: Quaternion, end: Quaternion, ratio: Float): Quaternion

Returns a new quaternion that is spherically interpolated between start and end using the interpolation amount ratio. If ratio is 0, this returns start. As ratio approaches 1, the result of this function may approach either +end or -end (whichever is closest to start).

If ratio is outside of the range [0, 1], the returned quaternion will be extrapolated.

Public companion properties

Identity

val IdentityQuaternion

Public constructors

Quaternion

Added in 1.0.0-alpha01
Quaternion(other: Quaternion)

Creates a new quaternion with the same values as the other quaternion.

Quaternion

Added in 1.0.0-alpha01
Quaternion(x: Float = 0.0f, y: Float = 0.0f, z: Float = 0.0f, w: Float = 1.0f)
Parameters
x: Float = 0.0f

the x value of the quaternion.

y: Float = 0.0f

the y value of the quaternion.

z: Float = 0.0f

the z value of the quaternion.

w: Float = 1.0f

the rotation of the unit vector, in radians.

Public functions

copy

Added in 1.0.0-alpha01
fun copy(x: Float = this.x, y: Float = this.y, z: Float = this.z, w: Float = this.w): Quaternion

Returns a copy of the quaternion.

div

Added in 1.0.0-alpha01
operator fun div(c: Float): Quaternion

Returns a new quaternion with this quaternion divided by a scalar amount.

dot

Added in 1.0.0-alpha01
inline infix fun dot(other: Quaternion): Float

Returns the dot product of this quaternion and the other quaternion.

equals

open operator fun equals(other: Any?): Boolean

Returns true if this quaternion is equal to the other.

hashCode

open fun hashCode(): Int

minus

Added in 1.0.0-alpha01
inline operator fun minus(other: Quaternion): Quaternion

Returns a new quaternion with the difference of this quaternion and the other quaternion.

plus

Added in 1.0.0-alpha01
inline operator fun plus(other: Quaternion): Quaternion

Returns a new quaternion with the sum of this quaternion and other quaternion.

times

Added in 1.0.0-alpha01
operator fun times(c: Float): Quaternion

Returns a new quaternion with the product of this quaternion and a scalar amount.

times

Added in 1.0.0-alpha01
inline operator fun times(other: Quaternion): Quaternion

Returns a new quaternion with the product of this quaternion and the other quaternion. The order of the multiplication is [this] * [other].

times

Added in 1.0.0-alpha01
inline operator fun times(src: Vector3): Vector3

Rotates a Vector3 by this quaternion.

toNormalized

Added in 1.0.0-alpha01
fun toNormalized(): Quaternion

Returns a new quaternion with a normalized rotation.

toString

open fun toString(): String

unaryMinus

Added in 1.0.0-alpha01
inline operator fun unaryMinus(): Quaternion

Flips the sign of the quaternion, but represents the same rotation.

Public properties

axisAngle

Added in 1.0.0-alpha01
val axisAnglePair<Vector3Float>

Returns this quaternion as an axis/angle (in degrees) pair.

eulerAngles

Added in 1.0.0-alpha01
val eulerAnglesVector3

Returns this quaternion as Euler angles (in degrees) applied in YXZ (yaw, pitch, roll) order.

inverse

Added in 1.0.0-alpha01
val inverseQuaternion

Returns a new quaternion with the inverse rotation. Assumes unit length.

w

Added in 1.0.0-alpha01
val wFloat

The normalized w component of the quaternion.

x

Added in 1.0.0-alpha01
val xFloat

The normalized x component of the quaternion.

y

Added in 1.0.0-alpha01
val yFloat

The normalized y component of the quaternion.

z

Added in 1.0.0-alpha01
val zFloat

The normalized z component of the quaternion.