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 ReadonlyIDENTITYA 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
Converts this quaternion into an equivalent 4x4 rotation matrix and returns the result.
A 4x4 rotation matrix representation of this Quaternion
Computes the inverse of this quaternion and returns the result in a new quaternion.
The inverse of this Quaternion
Inverts the quaternion and save the result in 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
Normalize this quaternion and save the result in this quaternion.
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 x,y,z,w components of the quaternion to the given x, y, z, and w values
The x value
The y value
The z value
The w value
Sets the quaternion to a rotation around axis by angle radians. Note, the axis parameter must be a unit vector.
A unit vector that describes the axis of rotation
The angle of rotation in radians
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 the quaternion to the identity quaternion
Sets the quaternion to a rotation equal to the one in the provided 4x4 rotation matrix
A 4x4 rotation matrix
Sets the quaternion to a rotation around the x axis
The angle of rotation in radians
Sets the quaternion to a rotation around the y axis
The angle of rotation in radians
Sets the quaternion to a rotation around the z axis
The angle of rotation in radians
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)
StaticcloneCreates a new quaternion and copies the x,y,z,w values of the input into it.
The Quaternion object to copy
A new Quaternion object with the same values as q
StaticinverseReturns a new quaternion that is the inverse (opposite rotation) of the input quaternion.
The Quaternion object to invert
A new Quaternion object representing the inverse of q
StaticlookCreates 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
StaticmakeCreates a new quaternion to represent a rotation of angle radians around axis.
The axis to rotate around
The angle of rotation
A new Quaternion
StaticmakeCreates a new quaternion from given Euler angles
The x-axis rotation angle
The y-axis rotation angle
The z-axis rotation angle
The order of the rotations (defaults to 'YZX')
A new Quaternion
StaticmakeCreates a new quaternion with the same rotation as in the provided 4x4 transformation matrix.
A 4x4 transformation matrix that includes a rotation.
A new Quaternion that specifies the same rotation
StaticmakeCreates a new Quaternion object representing a rotation around the x-axis
The angle to rotate by around the x-axis (in radians)
A new Quaternion object representing a rotation around the x-axis
StaticmakeCreates a new Quaternion object representing a rotation around the y-axis
The angle to rotate by around the y-axis (in radians)
A new Quaternion object representing a rotation around the y-axis
StaticmakeCreates a new Quaternion object representing a rotation around the z-axis
The angle to rotate by around the z-axis (in radians)
A new Quaternion object representing a rotation around the z-axis
StaticmultiplyMultiplies 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.
The first Quaternion object
The second Quaternion object
A new Quaternion object representing the product of q1 and q2
StaticnormalizeReturns a new quaternion that is a normalized version of the input quaternion.
The Quaternion object to normalize
A new Quaternion object with normalized values
StaticpremultiplyPremultiplies 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.
The first Quaternion object
The second Quaternion object
A new Quaternion object which is the result of the premultiplication of the two input Quaternion objects
StaticrotateRotates a 3D point or 3D vector by the specified quaternion and returns the result in a new Vector3
The original 3D point or 3D vector
The rotation to apply
A new 3D point or 3D vector
StaticslerpReturns a Quaternion from two input Quaternions using spherical linear interpolation.
The first Quaternion
The second Quaternion
The interpolation factor
A new Quaternion representing the slerp between q1 and q2
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: