Quaternion
A quaternion object, mostly used to represent rotations without gimbal lock.
Rotation quaternions must be unit length, q and -q represent the same rotation.
Operators:
quat * quat- Hamilton product,a * brotates bybfirst, then bya.quat * vec3- rotates the vector, returns a newVector3.quat / quat-a * b:getInverse(), the rotation frombtoa.quat + quat,quat - quat- component-wise.quat +- number,number +- quat- adds to / subtracts from the real part.quat * number,number * quat,quat / number- scales all components.quat ^ number- raises to the power ( scales the rotation angle ),number ^ quat- exponent.-quat- negates all components.
Constructor
Quaternion(r: number?, i: number?, j: number?, k: number?): QuaternionFields
| Name | Type | Description |
|---|---|---|
w | number | The real part ( r ), cos( angle / 2 ) for rotations. |
x | number | The first imaginary part ( i ), axis.x * sin( angle / 2 ) for rotations. |
y | number | The second imaginary part ( j ), axis.y * sin( angle / 2 ) for rotations. |
z | number | The third imaginary part ( k ), axis.z * sin( angle / 2 ) for rotations. |
Operators
| Operator | Operand | Result |
|---|---|---|
add | Quaternion | number | Quaternion |
sub | Quaternion | number | Quaternion |
mul | Vector3 | Vector3 |
mul | Quaternion | number | Quaternion |
div | Quaternion | number | Quaternion |
pow | number | Quaternion |
unm | | Quaternion |
Static functions
add | Adds another quaternion ( component-wise ) or a real number ( to w only ) to the quaternion. |
copy | Creates a new independent copy of the quaternion. |
div | Divides the quaternion by another quaternion ( self = self * value:getInverse() ) or by a number. |
dot | Calculates the dot product of two quaternions. |
exp | Raises e to the power of the quaternion. |
fromAngle3 | Creates a new quaternion from the given angle. |
fromAngles | Creates a new quaternion from the given Euler angles in degrees. |
fromAxisAngle | Creates a new quaternion from the rotation around the given axis ( right-hand rule ). |
fromMatrix | Creates a new quaternion from the unpacked 3x3 rotation matrix ( row-major ). |
fromVectors | Creates a new quaternion that rotates the from direction to the to direction along the shortest arc. |
fromVMatrix | Creates a new quaternion from the rotation part of the given matrix. |
getAngles | Returns the rotation of the quaternion as an angle. |
getLength | Calculates the length ( norm ) of the quaternion. |
getLengthSqr | Calculates the squared length ( norm ) of the quaternion. |
getRotatedVector3 | Returns a copy of the vector rotated by the quaternion, same as quat * vec3. |
identity | Creates a new identity quaternion ( 1, 0, 0, 0 ), which means no rotation. |
invert | Inverts the quaternion, so q * q:getInverse() is identity. |
lerp | Normalized linear interpolation ( nlerp ) between two quaternions along the shortest path. |
log | Calculates the natural logarithm of the quaternion, the inverse of exp. |
mul | Multiplies the quaternion by another quaternion ( Hamilton product, self = self * value ) or by a number. |
normalize | Scales the quaternion to the length of 1. |
pow | Raises the quaternion to the given power, same as quat ^ exponent. |
scale | Multiplies all components of the quaternion by the number. |
slerp | Spherical linear interpolation ( slerp ) between two unit quaternions along the shortest path. |
sub | Subtracts another quaternion ( component-wise ) or a real number ( from w only ) from the quaternion. |
toAngle3 | Returns the rotation of the quaternion as an angle. |
unpackAngles | Returns the unpacked Euler angles ( pitch, yaw, roll ) of the quaternion in degrees. |
#Quaternion.add
function Quaternion.add(self: Quaternion, value: Quaternion | number): Quaternion
Adds another quaternion ( component-wise ) or a real number ( to w only ) to the quaternion.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
value | Quaternion | number | The other quaternion or a real number. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, with the sum. |
#Quaternion.copy
function Quaternion.copy(self: Quaternion): Quaternion
Creates a new independent copy of the quaternion.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
Quaternion | copy | The new quaternion. |
#Quaternion.div
function Quaternion.div(self: Quaternion, value: Quaternion | number): Quaternion
Divides the quaternion by another quaternion ( self = self * value:getInverse() ) or by a number.
For rotations a / b is the rotation that turns b into a.
Division by a zero number is not checked and results in inf / nan components.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
value | Quaternion | number | The divisor quaternion or number. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, divided. |
#Quaternion.dot
function Quaternion.dot(self: Quaternion, quaternion: Quaternion): number
Calculates the dot product of two quaternions.
For unit quaternions it is cos( angle / 2 ) of the rotation between them, negative means they are more than 180 degrees apart.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
quaternion | Quaternion | The other quaternion. |
| Type | Name | Description |
|---|---|---|
number | dot_product | The dot product of two quaternions. |
#Quaternion.exp
function Quaternion.exp(self: Quaternion): Quaternion
Raises e to the power of the quaternion.
For a pure imaginary ( 0, axis * angle / 2 ) it returns the rotation quaternion of angle radians around axis.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, exponentiated. |
#Quaternion.fromAngle3
function Quaternion.fromAngle3(angle: Angle3): Quaternion
Creates a new quaternion from the given angle.
Same as AngleQuaternion in Source engine.
| Name | Type | Description |
|---|---|---|
angle | Angle3 | The angle. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The new unit quaternion. |
#Quaternion.fromAngles
function Quaternion.fromAngles(pitch: number, yaw: number, roll: number): Quaternion
Creates a new quaternion from the given Euler angles in degrees.
Same as AngleQuaternion in Source engine.
| Name | Type | Description |
|---|---|---|
pitch | number | The pitch in degrees. |
yaw | number | The yaw in degrees. |
roll | number | The roll in degrees. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The new unit quaternion. |
#Quaternion.fromAxisAngle
function Quaternion.fromAxisAngle(axis: Vector3, degrees: number): Quaternion
Creates a new quaternion from the rotation around the given axis ( right-hand rule ).
Same as AxisAngleQuaternion in Source engine, zero axis returns identity.
| Name | Type | Description |
|---|---|---|
axis | Vector3 | The rotation axis, does not have to be normalized. |
degrees | number | The rotation angle in degrees. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The new unit quaternion. |
#Quaternion.fromMatrix
function Quaternion.fromMatrix(a11: number, a12: number, a13: number, a21: number, a22: number, a23: number, a31: number, a32: number, a33: number): Quaternion
Creates a new quaternion from the unpacked 3x3 rotation matrix ( row-major ).
Same as MatrixQuaternion in Source engine, scale of the matrix is removed first.
| Name | Type | Description |
|---|---|---|
a11 | number | |
a12 | number | |
a13 | number | |
a21 | number | |
a22 | number | |
a23 | number | |
a31 | number | |
a32 | number | |
a33 | number |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The new unit quaternion. |
#Quaternion.fromVectors
function Quaternion.fromVectors(from: Vector3, to: Vector3): Quaternion
Creates a new quaternion that rotates the from direction to the to direction along the shortest arc.
Vectors do not have to be normalized, opposite directions rotate 180 degrees around any perpendicular axis, zero vectors return identity.
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The new unit quaternion. |
#Quaternion.fromVMatrix
function Quaternion.fromVMatrix(matrix: VMatrix): Quaternion
Creates a new quaternion from the rotation part of the given matrix.
Same as MatrixQuaternion in Source engine, scale and translation of the matrix are ignored.
| Name | Type | Description |
|---|---|---|
matrix | VMatrix | The matrix. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The new unit quaternion. |
#Quaternion.getAngles
function Quaternion.getAngles(self: Quaternion): Angle3
Returns the rotation of the quaternion as an angle.
Same as QuaternionAngles in Source engine, values are in range [-180, 180].
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
Angle3 | ang3 | The new angle. |
#Quaternion.getLength
function Quaternion.getLength(self: Quaternion): number
Calculates the length ( norm ) of the quaternion.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
number | length | The length of the quaternion. |
#Quaternion.getLengthSqr
function Quaternion.getLengthSqr(self: Quaternion): number
Calculates the squared length ( norm ) of the quaternion.
Faster than getLength, 1 for unit quaternions.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
number | length | The squared length of the quaternion. |
#Quaternion.getRotatedVector3
function Quaternion.getRotatedVector3(self: Quaternion, vector: Vector3): Vector3
Returns a copy of the vector rotated by the quaternion, same as quat * vec3.
Works with non-unit quaternions, zero quaternion returns an unrotated copy.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
vector | Vector3 | The vector to rotate. |
| Type | Name | Description |
|---|---|---|
Vector3 | rotated_vec3 | The new vector. |
#Quaternion.identity
function Quaternion.identity(): Quaternion
Creates a new identity quaternion ( 1, 0, 0, 0 ), which means no rotation.
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The new quaternion. |
#Quaternion.invert
function Quaternion.invert(self: Quaternion): Quaternion
Inverts the quaternion, so q * q:getInverse() is identity.
Works with non-unit quaternions, zero quaternion stays unchanged.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, inverted. |
#Quaternion.lerp
function Quaternion.lerp(self: Quaternion, quaternion: Quaternion, frac: number): Quaternion
Normalized linear interpolation ( nlerp ) between two quaternions along the shortest path.
Faster than slerp, but the rotation speed is not constant over frac.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
quaternion | Quaternion | The target quaternion. |
frac | number | The interpolation factor, 0 keeps the quaternion, 1 sets it to the target. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, interpolated and normalized. |
#Quaternion.log
function Quaternion.log(self: Quaternion): Quaternion
Calculates the natural logarithm of the quaternion, the inverse of exp.
For unit quaternions the result is pure imaginary ( 0, axis * angle / 2 ), zero quaternion results in ( -inf, 0, 0, 0 ).
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, logarithm. |
#Quaternion.mul
function Quaternion.mul(self: Quaternion, value: Quaternion | number): Quaternion
Multiplies the quaternion by another quaternion ( Hamilton product, self = self * value ) or by a number.
For rotations a * b means "rotate by b, then by a", use premul for the opposite order.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
value | Quaternion | number | The other quaternion or a number. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, with the product. |
#Quaternion.normalize
function Quaternion.normalize(self: Quaternion): Quaternion
Scales the quaternion to the length of 1.
Normalize after many multiplications to remove accumulated floating point errors.
Zero quaternion stays unchanged.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, normalized. |
#Quaternion.pow
function Quaternion.pow(self: Quaternion, exponent: number): Quaternion
Raises the quaternion to the given power, same as quat ^ exponent.
For unit quaternions this scales the rotation angle, e.g. 0.5 returns half of the rotation.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
exponent | number | The exponent. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, raised to the power. |
#Quaternion.scale
function Quaternion.scale(self: Quaternion, scale: number): Quaternion
Multiplies all components of the quaternion by the number.
Scaling does not change the rotation, but makes the quaternion non-unit.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
scale | number | The scale factor. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, scaled. |
#Quaternion.slerp
function Quaternion.slerp(self: Quaternion, quaternion: Quaternion, frac: number): Quaternion
Spherical linear interpolation ( slerp ) between two unit quaternions along the shortest path.
Rotates with a constant speed over frac, falls back to lerp for almost equal quaternions.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion, must be normalized. |
quaternion | Quaternion | The target quaternion, must be normalized. |
frac | number | The interpolation factor, 0 keeps the quaternion, 1 sets it to the target. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, interpolated. |
#Quaternion.sub
function Quaternion.sub(self: Quaternion, value: Quaternion | number): Quaternion
Subtracts another quaternion ( component-wise ) or a real number ( from w only ) from the quaternion.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
value | Quaternion | number | The other quaternion or a real number. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, with the difference. |
#Quaternion.toAngle3
function Quaternion.toAngle3(self: Quaternion): Angle3
Returns the rotation of the quaternion as an angle.
Same as QuaternionAngles in Source engine, values are in range [-180, 180].
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
Angle3 | ang3 | The new angle. |
#Quaternion.unpackAngles
function Quaternion.unpackAngles(self: Quaternion): number, number, number
Returns the unpacked Euler angles ( pitch, yaw, roll ) of the quaternion in degrees.
Same as QuaternionAngles in Source engine, allocation free alternative to getAngles.
At pitch ±90 ( gimbal lock ) roll is always 0 and the whole rotation goes into yaw.
| Name | Type | Description |
|---|---|---|
self | Quaternion | The quaternion. |
| Type | Name | Description |
|---|---|---|
number | pitch | The pitch in degrees. |
number | yaw | The yaw in degrees. |
number | roll | The roll in degrees. |
Methods
conjugate | Conjugates the quaternion ( negates the imaginary part ). |
getAngle | Returns the rotation angle of the quaternion in degrees. |
getAxis | Returns the rotation axis of the quaternion. |
getConjugate | Returns the conjugate of the quaternion ( imaginary part negated ). |
getExp | Returns e raised to the power of the quaternion. |
getForward | Returns the forward direction ( rotated +X ) of the quaternion. |
getInverse | Returns the inverse of the quaternion, so q * q:getInverse() is identity. |
getLeft | Returns the left direction ( rotated +Y ) of the quaternion. |
getLerped | Returns a normalized linear interpolation ( nlerp ) between two quaternions along the shortest path. |
getLog | Returns the natural logarithm of the quaternion. |
getNormalized | Returns a copy of the quaternion with the length of 1. |
getPow | Returns the quaternion raised to the given power. |
getRight | Returns the right direction ( rotated -Y ) of the quaternion. |
getScaled | Returns a scaled copy of the quaternion. |
getSlerped | Returns a spherical linear interpolation ( slerp ) between two unit quaternions along the shortest path. |
getUp | Returns the up direction ( rotated +Z ) of the quaternion. |
identity | Sets the quaternion to identity ( 1, 0, 0, 0 ), which means no rotation. |
isIdentity | Checks if the quaternion is exactly identity ( 1, 0, 0, 0 ). |
isImaginary | Checks if the quaternion is pure imaginary ( real component is zero ). |
isNear | Checks if the quaternion is equal to the given quaternion with the given tolerance. |
isReal | Checks if the quaternion is real ( all imaginary components are zero ). |
isZero | Checks if all components of the quaternion are exactly zero. |
negate | Negates all components of the quaternion. |
premul | Multiplies another quaternion by this quaternion ( self = value * self ). |
rotateVector3 | Rotates the given vector by the quaternion in place. |
set | Copies the components of another quaternion into this quaternion. |
setUnpacked | Sets the w ( r ), x ( i ), y ( j ), and z ( k ) components of the quaternion. |
toVMatrix | Returns the rotation of the quaternion as a matrix without translation. |
unpack | Returns the w ( r ), x ( i ), y ( j ), and z ( k ) components of the quaternion. |
unpackMatrix | Returns the unpacked 3x3 rotation matrix ( row-major ) of the quaternion. |
zero | Sets all components of the quaternion to zero. |
#Quaternion:conjugate
function Quaternion:conjugate(): Quaternion
Conjugates the quaternion ( negates the imaginary part ).
For unit quaternions the conjugate is the inverse rotation, faster than invert.
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, conjugated. |
#Quaternion:getAngle
function Quaternion:getAngle(full?: boolean): number
Returns the rotation angle of the quaternion in degrees.
Works with non-unit quaternions.
| Name | Type | Description |
|---|---|---|
fulloptional | boolean | If true, returns angle in range [0, 360], otherwise in range [-180, 180]. |
| Type | Name | Description |
|---|---|---|
number | degrees | The rotation angle. |
#Quaternion:getAxis
function Quaternion:getAxis(): Vector3
Returns the rotation axis of the quaternion.
Returns ( 0, 0, 1 ) if the quaternion has no rotation.
| Type | Name | Description |
|---|---|---|
Vector3 | axis | The new normalized vector. |
#Quaternion:getConjugate
function Quaternion:getConjugate(): Quaternion
Returns the conjugate of the quaternion ( imaginary part negated ).
For unit quaternions the conjugate is the inverse rotation, faster than getInverse.
| Type | Name | Description |
|---|---|---|
Quaternion | conjugated_quat | The new quaternion. |
#Quaternion:getExp
function Quaternion:getExp(): Quaternion
Returns e raised to the power of the quaternion.
| Type | Name | Description |
|---|---|---|
Quaternion | exp_quat | The new quaternion. |
#Quaternion:getForward
function Quaternion:getForward(): Vector3
Returns the forward direction ( rotated +X ) of the quaternion.
| Type | Name | Description |
|---|---|---|
Vector3 | forward_dir | The new normalized direction. |
#Quaternion:getInverse
function Quaternion:getInverse(): Quaternion
Returns the inverse of the quaternion, so q * q:getInverse() is identity.
| Type | Name | Description |
|---|---|---|
Quaternion | inverted_quat | The new quaternion. |
#Quaternion:getLeft
function Quaternion:getLeft(): Vector3
Returns the left direction ( rotated +Y ) of the quaternion.
| Type | Name | Description |
|---|---|---|
Vector3 | left_dir | The new normalized direction. |
#Quaternion:getLerped
function Quaternion:getLerped(quaternion: Quaternion, frac: number): Quaternion
Returns a normalized linear interpolation ( nlerp ) between two quaternions along the shortest path.
| Name | Type | Description |
|---|---|---|
quaternion | Quaternion | The target quaternion. |
frac | number | The interpolation factor, 0 keeps the quaternion, 1 sets it to the target. |
| Type | Name | Description |
|---|---|---|
Quaternion | lerped_quat | The new quaternion. |
#Quaternion:getLog
function Quaternion:getLog(): Quaternion
Returns the natural logarithm of the quaternion.
| Type | Name | Description |
|---|---|---|
Quaternion | log_quat | The new quaternion. |
#Quaternion:getNormalized
function Quaternion:getNormalized(): Quaternion
Returns a copy of the quaternion with the length of 1.
Zero quaternion returns a zero copy.
| Type | Name | Description |
|---|---|---|
Quaternion | normalized_quat | The new quaternion. |
#Quaternion:getPow
function Quaternion:getPow(exponent: number): Quaternion
Returns the quaternion raised to the given power.
| Name | Type | Description |
|---|---|---|
exponent | number | The exponent. |
| Type | Name | Description |
|---|---|---|
Quaternion | pow_quat | The new quaternion. |
#Quaternion:getRight
function Quaternion:getRight(): Vector3
Returns the right direction ( rotated -Y ) of the quaternion.
| Type | Name | Description |
|---|---|---|
Vector3 | right_dir | The new normalized direction. |
#Quaternion:getScaled
function Quaternion:getScaled(scale: number): Quaternion
Returns a scaled copy of the quaternion.
| Name | Type | Description |
|---|---|---|
scale | number | The scale factor. |
| Type | Name | Description |
|---|---|---|
Quaternion | scaled_quat | The new quaternion. |
#Quaternion:getSlerped
function Quaternion:getSlerped(quaternion: Quaternion, frac: number): Quaternion
Returns a spherical linear interpolation ( slerp ) between two unit quaternions along the shortest path.
| Name | Type | Description |
|---|---|---|
quaternion | Quaternion | The target quaternion, must be normalized. |
frac | number | The interpolation factor, 0 keeps the quaternion, 1 sets it to the target. |
| Type | Name | Description |
|---|---|---|
Quaternion | slerped_quat | The new quaternion. |
#Quaternion:getUp
function Quaternion:getUp(): Vector3
Returns the up direction ( rotated +Z ) of the quaternion.
| Type | Name | Description |
|---|---|---|
Vector3 | up_dir | The new normalized direction. |
#Quaternion:identity
function Quaternion:identity(): Quaternion
Sets the quaternion to identity ( 1, 0, 0, 0 ), which means no rotation.
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion. |
#Quaternion:isIdentity
function Quaternion:isIdentity(): boolean
Checks if the quaternion is exactly identity ( 1, 0, 0, 0 ).
( -1, 0, 0, 0 ) also means no rotation, but is not identity.
| Type | Name | Description |
|---|---|---|
boolean | is_identity | true if the quaternion is identity, false otherwise. |
#Quaternion:isImaginary
function Quaternion:isImaginary(): boolean
Checks if the quaternion is pure imaginary ( real component is zero ).
Unit pure imaginary quaternions are 180 degree rotations.
| Type | Name | Description |
|---|---|---|
boolean | is_imaginary | true if the quaternion is pure imaginary, false otherwise. |
#Quaternion:isNear
function Quaternion:isNear(quaternion: Quaternion, tolerance: number): boolean
Checks if the quaternion is equal to the given quaternion with the given tolerance.
Each component is compared separately, q and -q are not near, compare getAngle of a / b to check rotations.
| Name | Type | Description |
|---|---|---|
quaternion | Quaternion | The quaternion to check. |
tolerance | number | The maximum allowed difference per component. |
| Type | Name | Description |
|---|---|---|
boolean | is_near | true if the quaternions are equal within the tolerance, otherwise false. |
#Quaternion:isReal
function Quaternion:isReal(): boolean
Checks if the quaternion is real ( all imaginary components are zero ).
| Type | Name | Description |
|---|---|---|
boolean | is_real | true if the quaternion is real, false otherwise. |
#Quaternion:isZero
function Quaternion:isZero(): boolean
Checks if all components of the quaternion are exactly zero.
| Type | Name | Description |
|---|---|---|
boolean | is_zero | true if the quaternion is zero, false otherwise. |
#Quaternion:negate
function Quaternion:negate(): Quaternion
Negates all components of the quaternion.
q and -q represent the same rotation.
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, negated. |
#Quaternion:premul
function Quaternion:premul(value: Quaternion): Quaternion
Multiplies another quaternion by this quaternion ( self = value * self ).
For rotations it applies value after the current rotation.
| Name | Type | Description |
|---|---|---|
value | Quaternion | The other quaternion. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion, with the product. |
#Quaternion:rotateVector3
function Quaternion:rotateVector3(vector: Vector3): Vector3
Rotates the given vector by the quaternion in place.
Unlike other methods, this one modifies the vector, not the quaternion.
| Name | Type | Description |
|---|---|---|
vector | Vector3 | The vector to rotate. |
| Type | Name | Description |
|---|---|---|
Vector3 | vec3 | The same vector, rotated. |
#Quaternion:set
function Quaternion:set(quaternion: Quaternion): Quaternion
Copies the components of another quaternion into this quaternion.
| Name | Type | Description |
|---|---|---|
quaternion | Quaternion | The quaternion to copy from. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion. |
#Quaternion:setUnpacked
function Quaternion:setUnpacked(w: number, x: number, y: number, z: number): Quaternion
Sets the w ( r ), x ( i ), y ( j ), and z ( k ) components of the quaternion.
| Name | Type | Description |
|---|---|---|
w | number | The real component. |
x | number | The first imaginary component. |
y | number | The second imaginary component. |
z | number | The third imaginary component. |
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion. |
#Quaternion:toVMatrix
function Quaternion:toVMatrix(): VMatrix
Returns the rotation of the quaternion as a matrix without translation.
Same as QuaternionMatrix in Source engine.
| Type | Name | Description |
|---|---|---|
VMatrix | matrix | The new rotation matrix. |
#Quaternion:unpack
function Quaternion:unpack(): number, number, number, number
Returns the w ( r ), x ( i ), y ( j ), and z ( k ) components of the quaternion.
| Type | Name | Description |
|---|---|---|
number | w | The real component. |
number | x | The first imaginary component. |
number | y | The second imaginary component. |
number | z | The third imaginary component. |
#Quaternion:unpackMatrix
function Quaternion:unpackMatrix(): number, number, number, number, number, number, number, number, number
Returns the unpacked 3x3 rotation matrix ( row-major ) of the quaternion.
Allocation free alternative to toVMatrix, columns are the forward, left and up directions.
| Type | Name | Description |
|---|---|---|
number | m11 | |
number | m12 | |
number | m13 | |
number | m21 | |
number | m22 | |
number | m23 | |
number | m31 | |
number | m32 | |
number | m33 |
#Quaternion:zero
function Quaternion:zero(): Quaternion
Sets all components of the quaternion to zero.
A zero quaternion is not a valid rotation.
| Type | Name | Description |
|---|---|---|
Quaternion | quat | The same quaternion. |