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 |
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 |
fromRotation(start: Quaternion, end: 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 |
Quaternion |
slerp(start: Quaternion, end: Quaternion, ratio: Float)Returns a new quaternion that is spherically interpolated between |
Public companion properties |
|
|---|---|
Quaternion |
Public constructors |
|---|
Quaternion(other: Quaternion)Creates a new quaternion with the same values as the |
Quaternion(x: Float, y: Float, z: Float, w: Float) |
Public functions |
|
|---|---|
Quaternion |
Returns a copy of the quaternion. |
operator Quaternion |
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 |
open operator Boolean |
Returns true if this quaternion is equal to the |
open Int |
hashCode() |
inline operator Quaternion |
minus(other: Quaternion)Returns a new quaternion with the difference of this quaternion and the |
inline operator Quaternion |
plus(other: Quaternion)Returns a new quaternion with the sum of this quaternion and |
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 |
inline operator Vector3 |
Rotates a |
Quaternion |
Returns a new quaternion with a normalized rotation. |
open String |
toString() |
inline operator Quaternion |
Flips the sign of the quaternion, but represents the same rotation. |
Public properties |
|
|---|---|
Pair<Vector3, Float> |
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
fun angle(start: Quaternion, end: Quaternion): Float
Returns the angle between start and end quaternion in degrees.
dot
fun dot(lhs: Quaternion, rhs: Quaternion): Float
Returns the dot product of two quaternions.
fromAxisAngle
fun fromAxisAngle(axis: Vector3, degrees: Float): Quaternion
Creates a new quaternion using an axis/angle to define the rotation.
fromEulerAngles
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
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
fun fromLookTowards(forward: Vector3, up: Vector3): Quaternion
Returns a new quaternion with the specified forward and upward directions.
fromRotation
fun fromRotation(start: Quaternion, end: Quaternion): Quaternion
Returns a new quaternion representing the rotation from one quaternion to another.
fromRotation
fun fromRotation(start: Vector3, end: Vector3): Quaternion
Returns a new quaternion representing the rotation from one vector to another.
lerp
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
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
Public constructors
Quaternion
Quaternion(other: Quaternion)
Creates a new quaternion with the same values as the other quaternion.
Quaternion
Quaternion(x: Float = 0.0f, y: Float = 0.0f, z: Float = 0.0f, w: Float = 1.0f)
Public functions
copy
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
operator fun div(c: Float): Quaternion
Returns a new quaternion with this quaternion divided by a scalar amount.
dot
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.
minus
inline operator fun minus(other: Quaternion): Quaternion
Returns a new quaternion with the difference of this quaternion and the other quaternion.
plus
inline operator fun plus(other: Quaternion): Quaternion
Returns a new quaternion with the sum of this quaternion and other quaternion.
times
operator fun times(c: Float): Quaternion
Returns a new quaternion with the product of this quaternion and a scalar amount.
times
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
inline operator fun times(src: Vector3): Vector3
Rotates a Vector3 by this quaternion.
toNormalized
fun toNormalized(): Quaternion
Returns a new quaternion with a normalized rotation.
unaryMinus
inline operator fun unaryMinus(): Quaternion
Flips the sign of the quaternion, but represents the same rotation.
Public properties
axisAngle
val axisAngle: Pair<Vector3, Float>
Returns this quaternion as an axis/angle (in degrees) pair.
eulerAngles
val eulerAngles: Vector3
Returns this quaternion as Euler angles (in degrees) applied in YXZ (yaw, pitch, roll) order.
inverse
val inverse: Quaternion
Returns a new quaternion with the inverse rotation. Assumes unit length.