dreamworkAPI
Ctrl K
GitHub
classDocs / Quaternion

Quaternion

classsharedmenusource
Object → 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 * b rotates by b first, then by a.
  • quat * vec3 - rotates the vector, returns a new Vector3.
  • quat / quat - a * b:getInverse(), the rotation from b to a.
  • 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?): Quaternion

Fields

NameTypeDescription
wnumberThe real part ( r ), cos( angle / 2 ) for rotations.
xnumberThe first imaginary part ( i ), axis.x * sin( angle / 2 ) for rotations.
ynumberThe second imaginary part ( j ), axis.y * sin( angle / 2 ) for rotations.
znumberThe third imaginary part ( k ), axis.z * sin( angle / 2 ) for rotations.

Operators

OperatorOperandResult
add Quaternion | number Quaternion
sub Quaternion | number Quaternion
mul Vector3 Vector3
mul Quaternion | number Quaternion
div Quaternion | number Quaternion
pow number Quaternion
unmQuaternion

Static functions

addAdds another quaternion ( component-wise ) or a real number ( to w only ) to the quaternion.
copyCreates a new independent copy of the quaternion.
divDivides the quaternion by another quaternion ( self = self * value:getInverse() ) or by a number.
dotCalculates the dot product of two quaternions.
expRaises e to the power of the quaternion.
fromAngle3Creates a new quaternion from the given angle.
fromAnglesCreates a new quaternion from the given Euler angles in degrees.
fromAxisAngleCreates a new quaternion from the rotation around the given axis ( right-hand rule ).
fromMatrixCreates a new quaternion from the unpacked 3x3 rotation matrix ( row-major ).
fromVectorsCreates a new quaternion that rotates the from direction to the to direction along the shortest arc.
fromVMatrixCreates a new quaternion from the rotation part of the given matrix.
getAnglesReturns the rotation of the quaternion as an angle.
getLengthCalculates the length ( norm ) of the quaternion.
getLengthSqrCalculates the squared length ( norm ) of the quaternion.
getRotatedVector3Returns a copy of the vector rotated by the quaternion, same as quat * vec3.
identityCreates a new identity quaternion ( 1, 0, 0, 0 ), which means no rotation.
invertInverts the quaternion, so q * q:getInverse() is identity.
lerpNormalized linear interpolation ( nlerp ) between two quaternions along the shortest path.
logCalculates the natural logarithm of the quaternion, the inverse of exp.
mulMultiplies the quaternion by another quaternion ( Hamilton product, self = self * value ) or by a number.
normalizeScales the quaternion to the length of 1.
powRaises the quaternion to the given power, same as quat ^ exponent.
scaleMultiplies all components of the quaternion by the number.
slerpSpherical linear interpolation ( slerp ) between two unit quaternions along the shortest path.
subSubtracts another quaternion ( component-wise ) or a real number ( from w only ) from the quaternion.
toAngle3Returns the rotation of the quaternion as an angle.
unpackAnglesReturns the unpacked Euler angles ( pitch, yaw, roll ) of the quaternion in degrees.

#Quaternion.add

sharedmenusource
function Quaternion.add(self: Quaternion, value: Quaternion | number): Quaternion

Adds another quaternion ( component-wise ) or a real number ( to w only ) to the quaternion.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
valueQuaternion | numberThe other quaternion or a real number.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, with the sum.

#Quaternion.copy

sharedmenunodiscardsource
function Quaternion.copy(self: Quaternion): Quaternion

Creates a new independent copy of the quaternion.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
QuaternioncopyThe new quaternion.

#Quaternion.div

sharedmenusource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
valueQuaternion | numberThe divisor quaternion or number.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, divided.

#Quaternion.dot

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
quaternionQuaternionThe other quaternion.
Returns
TypeNameDescription
numberdot_productThe dot product of two quaternions.

#Quaternion.exp

sharedmenusource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, exponentiated.

#Quaternion.fromAngle3

sharedmenunodiscardsource
function Quaternion.fromAngle3(angle: Angle3): Quaternion

Creates a new quaternion from the given angle.

Same as AngleQuaternion in Source engine.

Parameters
NameTypeDescription
angleAngle3The angle.
Returns
TypeNameDescription
QuaternionquatThe new unit quaternion.

#Quaternion.fromAngles

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
pitchnumberThe pitch in degrees.
yawnumberThe yaw in degrees.
rollnumberThe roll in degrees.
Returns
TypeNameDescription
QuaternionquatThe new unit quaternion.

#Quaternion.fromAxisAngle

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
axisVector3The rotation axis, does not have to be normalized.
degreesnumberThe rotation angle in degrees.
Returns
TypeNameDescription
QuaternionquatThe new unit quaternion.

#Quaternion.fromMatrix

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
a11number
a12number
a13number
a21number
a22number
a23number
a31number
a32number
a33number
Returns
TypeNameDescription
QuaternionquatThe new unit quaternion.

#Quaternion.fromVectors

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
fromVector3The source direction.
toVector3The target direction.
Returns
TypeNameDescription
QuaternionquatThe new unit quaternion.

#Quaternion.fromVMatrix

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
matrixVMatrixThe matrix.
Returns
TypeNameDescription
QuaternionquatThe new unit quaternion.

#Quaternion.getAngles

sharedmenunodiscardsource
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].

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
Angle3ang3The new angle.

#Quaternion.getLength

sharedmenunodiscardsource
function Quaternion.getLength(self: Quaternion): number

Calculates the length ( norm ) of the quaternion.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
numberlengthThe length of the quaternion.

#Quaternion.getLengthSqr

sharedmenunodiscardsource
function Quaternion.getLengthSqr(self: Quaternion): number

Calculates the squared length ( norm ) of the quaternion.

Faster than getLength, 1 for unit quaternions.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
numberlengthThe squared length of the quaternion.

#Quaternion.getRotatedVector3

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
vectorVector3The vector to rotate.
Returns
TypeNameDescription
Vector3rotated_vec3The new vector.

#Quaternion.identity

sharedmenunodiscardsource
function Quaternion.identity(): Quaternion

Creates a new identity quaternion ( 1, 0, 0, 0 ), which means no rotation.

Returns
TypeNameDescription
QuaternionquatThe new quaternion.

#Quaternion.invert

sharedmenusource
function Quaternion.invert(self: Quaternion): Quaternion

Inverts the quaternion, so q * q:getInverse() is identity.

Works with non-unit quaternions, zero quaternion stays unchanged.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, inverted.

#Quaternion.lerp

sharedmenusource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
quaternionQuaternionThe target quaternion.
fracnumberThe interpolation factor, 0 keeps the quaternion, 1 sets it to the target.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, interpolated and normalized.

#Quaternion.log

sharedmenusource
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 ).

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, logarithm.

#Quaternion.mul

sharedmenusource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
valueQuaternion | numberThe other quaternion or a number.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, with the product.

#Quaternion.normalize

sharedmenusource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, normalized.

#Quaternion.pow

sharedmenusource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
exponentnumberThe exponent.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, raised to the power.

#Quaternion.scale

sharedmenusource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
scalenumberThe scale factor.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, scaled.

#Quaternion.slerp

sharedmenusource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion, must be normalized.
quaternionQuaternionThe target quaternion, must be normalized.
fracnumberThe interpolation factor, 0 keeps the quaternion, 1 sets it to the target.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, interpolated.

#Quaternion.sub

sharedmenusource
function Quaternion.sub(self: Quaternion, value: Quaternion | number): Quaternion

Subtracts another quaternion ( component-wise ) or a real number ( from w only ) from the quaternion.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
valueQuaternion | numberThe other quaternion or a real number.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, with the difference.

#Quaternion.toAngle3

sharedmenunodiscardsource
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].

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
Angle3ang3The new angle.

#Quaternion.unpackAngles

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
selfQuaternionThe quaternion.
Returns
TypeNameDescription
numberpitchThe pitch in degrees.
numberyawThe yaw in degrees.
numberrollThe roll in degrees.

Methods

conjugateConjugates the quaternion ( negates the imaginary part ).
getAngleReturns the rotation angle of the quaternion in degrees.
getAxisReturns the rotation axis of the quaternion.
getConjugateReturns the conjugate of the quaternion ( imaginary part negated ).
getExpReturns e raised to the power of the quaternion.
getForwardReturns the forward direction ( rotated +X ) of the quaternion.
getInverseReturns the inverse of the quaternion, so q * q:getInverse() is identity.
getLeftReturns the left direction ( rotated +Y ) of the quaternion.
getLerpedReturns a normalized linear interpolation ( nlerp ) between two quaternions along the shortest path.
getLogReturns the natural logarithm of the quaternion.
getNormalizedReturns a copy of the quaternion with the length of 1.
getPowReturns the quaternion raised to the given power.
getRightReturns the right direction ( rotated -Y ) of the quaternion.
getScaledReturns a scaled copy of the quaternion.
getSlerpedReturns a spherical linear interpolation ( slerp ) between two unit quaternions along the shortest path.
getUpReturns the up direction ( rotated +Z ) of the quaternion.
identitySets the quaternion to identity ( 1, 0, 0, 0 ), which means no rotation.
isIdentityChecks if the quaternion is exactly identity ( 1, 0, 0, 0 ).
isImaginaryChecks if the quaternion is pure imaginary ( real component is zero ).
isNearChecks if the quaternion is equal to the given quaternion with the given tolerance.
isRealChecks if the quaternion is real ( all imaginary components are zero ).
isZeroChecks if all components of the quaternion are exactly zero.
negateNegates all components of the quaternion.
premulMultiplies another quaternion by this quaternion ( self = value * self ).
rotateVector3Rotates the given vector by the quaternion in place.
setCopies the components of another quaternion into this quaternion.
setUnpackedSets the w ( r ), x ( i ), y ( j ), and z ( k ) components of the quaternion.
toVMatrixReturns the rotation of the quaternion as a matrix without translation.
unpackReturns the w ( r ), x ( i ), y ( j ), and z ( k ) components of the quaternion.
unpackMatrixReturns the unpacked 3x3 rotation matrix ( row-major ) of the quaternion.
zeroSets all components of the quaternion to zero.

#Quaternion:conjugate

sharedmenusource
function Quaternion:conjugate(): Quaternion

Conjugates the quaternion ( negates the imaginary part ).

For unit quaternions the conjugate is the inverse rotation, faster than invert.

Returns
TypeNameDescription
QuaternionquatThe same quaternion, conjugated.

#Quaternion:getAngle

sharedmenunodiscardsource
function Quaternion:getAngle(full?: boolean): number

Returns the rotation angle of the quaternion in degrees.

Works with non-unit quaternions.

Parameters
NameTypeDescription
fulloptionalbooleanIf true, returns angle in range [0, 360], otherwise in range [-180, 180].
Returns
TypeNameDescription
numberdegreesThe rotation angle.

#Quaternion:getAxis

sharedmenunodiscardsource
function Quaternion:getAxis(): Vector3

Returns the rotation axis of the quaternion.

Returns ( 0, 0, 1 ) if the quaternion has no rotation.

Returns
TypeNameDescription
Vector3axisThe new normalized vector.

#Quaternion:getConjugate

sharedmenunodiscardsource
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.

Returns
TypeNameDescription
Quaternionconjugated_quatThe new quaternion.

#Quaternion:getExp

sharedmenunodiscardsource
function Quaternion:getExp(): Quaternion

Returns e raised to the power of the quaternion.

Returns
TypeNameDescription
Quaternionexp_quatThe new quaternion.

#Quaternion:getForward

sharedmenunodiscardsource
function Quaternion:getForward(): Vector3

Returns the forward direction ( rotated +X ) of the quaternion.

Returns
TypeNameDescription
Vector3forward_dirThe new normalized direction.

#Quaternion:getInverse

sharedmenunodiscardsource
function Quaternion:getInverse(): Quaternion

Returns the inverse of the quaternion, so q * q:getInverse() is identity.

Returns
TypeNameDescription
Quaternioninverted_quatThe new quaternion.

#Quaternion:getLeft

sharedmenunodiscardsource
function Quaternion:getLeft(): Vector3

Returns the left direction ( rotated +Y ) of the quaternion.

Returns
TypeNameDescription
Vector3left_dirThe new normalized direction.

#Quaternion:getLerped

sharedmenunodiscardsource
function Quaternion:getLerped(quaternion: Quaternion, frac: number): Quaternion

Returns a normalized linear interpolation ( nlerp ) between two quaternions along the shortest path.

Parameters
NameTypeDescription
quaternionQuaternionThe target quaternion.
fracnumberThe interpolation factor, 0 keeps the quaternion, 1 sets it to the target.
Returns
TypeNameDescription
Quaternionlerped_quatThe new quaternion.

#Quaternion:getLog

sharedmenunodiscardsource
function Quaternion:getLog(): Quaternion

Returns the natural logarithm of the quaternion.

Returns
TypeNameDescription
Quaternionlog_quatThe new quaternion.

#Quaternion:getNormalized

sharedmenunodiscardsource
function Quaternion:getNormalized(): Quaternion

Returns a copy of the quaternion with the length of 1.

Zero quaternion returns a zero copy.

Returns
TypeNameDescription
Quaternionnormalized_quatThe new quaternion.

#Quaternion:getPow

sharedmenunodiscardsource
function Quaternion:getPow(exponent: number): Quaternion

Returns the quaternion raised to the given power.

Parameters
NameTypeDescription
exponentnumberThe exponent.
Returns
TypeNameDescription
Quaternionpow_quatThe new quaternion.

#Quaternion:getRight

sharedmenunodiscardsource
function Quaternion:getRight(): Vector3

Returns the right direction ( rotated -Y ) of the quaternion.

Returns
TypeNameDescription
Vector3right_dirThe new normalized direction.

#Quaternion:getScaled

sharedmenunodiscardsource
function Quaternion:getScaled(scale: number): Quaternion

Returns a scaled copy of the quaternion.

Parameters
NameTypeDescription
scalenumberThe scale factor.
Returns
TypeNameDescription
Quaternionscaled_quatThe new quaternion.

#Quaternion:getSlerped

