Creates a new Quat instance.
Optional
x: numberThe x value. Defaults to 0.
Optional
y: numberThe y value. Defaults to 0.
Optional
z: numberThe z value. Defaults to 0.
Optional
w: numberThe w value. Defaults to 1.
Creates a new Quat instance.
The array to set the vector values from.
The w component of the quaternion.
The x component of the quaternion.
The y component of the quaternion.
The z component of the quaternion.
Static
Readonly
IDENTITYA constant quaternion set to [0, 0, 0, 1] (the identity). Represents no rotation.
Static
Readonly
ZEROA constant quaternion set to [0, 0, 0, 0].
Returns an identical copy of the specified quaternion.
A new quaternion identical to this one.
Calculates the dot product of two quaternions.
The quaternion to calculate the dot product with.
The dot product of the two quaternions.
Reports whether two quaternions are equal.
The quaternion to be compared against.
True if the quaternions are equal and false otherwise.
Reports whether two quaternions are equal using an absolute error tolerance.
The quaternion to be compared against.
Optional
epsilon: number = 1e-6The maximum difference between each component of the two quaternions. Defaults to 1e-6.
True if the quaternions are equal and false otherwise.
Set the values of the quaternion from an array.
The array to set the quaternion values from.
Optional
offset: number = 0The zero-based index at which to start copying elements from the array. Default is 0.
Self for chaining.
Gets the rotation axis and angle for a given quaternion. If a quaternion is created with
setFromAxisAngle
, this method will return the same values as provided in the original
parameter list OR functionally equivalent values.
The 3-dimensional vector to receive the axis of rotation.
Angle, in degrees, of the rotation.
Converts this quaternion to Euler angles, specified in degrees. The decomposition uses an intrinsic XYZ order, representing the angles required to achieve the quaternion's orientation by rotating sequentially: first around the X-axis, then around the newly transformed Y-axis, and finally around the resulting Z-axis.
Optional
eulers: Vec3 = ...An optional 3-dimensional vector to receive the calculated Euler angles (output parameter). If not provided, a new Vec3 object will be allocated and returned.
The 3-dimensional vector holding the Euler angles in degrees. This will be
the same object passed in as the eulers
parameter (if one was provided).
Performs a linear interpolation between two quaternions. The result of the interpolation is written to the quaternion calling the function.
The quaternion to interpolate from.
The quaternion to interpolate to.
The value controlling the interpolation in relation to the two input quaternions. The value is in the range 0 to 1, 0 generating q1, 1 generating q2 and anything in between generating a linear interpolation between the two.
Self for chaining.
Sets the specified quaternion to the supplied numerical values.
The x component of the quaternion.
The y component of the quaternion.
The z component of the quaternion.
The w component of the quaternion.
Self for chaining.
Sets this quaternion to represent a rotation specified by Euler angles in degrees. The rotation is applied using an intrinsic XYZ order: first around the X-axis, then around the newly transformed Y-axis, and finally around the resulting Z-axis.
The angle to rotate around the X-axis in degrees, or a Vec3
object containing the X, Y, and Z angles in degrees in its respective components (ex.x
,
ex.y
, ex.z
).
Optional
ey: numberThe angle to rotate around the Y-axis in degrees. This parameter is
only used if ex
is provided as a number.
Optional
ez: numberThe angle to rotate around the Z-axis in degrees. This parameter is
only used if ex
is provided as a number.
The quaternion itself (this), now representing the orientation from the specified XYZ Euler angles. Allows for method chaining.
Performs a spherical interpolation between two quaternions. The result of the interpolation is written to the quaternion calling the function.
The quaternion to interpolate from.
The quaternion to interpolate to.
The value controlling the interpolation in relation to the two input quaternions. The value is in the range 0 to 1, 0 generating q1, 1 generating q2 and anything in between generating a spherical interpolation between the two.
Self for chaining.
Optional
arr: number[]The array to populate with the quaternion's number components. If not specified, a new array is created.
Optional
offset: numberThe zero-based index at which to start copying elements to the array. Default is 0.
The quaternion as an array.
The array to populate with the quaternion's number components. If not specified, a new array is created.
Optional
offset: numberThe zero-based index at which to start copying elements to the array. Default is 0.
The quaternion as an array.
Transforms a 3-dimensional vector by the specified quaternion.
The transformed vector (res if specified, otherwise a new Vec3).
A quaternion representing rotation in 3D space. Quaternions are typically used to represent rotations in 3D applications, offering advantages over Euler angles including no gimbal lock and more efficient interpolation.