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.

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.

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.

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-alpha10
fun angle(start: Quaternion, end: Quaternion): Float

Returns the angle between start and end quaternion in degrees.

Parameters
start: Quaternion

the starting quaternion

end: Quaternion

the ending quaternion

dot

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

Returns the dot product of two quaternions.

Parameters
lhs: Quaternion

the first quaternion

rhs: Quaternion

the second quaternion

fromAxisAngle

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

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

Parameters
axis: Vector3

the axis of rotation

degrees: Float

the angle of rotation in degrees

fromEulerAngles

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

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

Parameters
eulerAngles: Vector3

the Euler angles in degrees

fromEulerAngles

Added in 1.0.0-alpha10
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.

Parameters
pitch: Float

the pitch in degrees

yaw: Float

the yaw in degrees

roll: Float

the roll in degrees

fromLookTowards

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

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

Parameters
forward: Vector3

the forward direction

up: Vector3

the upward direction

fromRotation

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

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

Parameters
start: Quaternion

the starting quaternion

end: Quaternion

the ending quaternion

fromRotation

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

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

Parameters
start: Vector3

the starting vector

end: Vector3

the ending vector

lerp

Added in 1.0.0-alpha10
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.

Parameters
start: Quaternion

the starting quaternion

end: Quaternion

the ending quaternion

ratio: Float

the interpolation ratio

slerp

Added in 1.0.0-alpha10
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.

Parameters
start: Quaternion

the starting quaternion

end: Quaternion

the ending quaternion

ratio: Float

the interpolation ratio

Public companion properties

Identity

val IdentityQuaternion

Public constructors

Quaternion

Added in 1.0.0-alpha10
Quaternion(other: Quaternion)

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

Quaternion

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

Public functions

copy

Added in 1.0.0-alpha10
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.

Parameters
x: Float = this.x

the new x value for the copied quaternion

y: Float = this.y

the new y value for the copied quaternion

z: Float = this.z

the new z value for the copied quaternion

w: Float = this.w

the new w value for the copied quaternion

dot

Added in 1.0.0-alpha10
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-alpha10
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-alpha10
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-alpha10
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-alpha10
inline operator fun times(src: Vector3): Vector3

Rotates a Vector3 by this quaternion.

Parameters
src: Vector3

the vector to rotate

toString

open fun toString(): String

unaryMinus

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

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

Public properties

axisAngle

Added in 1.0.0-alpha10
val axisAnglePair<Vector3Float>

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

eulerAngles

Added in 1.0.0-alpha10
val eulerAnglesVector3

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

inverse

Added in 1.0.0-alpha10
val inverseQuaternion

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

w

Added in 1.0.0-alpha10
val wFloat

The normalized w component of the quaternion.

x

Added in 1.0.0-alpha10
val xFloat

The normalized x component of the quaternion.

y

Added in 1.0.0-alpha10
val yFloat

The normalized y component of the quaternion.

z

Added in 1.0.0-alpha10
val zFloat

The normalized z component of the quaternion.