Creates a new Quaternion object with zero rotation (i.e., the identity quaternion)
The x component of the Quaternion
The y component of the Quaternion
The z component of the Quaternion
The w component of the Quaternion
Static
Readonly
IDENTITYA static property to provide quick access to the identity quaternion (0, 0, 0, 1). (Note: Be careful not to change the value of this field! It is marked readonly, but typescipt do not completely enforce this!)
// Good use of IDENTITY:
const q = Quaternion();
if (q.equals(Quaternion.IDENTITY)) {
console.log("q equals the identity quaternion")
}
// Dangerous use of IDENTITY!!!!
const q = Quaternion.IDENTITY; // makes q a reference to Quaternion.IDENTITY
q.makeRotationZ(Math.PI); // changes Quaternion.IDENTITY!
// Do this instead:
const q = Quaternion.makeIdentity(); // create a new identity matrix M
q.makeRotationZ(Math.PI);
Creates a new quaternion with the same values as this one
A new quaternion with the same values as this one
Copies the x,y,z,w components of another quaternion into this one
The quaternion to copy
Computes the inverse of this quaternion and returns the result in a new quaternion.
The inverse of this Quaternion
Sets this quaternion to a rotation like that used to orient a camera. The quaternion will rotate the -Z direction (typically, the "forward" direction for objects and the default "look" direction for cameras) to point in the new "look" direction defined by the vector (targetPoint - eyePoint). The up vector is used to further constrain the rotation. The original Y direction will rotate to point, as much as possible, toward the upVector.
Creates a new identity Quaternion object
A new Quaternion object representing the identity Quaternion (0, 0, 0, 1)
Multiply this quaternion with the input quaternion and save the result in this quaternion. i.e., this = this * q Quaternion multiplication is not commutative, so order matters. See premultiply() to do the multiplication in the opposite order.
The quaternion to multiply with
Premultiply this quaternion with the input quaternion and save the result in this quaternion. i.e., this = q * this. This operation is not commutative, so order matters; See multiply() to do the multiplication in the opposite order.
The quaternion to premultiply with
Sets the quaternion to the rotation specified by the provied Euler angles and order of rotation
The x-axis rotation angle in radians
The y-axis rotation angle in radians
The z-axis rotation angle in radians
The order in which the rotation angles are applied (defaults to 'YZX')
Sets this quaternion to an interpolation between two quaternions, q1 and q2, based on the given alpha
value
The starting quaternion
The ending quaternion
The interpolation value (0-1)
Static
copyCreates a new quaternion and copies the x,y,z,w values of the input into it.
A new Quaternion object with the same values as q
The Quaternion object to copy
Static
inverseReturns a new quaternion that is the inverse (opposite rotation) of the input quaternion.
A new Quaternion object representing the inverse of q
The Quaternion object to invert
Static
lookCreates a new quaternion with a rotation like that used to orient a camera. The quaternion will rotate the -Z direction (typically, the "forward" direction for objects and the default "look" direction for cameras) to point in the new "look" direction defined by the vector (targetPoint - eyePoint). The up vector is used to further constrain the rotation. The original Y direction will rotate to point, as much as possible, toward the upVector.
A new Quaternion that performs the specified rotation
Static
makeCreates a new quaternion to represent a rotation of angle radians around axis.
A new Quaternion
The axis to rotate around
The angle of rotation
Static
makeCreates a new quaternion from given Euler angles
A new Quaternion
The x-axis rotation angle
The y-axis rotation angle
The z-axis rotation angle
The order of the rotations (defaults to 'YZX')
Static
makeCreates a new quaternion with the same rotation as in the provided 4x4 transformation matrix.
A new Quaternion that specifies the same rotation
A 4x4 transformation matrix that includes a rotation.
Static
makeCreates a new Quaternion object representing a rotation around the x-axis
A new Quaternion object representing a rotation around the x-axis
The angle to rotate by around the x-axis (in radians)
Static
makeCreates a new Quaternion object representing a rotation around the y-axis
A new Quaternion object representing a rotation around the y-axis
The angle to rotate by around the y-axis (in radians)
Static
makeCreates a new Quaternion object representing a rotation around the z-axis
A new Quaternion object representing a rotation around the z-axis
The angle to rotate by around the z-axis (in radians)
Static
multiplyMultiplies two Quaternion objects together and returns a new quaternion = q1 * q2 Note: multiplication of quaternions is not commutative, so order matters. See premultiply() to do the opposite order, or just switch the order of the arguments.
A new Quaternion object representing the product of q1 and q2
The first Quaternion object
The second Quaternion object
Static
normalizeReturns a new quaternion that is a normalized version of the input quaternion.
A new Quaternion object with normalized values
The Quaternion object to normalize
Static
premultiplyPremultiplies two Quaternion objects and returns a new quaternion = q2 * q1 Note: multiplication of quaternions is not commutative, so order matters. See multiply() to do the opposite order, or just switch the order of the arguments.
A new Quaternion object which is the result of the premultiplication of the two input Quaternion objects
The first Quaternion object
The second Quaternion object
Static
rotateRotates a 3D point or 3D vector by the specified quaternion and returns the result in a new Vector3
A new 3D point or 3D vector
The original 3D point or 3D vector
The rotation to apply
Static
slerpReturns a Quaternion from two input Quaternions using spherical linear interpolation.
A new Quaternion representing the slerp between q1 and q2
The first Quaternion
The second Quaternion
The interpolation factor
Generated using TypeDoc
This class holds a quaternion rotation. It includes routines for using the quaternion to rotate points and vectors. It includes routines for constructing many common rotations and inverting the rotation as well as accessing the underlying x,y,z,w components of the quaterion.
Most of the functions in the class are defined both as member functions that can be called on a specific instance of Quaternion and as static functions. The static functions return a new result, leaving the original inputs unchanged, whereas, in general, member functions save the result in the quaternion itself and return void: