Quaternion

class Quaternion(x: Double = 0.0, y: Double = 0.0, z: Double = 0.0, w: Double = 1.0) : Iterable<Double>

A quaternion, used in three.js to represent rotations.

Iterating through an instance yields its components (x, y, z, w) in order.

three.js expects quaternions to be normalized.

Instances are mutable and not thread-safe; confine an instance (and any object graph holding it) to a single thread, exactly as in three.js.

Reading x/y/z/w has no side effect. Writing any of them, or calling a mutating method, fires the registered onChange callback (see that method).

Constructors

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

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
var w: Double

The w value of this quaternion. Assigning fires the onChange callback.

Link copied to clipboard
var x: Double

The x value of this quaternion. Assigning fires the onChange callback.

Link copied to clipboard
var y: Double

The y value of this quaternion. Assigning fires the onChange callback.

Link copied to clipboard
var z: Double

The z value of this quaternion. Assigning fires the onChange callback.

Functions

Link copied to clipboard

Returns the angle between this quaternion and q in radians.

Link copied to clipboard

Returns a new quaternion with copied values from this instance.

Link copied to clipboard

Returns the rotational conjugate of this quaternion: the same rotation in the opposite direction about the rotational axis.

Link copied to clipboard
fun copy(quaternion: Quaternion): Quaternion

Copies the values of quaternion into this instance.

Link copied to clipboard

Returns the dot product of this quaternion and v.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Structural equality: true when other is a Quaternion with equal components (component-wise ==, so NaN != NaN).

Link copied to clipboard
fun fromArray(array: DoubleArray, offset: Int = 0): Quaternion

Sets this quaternion's components from array starting at offset.

Link copied to clipboard

Sets the components of this quaternion from attribute at index.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Sets this quaternion to the identity quaternion (no rotation).

Link copied to clipboard

Inverts this quaternion via conjugate. The quaternion is assumed to have unit length.

Link copied to clipboard
open operator override fun iterator(): Iterator<Double>
Link copied to clipboard
fun length(): Double

Returns the Euclidean length of this quaternion (as a 4D vector).

Link copied to clipboard

Returns the squared Euclidean length of this quaternion (as a 4D vector).

Link copied to clipboard

Multiplies this quaternion by q.

Link copied to clipboard

Multiplies a and b and stores the result in this instance.

Link copied to clipboard

Normalizes this quaternion. It computes the quaternion that performs the same rotation but has length 1. A zero-length quaternion becomes the identity.

Link copied to clipboard
fun onChange(callback: () -> Unit): Quaternion

Registers callback to run whenever this quaternion's state changes (via a component setter or a mutating method). Reads never fire it.

Link copied to clipboard

Pre-multiplies this quaternion by q.

Link copied to clipboard

Sets this quaternion to a uniformly random, normalized quaternion.

Link copied to clipboard

Rotates this quaternion by an angular step (in radians) toward q, without overshooting it.

Link copied to clipboard
fun set(x: Double, y: Double, z: Double, w: Double): Quaternion

Sets the quaternion components.

Link copied to clipboard

Sets this quaternion from the given axis and angle.

Link copied to clipboard
fun setFromEuler(euler: Euler, update: Boolean = true): Quaternion

Sets this quaternion from the rotation specified by the given Euler angles.

Link copied to clipboard

Sets this quaternion from the given rotation matrix m (the upper 3x3 of which must be an unscaled rotation).

Link copied to clipboard

Sets this quaternion to the rotation required to rotate the direction vector vFrom to the direction vector vTo. Both are assumed normalized.

Link copied to clipboard

Performs a spherical linear interpolation between this quaternion and qb by factor t. Values in [0, 1] interpolate; values outside extrapolate.

Link copied to clipboard

Performs a spherical linear interpolation between qa and qb and stores the result in this quaternion.

Link copied to clipboard
fun toArray(array: MutableList<Double> = mutableListOf(), offset: Int = 0): MutableList<Double>

Writes the components of this quaternion into array at offset, growing the list as needed, and returns it.

Link copied to clipboard

Serialization result: the components of this quaternion as [x, y, z, w].

Link copied to clipboard
open override fun toString(): String