Quaternion

The Quaternion class

Constructor

new Quaternion(xopt, yopt, zopt, wopt)

Parameters:
NameTypeAttributesDefaultDescription
xnumber<optional>
0

x coordinate

ynumber<optional>
0

y coordinate

znumber<optional>
0

z coordinate

wnumber<optional>
1

w coordinate

Members

w :number

Type:
  • number

w :number

Type:
  • number

x :number

Type:
  • number

x :number

Type:
  • number

y :number

Type:
  • number

y :number

Type:
  • number

z :number

Type:
  • number

z :number

Type:
  • number

Methods

clone() → {Quaternion}

Creates a new Quaternion with identical x, y, z and w properties to this one.

Returns:
Type: 
Quaternion

conjugate() → {Quaternion}

Returns the rotational conjugate of this quaternion. The conjugate of a quaternion represents the same rotation in the opposite direction about the rotational axis.

Returns:
Type: 
Quaternion

copy(quaternion) → {Quaternion}

Copies the x, y, z and w properties of q into this quaternion.

Parameters:
NameTypeDescription
quaternionQuaternion
Returns:
Type: 
Quaternion

dot(v) → {Quaternion}

Calculates the dot product of quaternions v and this one.

Parameters:
NameTypeDescription
vQuaternion
Returns:
Type: 
Quaternion

fromArray(array, offsetopt, denormalizeopt) → {Quaternion}

Sets this quaternion's x, y, z and w properties from an array.

Parameters:
NameTypeAttributesDefaultDescription
arrayArray.<number>

array of format (x, y, z, w) used to construct the quaternion.

offsetnumber<optional>
0

an offset into the array.

denormalizeboolean<optional>
false

if true, denormalize the values, and array should be a typed array.

Returns:
Type: 
Quaternion

length() → {number}

Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector.

Returns:
Type: 
number

lerpQuaternions(q1, q2, ratio) → {Quaternion}

Linearly interpolates between two quaternions.

Parameters:
NameTypeDescription
q1Quaternion
q2Quaternion
rationumber
Returns:
Type: 
Quaternion

multiply(q) → {Quaternion}

Multiplies this quaternion by q.

Parameters:
NameTypeDescription
qQuaternion
Returns:
Type: 
Quaternion

multiplyQuaternions(a, b) → {Quaternion}

Sets this quaternion to a x b.

Parameters:
NameTypeDescription
aQuaternion
bQuaternion
Returns:
Type: 
Quaternion

normalize() → {Quaternion}

Normalizes this quaternion - that is, calculated the quaternion that performs the same rotation as this one, but has length equal to 1.

Returns:
Type: 
Quaternion

onChange(callback) → {Quaternion}

Parameters:
NameTypeDescription
callbackfunction

When the Quaternion angle value changes, the callback method is triggered

Returns:
Type: 
Quaternion

premultiply(q) → {Quaternion}

Pre-multiplies this quaternion by q.

Parameters:
NameTypeDescription
qQuaternion
Returns:
Type: 
Quaternion

set(x, y, z, w) → {Quaternion}

Sets x, y, z, w properties of this quaternion.

Parameters:
NameTypeDefaultDescription
xnumber0
ynumber0
znumber0
wnumber1
Returns:
Type: 
Quaternion

setFromAxisAngle(axis, angle) → {Quaternion}

Set quaternion from axis angle

Parameters:
NameTypeDescription
axisVector3
anglenumber
Returns:
Type: 
Quaternion

setFromEuler(euler, updateopt) → {Quaternion}

Sets this quaternion from the rotation specified by Euler angle.

Parameters:
NameTypeAttributesDefaultDescription
eulerEuler
updateboolean<optional>
true

Whether to notify quaternion angle has changed

Returns:
Type: 
Quaternion

setFromRotationMatrix(m) → {Quaternion}

Sets this quaternion from rotation component of m.

Parameters:
NameTypeDescription
mMatrix4
Returns:
Type: 
Quaternion

setFromUnitVectors(vFrom, vTo) → {Quaternion}

vFrom and vTo are assumed to be normalized.

Parameters:
NameTypeDescription
vFromVector3
vToVector3
Returns:
Type: 
Quaternion

slerpQuaternions(q1, q2, ratio) → {Quaternion}

Spherically interpolates between two quaternions providing an interpolation between rotations with constant angle change rate.

Parameters:
NameTypeDescription
q1Quaternion
q2Quaternion
rationumber
Returns:
Type: 
Quaternion

toArray(arrayopt, offsetopt, normalizeopt) → {Quaternion}

Returns the numerical elements of this quaternion in an array of format [x, y, z, w].

Parameters:
NameTypeAttributesDefaultDescription
arrayArray.<number><optional>

An array to store the quaternion. If not specified, a new array will be created.

offsetnumber<optional>
0

An offset into the array.

normalizeboolean<optional>
false

if true, normalize the values, and array should be a typed array.

Returns:
Type: 
Quaternion

toMatrix4(target) → {Matrix4}

Convert the current quaternion to a matrix4

Parameters:
NameTypeDescription
targetMatrix4
Returns:
Type: 
Matrix4

(static) multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) → {Array.<number>}

Multipley quaternions, but operates directly on flat arrays of numbers.

Parameters:
NameTypeDescription
dstArray.<number>

The output array.

dstOffsetnumber

An offset into the output array.

src0Array.<number>

The source array of the starting quaternion.

srcOffset0number

An offset into the array src0.

src1Array.<number>

The source array of the target quatnerion.

srcOffset1number

An offset into the array src1.

Returns:
Type: 
Array.<number>

(static) slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t)

Slerp method, operates directly on flat arrays of numbers.

Parameters:
NameTypeDescription
dstArray.<number>

The output array.

dstOffsetnumber

An offset into the output array.

src0Array.<number>

The source array of the starting quaternion.

srcOffset0number

An offset into the array src0.

src1Array.<number>

The source array of the target quatnerion.

srcOffset1number

An offset into the array src1.

tnumber

Normalized interpolation factor (between 0 and 1).