sharedmenunodiscardsource
function Quaternion:getSlerped(quaternion: Quaternion, frac: number): Quaternion

Returns a spherical linear interpolation ( slerp ) between two unit quaternions along the shortest path.

Parameters
NameTypeDescription
quaternionQuaternionThe target quaternion, must be normalized.
fracnumberThe interpolation factor, 0 keeps the quaternion, 1 sets it to the target.
Returns
TypeNameDescription
Quaternionslerped_quatThe new quaternion.

#Quaternion:getUp

sharedmenunodiscardsource
function Quaternion:getUp(): Vector3

Returns the up direction ( rotated +Z ) of the quaternion.

Returns
TypeNameDescription
Vector3up_dirThe new normalized direction.

#Quaternion:identity

sharedmenusource
function Quaternion:identity(): Quaternion

Sets the quaternion to identity ( 1, 0, 0, 0 ), which means no rotation.

Returns
TypeNameDescription
QuaternionquatThe same quaternion.

#Quaternion:isIdentity

sharedmenunodiscardsource
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.

Returns
TypeNameDescription
booleanis_identitytrue if the quaternion is identity, false otherwise.

#Quaternion:isImaginary

sharedmenunodiscardsource
function Quaternion:isImaginary(): boolean

Checks if the quaternion is pure imaginary ( real component is zero ).

Unit pure imaginary quaternions are 180 degree rotations.

Returns
TypeNameDescription
booleanis_imaginarytrue if the quaternion is pure imaginary, false otherwise.

#Quaternion:isNear

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
quaternionQuaternionThe quaternion to check.
tolerancenumberThe maximum allowed difference per component.
Returns
TypeNameDescription
booleanis_neartrue if the quaternions are equal within the tolerance, otherwise false.

#Quaternion:isReal

sharedmenunodiscardsource
function Quaternion:isReal(): boolean

Checks if the quaternion is real ( all imaginary components are zero ).

Returns
TypeNameDescription
booleanis_realtrue if the quaternion is real, false otherwise.

#Quaternion:isZero

sharedmenunodiscardsource
function Quaternion:isZero(): boolean

Checks if all components of the quaternion are exactly zero.

Returns
TypeNameDescription
booleanis_zerotrue if the quaternion is zero, false otherwise.

#Quaternion:negate

sharedmenusource
function Quaternion:negate(): Quaternion

Negates all components of the quaternion.

q and -q represent the same rotation.

Returns
TypeNameDescription
QuaternionquatThe same quaternion, negated.

#Quaternion:premul

sharedmenusource
function Quaternion:premul(value: Quaternion): Quaternion

Multiplies another quaternion by this quaternion ( self = value * self ).

For rotations it applies value after the current rotation.

Parameters
NameTypeDescription
valueQuaternionThe other quaternion.
Returns
TypeNameDescription
QuaternionquatThe same quaternion, with the product.

#Quaternion:rotateVector3

sharedmenusource
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.

Parameters
NameTypeDescription
vectorVector3The vector to rotate.
Returns
TypeNameDescription
Vector3vec3The same vector, rotated.

#Quaternion:set

sharedmenusource
function Quaternion:set(quaternion: Quaternion): Quaternion

Copies the components of another quaternion into this quaternion.

Parameters
NameTypeDescription
quaternionQuaternionThe quaternion to copy from.
Returns
TypeNameDescription
QuaternionquatThe same quaternion.

#Quaternion:setUnpacked

sharedmenusource
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.

Parameters
NameTypeDescription
wnumberThe real component.
xnumberThe first imaginary component.
ynumberThe second imaginary component.
znumberThe third imaginary component.
Returns
TypeNameDescription
QuaternionquatThe same quaternion.

#Quaternion:toVMatrix

sharedmenunodiscardsource
function Quaternion:toVMatrix(): VMatrix

Returns the rotation of the quaternion as a matrix without translation.

Same as QuaternionMatrix in Source engine.

Returns
TypeNameDescription
VMatrixmatrixThe new rotation matrix.

#Quaternion:unpack

sharedmenunodiscardsource
function Quaternion:unpack(): number, number, number, number

Returns the w ( r ), x ( i ), y ( j ), and z ( k ) components of the quaternion.

Returns
TypeNameDescription
numberwThe real component.
numberxThe first imaginary component.
numberyThe second imaginary component.
numberzThe third imaginary component.

#Quaternion:unpackMatrix

sharedmenunodiscardsource
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.

Returns
TypeNameDescription
numberm11
numberm12
numberm13
numberm21
numberm22
numberm23
numberm31
numberm32
numberm33

#Quaternion:zero

sharedmenusource
function Quaternion:zero(): Quaternion

Sets all components of the quaternion to zero.

A zero quaternion is not a valid rotation.

Returns
TypeNameDescription
QuaternionquatThe same quaternion.
Generated from the dreamwork meta branch.