Constructor
new Quaternion(xopt, yopt, zopt, wopt)
Constructs a new quaternion.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number | <optional> | 0 | The x value of this quaternion. |
y | number | <optional> | 0 | The y value of this quaternion. |
z | number | <optional> | 0 | The z value of this quaternion. |
w | number | <optional> | 1 | The w value of this quaternion. |
Members
(readonly) isQuaternion :boolean
This flag can be used for type testing.
- boolean
- Default Value
- true
w :number
The w value of this quaternion.
- number
- Default Value
- 1
x :number
The x value of this quaternion.
- number
- Default Value
- 0
y :number
The y value of this quaternion.
- number
- Default Value
- 0
z :number
The z value of this quaternion.
- number
- Default Value
- 0
Methods
angleTo(q) → {number}
Returns the angle between this quaternion and the given one in radians.
Name | Type | Description |
---|---|---|
q | Quaternion | The quaternion to compute the angle with. |
The angle in radians.
- Type:
- number
clone() → {Quaternion}
Returns a new quaternion with copied values from this instance.
A clone of this instance.
- 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.
A reference to this quaternion.
- Type:
- Quaternion
copy(quaternion) → {Quaternion}
Copies the values of the given quaternion to this instance.
Name | Type | Description |
---|---|---|
quaternion | Quaternion | The quaternion to copy. |
A reference to this quaternion.
- Type:
- Quaternion
dot(v) → {number}
Calculates the dot product of this quaternion and the given one.
Name | Type | Description |
---|---|---|
v | Quaternion | The quaternion to compute the dot product with. |
The result of the dot product.
- Type:
- number
equals(quaternion) → {boolean}
Returns true
if this quaternion is equal with the given one.
Name | Type | Description |
---|---|---|
quaternion | Quaternion | The quaternion to test for equality. |
Whether this quaternion is equal with the given one.
- Type:
- boolean
fromArray(array, offsetopt, denormalizeopt) → {Quaternion}
Sets this quaternion's components from the given array.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | Array.<number> | An array holding the quaternion component values. | ||
offset | number | <optional> | 0 | The offset into the array. |
denormalize | boolean | <optional> | false | If true, denormalize the values, and array should be a typed array. |
A reference to this quaternion.
- Type:
- Quaternion
identity() → {Quaternion}
Sets this quaternion to the identity quaternion; that is, to the quaternion that represents "no rotation".
A reference to this quaternion.
- Type:
- Quaternion
length() → {number}
Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector.
The Euclidean length.
- Type:
- number
lengthSq() → {number}
Computes the squared Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector. This can be useful if you are comparing the lengths of two quaternions, as this is a slightly more efficient calculation than Quaternion#length.
The squared Euclidean length.
- Type:
- number
lerpQuaternions(q1, q2, ratio) → {Quaternion}
Linearly interpolates between two quaternions.
Name | Type | Description |
---|---|---|
q1 | Quaternion | |
q2 | Quaternion | |
ratio | number |
- Type:
- Quaternion
multiply(q) → {Quaternion}
Multiplies this quaternion by the given one.
Name | Type | Description |
---|---|---|
q | Quaternion | The quaternion. |
A reference to this quaternion.
- Type:
- Quaternion
multiplyQuaternions(a, b) → {Quaternion}
Multiplies the given quaternions and stores the result in this instance.
Name | Type | Description |
---|---|---|
a | Quaternion | The first quaternion. |
b | Quaternion | The second quaternion. |
A reference to this quaternion.
- Type:
- Quaternion
normalize() → {Quaternion}
Normalizes this quaternion - that is, calculated the quaternion that performs the same rotation as this one, but has a length equal to 1
.
A reference to this quaternion.
- Type:
- Quaternion
onChange(callback) → {Quaternion}
Registers a callback that is called whenever the quaternion's angle value changes.
Name | Type | Description |
---|---|---|
callback | function | When the Quaternion angle value changes, the callback method is triggered |
A reference to this quaternion.
- Type:
- Quaternion
premultiply(q) → {Quaternion}
Pre-multiplies this quaternion by the given one.
Name | Type | Description |
---|---|---|
q | Quaternion | The quaternion. |
A reference to this quaternion.
- Type:
- Quaternion
set(x, y, z, w) → {Quaternion}
Sets the quaternion components.
Name | Type | Description |
---|---|---|
x | number | The x value of this quaternion. |
y | number | The y value of this quaternion. |
z | number | The z value of this quaternion. |
w | number | The w value of this quaternion. |
A reference to this quaternion.
- Type:
- Quaternion
setFromAxisAngle(axis, angle) → {Quaternion}
Sets this quaternion from the given axis and angle.
Name | Type | Description |
---|---|---|
axis | Vector3 | The normalized axis. |
angle | number | The angle in radians. |
A reference to this quaternion.
- Type:
- Quaternion
setFromEuler(euler, updateopt) → {Quaternion}
Sets this quaternion from the rotation specified by the given Euler angles.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
euler | Euler | The Euler angles. | ||
update | boolean | <optional> | true | Whether the internal |
A reference to this quaternion.
- Type:
- Quaternion
setFromRotationMatrix(m) → {Quaternion}
Sets this quaternion from the given rotation matrix.
Name | Type | Description |
---|---|---|
m | Matrix4 | A 4x4 matrix of which the upper 3x3 of matrix is a pure rotation matrix (i.e. unscaled). |
A reference to this quaternion.
- Type:
- Quaternion
setFromUnitVectors(vFrom, vTo) → {Quaternion}
Sets this quaternion to the rotation required to rotate the direction vector vFrom
to the direction vector vTo
.
Name | Type | Description |
---|---|---|
vFrom | Vector3 | The first (normalized) direction vector. |
vTo | Vector3 | The second (normalized) direction vector. |
A reference to this quaternion.
- Type:
- Quaternion
slerp(qb, t) → {Quaternion}
Performs a spherical linear interpolation between quaternions.
Name | Type | Description |
---|---|---|
qb | Quaternion | The target quaternion. |
t | number | The interpolation factor in the closed interval |
A reference to this quaternion.
- Type:
- Quaternion
slerpQuaternions(qa, qb, t) → {Quaternion}
Performs a spherical linear interpolation between the given quaternions and stores the result in this quaternion.
Name | Type | Description |
---|---|---|
qa | Quaternion | The source quaternion. |
qb | Quaternion | The target quaternion. |
t | number | The interpolation factor in the closed interval |
A reference to this quaternion.
- Type:
- Quaternion
toArray(arrayopt, offsetopt, normalizeopt) → {Quaternion}
Writes the components of this quaternion to the given array. If no array is provided, the method returns a new instance.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | Array.<number> | <optional> | [] | The target array holding the quaternion components. |
offset | number | <optional> | 0 | Index of the first element in the array. |
normalize | boolean | <optional> | false | If true, normalize the values, and array should be a typed array. |
The quaternion components.
- Type:
- Quaternion
toMatrix4(target) → {Matrix4}
Convert the current quaternion to a matrix4.
Name | Type | Description |
---|---|---|
target | Matrix4 | The target matrix to write the quaternion data to. |
The target matrix with the quaternion data written to it.
- Type:
- Matrix4
(static) multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) → {Array.<number>}
Multiplies two quaternions. This implementation assumes the quaternion data are managed in flat arrays.
Name | Type | Description |
---|---|---|
dst | Array.<number> | The destination array. |
dstOffset | number | An offset into the destination array. |
src0 | Array.<number> | The source array of the first quaternion. |
srcOffset0 | number | An offset into the first source array. |
src1 | Array.<number> | The source array of the second quaternion. |
srcOffset1 | number | An offset into the second source array. |
The destination array.
- Type:
- Array.<number>
(static) slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t)
Interpolates between two quaternions via SLERP. This implementation assumes the quaternion data are managed in flat arrays.
Name | Type | Description |
---|---|---|
dst | Array.<number> | The destination array. |
dstOffset | number | An offset into the destination array. |
src0 | Array.<number> | The source array of the first quaternion. |
srcOffset0 | number | An offset into the first source array. |
src1 | Array.<number> | The source array of the second quaternion. |
srcOffset1 | number | An offset into the second source array. |
t | number | The interpolation factor in the range |