Quaternion
new Quaternion(x, y, z, w)
Quaternion representation of a rotation.
Parameters
| x number | The x component. |
| y number | The y component. |
| z number | The z component. |
| w number | The w component. |
Properties
| x number | The x component. |
| y number | The y component. |
| z number | The z component. |
| w number | The w component. |
Methods
set(x, y, z, w)
Set the components of this quaternion.
Parameters
| x* number | The x component. |
| y* number | The y component. |
| z* number | The z component. |
| w* number | The w component. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
copy(quaternion)
Copy the components from another quaternion.
Parameters
| quaternion* | The quaternion to copy. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
setFromAxisAngle(axis, angle)
Set this quaternion from an axis and angle.
Parameters
| axis* | The axis (assumed to be normalized). |
| angle* number | The angle in radians. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
setFromRotationMatrix(m)
Set this quaternion from a rotation matrix.
Parameters
| m* | A 4x4 matrix with a pure rotation in the upper 3x3. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
setFromUnitVectors(vFrom, vTo)
Set this quaternion from two unit vectors.
Parameters
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
invert()
Invert this quaternion.
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
conjugate()
Calculate the conjugate of this quaternion. For a normalized quaternion this is also its inverse.
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
dot(v)
Calculate the dot product of this quaternion and another.
Parameters
| v* | The other quaternion. |
Returns
| type | description |
|---|---|
| number | The dot product. |
lengthSq()
Calculate the squared length of this quaternion.
Returns
| type | description |
|---|---|
| number | The squared length. |
length()
Calculate the length of this quaternion.
Returns
| type | description |
|---|---|
| number | The length. |
normalize()
Normalize this quaternion.
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
multiply(q)
Multiply this quaternion by another quaternion.
Parameters
| q* | The quaternion to multiply by. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
multiplyQuaternions(a, b)
Set this quaternion to the product of two quaternions.
Parameters
| a* | The first quaternion. |
| b* | The second quaternion. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
slerp(qb, t)
Spherical linear interpolation between this quaternion and another.
Parameters
| qb* | The other quaternion. |
| t* number | The interpolation factor between 0 and 1. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
slerpQuaternions(qa, qb, t)
Linear spherical interpolation between the given quaternions. The result is stored in this quaternion.
Parameters
| qa* | The initial quaternion. |
| qb* | The final quaternion. |
| t* number | The interpolation factor in the interval [0, 1]. |
Returns
| type | description |
|---|---|
| Quaternion | This quaternion. |
equals(quaternion)
Check if this quaternion equals another quaternion.
Parameters
| quaternion* | The quaternion to compare. |
Returns
| type | description |
|---|---|
| boolean | True if the quaternions are equal. |
fromArray(array, offset)
Set this quaternion from an array.
Parameters
| array* Array.<number> | The source array. |
| offset number | The offset into the array. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
toArray(array, offset)
Convert this quaternion to an array.
Parameters
| array Array.<number> | The target array. |
| offset number | The offset into the array. |
Returns
| type | description |
|---|---|
| Array.<number> | The array [x, y, z, w]. |
onChange(callback)
Set the callback function to be called when this quaternion changes.
Parameters
| callback* function | The callback function. |
Returns
| type | description |
|---|---|
| Quaternion | A reference to this quaternion. |
clone()
Create a clone of this quaternion.
Returns
| type | description |
|---|---|
| Quaternion | A new quaternion with the same components. |
slerp(qa, qb, qm, t)
Static method for linear spherical interpolation between the given quaternions. The result is stored in qm.
Parameters
| qa* | The initial quaternion. |
| qb* | The final quaternion. |
| qm* | The interpolated quaternion. |
| t* number | The interpolation factor in the interval [0, 1]. |
Returns
| type | description |
|---|---|
| Quaternion | qm |