Optionalx: number = 0
x of the vector part
Optionaly: number = 0
y of the vector part
Optionalz: number = 0
z of the vector part
Optionalw: number = 1
the scalar part; 1 (with the rest 0) is no rotation
Turn a vector by this rotation, in place: what Matrix3d#apply does with a matrix. The vector is changed and returned, not this quaternion.
the vector to turn
v, turned
Turn a vector by the inverse of this rotation, in place: what Matrix3d#applyInverse does with a matrix. The vector is changed and returned, not this quaternion.
the vector to turn back
v, turned back
Copy another quaternion into this one.
the quaternion to copy
this, for chaining
The dot product with another quaternion: the cosine of half the angle between the two orientations, for unit ones.
the other quaternion
the dot product
Whether q holds the same components, within epsilon.
the quaternion to compare with
Optionalepsilon: number = 0
the tolerance per component
true if they match
Set from an array [x, y, z, w], as glTF stores a rotation.
the four components
this, for chaining
The rotation held in a matrix: its upper 3×3. A scale along each axis
is taken out, so a renderable's currentTransform can be read as it
is; a mirror or a shear is not, and a matrix with an axis scaled to
nothing gives no rotation. The inverse of Quaternion#toMatrix3d.
the matrix to read
this, for chaining
Turn this into the opposite rotation. For a unit quaternion this is
its conjugate, (-x, -y, -z, w). A zero quaternion, or one that is
not a finite number, becomes no rotation.
this, for chaining
Whether this is no rotation. q and -q are the same orientation, so
(0, 0, 0, -1) counts too.
true if it turns nothing
The length, 1 for a rotation.
the length
Compose two rotations: this = this × q, so q is applied first and
this one after it, as with Matrix3d#multiply.
the rotation applied first
this, for chaining
Scale to unit length, so it is a rotation again after rounding has drifted it. A zero quaternion becomes no rotation.
this, for chaining
Compose the other way round: this = q × this, so this rotation is
applied first and q after it.
the rotation applied after
this, for chaining
Turn this rotation further by angle radians about an axis, as
Matrix3d#rotate turns a matrix: this = this × R(axis, angle),
so the new turn is applied first, then this one. On a new quaternion,
that is simply the turn. The axis defaults to Z and need not be of unit
length; an axis of length 0, or an angle or axis that is not a finite
number, turns nothing.
the angle, in radians
Optionalv: Vector3d
the axis to turn about (defaults to Z)
this, for chaining
Set the four components.
x of the vector part
y of the vector part
z of the vector part
the scalar part
this, for chaining
The shortest turn that takes the direction from onto the direction
to. Neither needs to be of unit length. Two opposite directions are
joined by a half turn about an axis square to them; a direction of
length 0, or one that is not a number, gives no rotation.
this, for chaining
Turn part of the way toward q, along the shortest arc: t = 0 is
this, t = 1 is q, at an even angular speed in between.
the orientation to turn toward
how far, 0 to 1
this, for chaining
The components as an array, [x, y, z, w], the order glTF stores
rotations in.
the array
A readable form, for logging.
the components
An orientation in 3D: a rotation about an axis, stored as a unit quaternion
(x, y, z, w). What a 3D physics body's rotation is read and written as (PhysicsAdapter.getRotation, PhysicsAdapter.setRotation), and handy wherever turns are composed or blended, as it has none of the gimbal lock of three Euler angles.(0, 0, 0, 1)is no rotation. Rotations follow the right-hand rule in the engine's own space (Y-down, +Z forward, the Camera3d convention), as Matrix3d#rotate does.Its methods read as a Matrix3d's do: a new one is no rotation,
rotate(angle, axis)turns it further,multiplycomposes,invert,apply(v)/applyInverse(v)turn a vector, andfromMat3d/toMatrix3dconvert, asMatrix2d#fromMat3dandMatrix3d#toMatrix2ddo.Example