quat
ClassQuaternion type for representing rotations in 3D space.
Index
Properties
Methods
Example
const identity = new quat(0, 0, 0, 1);
console.log('Identity quat:', identity.x, identity.y, identity.z, identity.w);
const rotation = quat.fromEulerAngles(0, Math.PI / 2, 0);
console.log('90-deg Y rotation:', rotation.x, rotation.y, rotation.z, rotation.w);
const euler = rotation.toEulerAngles();
console.log('Back to Euler:', euler.x, euler.y, euler.z);
Constructors
Constructor
new quat(
w,x,y,z):quat
Constructs a quaternion with the given w, x, y, z components.
Parameters
| Parameter | Type |
|---|---|
w | number |
x | number |
y | number |
z | number |
Returns
quat
Properties
w
w:
number
The w (scalar) component of the quaternion.
x
x:
number
The x component of the quaternion.
y
y:
number
The y component of the quaternion.
z
z:
number
The z component of the quaternion.
Methods
angleAxis()
staticangleAxis(angle,axis):quat
Creates a quaternion from an angle in radians and a rotation axis.
Parameters
| Parameter | Type |
|---|---|
angle | number |
axis | vec3 |
Returns
quat
angleBetween()
staticangleBetween(a,b):number
Returns the angle in radians between two quaternions.
Parameters
| Parameter | Type |
|---|---|
a | quat |
b | quat |
Returns
number
dot()
dot(
quat):number
Computes the dot product with another quaternion.
Parameters
| Parameter | Type |
|---|---|
quat | quat |
Returns
number
equal()
equal(
quat):boolean
Returns true if this quaternion equals another quaternion.
Parameters
| Parameter | Type |
|---|---|
quat | quat |
Returns
boolean
fromEulerAngles()
staticfromEulerAngles(x,y,z):quat
Creates a quaternion from Euler angles given as separate x, y, z values.
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
z | number |
Returns
quat
fromEulerVec()
staticfromEulerVec(eulerAngles):quat
Creates a quaternion from a vec3 of Euler angles.
Parameters
| Parameter | Type |
|---|---|
eulerAngles | vec3 |
Returns
quat
fromRotationMat()
staticfromRotationMat(rotationMat):quat
Creates a quaternion from a 3x3 rotation matrix.
Parameters
| Parameter | Type |
|---|---|
rotationMat | mat3 |
Returns
quat
fromRotationMat4()
staticfromRotationMat4(rotationMat4):quat
Creates a quaternion from a 4x4 rotation matrix.
Parameters
| Parameter | Type |
|---|---|
rotationMat4 | mat4 |
Returns
quat
getAngle()
getAngle():
number
Returns the rotation angle in radians represented by this quaternion.
Returns
number
getAxis()
getAxis():
vec3
Returns the rotation axis as a vec3.
Returns
invert()
invert():
quat
Returns the inverse of this quaternion.
Returns
quat
lerp()
staticlerp(a,b,time):quat
Linearly interpolates between two quaternions by factor t.
Parameters
| Parameter | Type |
|---|---|
a | quat |
b | quat |
time | number |
Returns
quat
lookAt()
staticlookAt(forward,up):quat
Creates a quaternion representing a rotation that looks from one point toward another.
Parameters
Returns
quat
multiply()
multiply(
quat):quat
Multiplies this quaternion by another, combining rotations.
Parameters
| Parameter | Type |
|---|---|
quat | quat |
Returns
quat
multiplyVec3()
multiplyVec3(
vec3):vec3
Rotates a vec3 by this quaternion.
Parameters
| Parameter | Type |
|---|---|
vec3 | vec3 |
Returns
normalize()
normalize():
void
Returns a normalized copy of this quaternion.
Returns
void
quatIdentity()
staticquatIdentity():quat
Returns the identity quaternion representing no rotation.
Returns
quat
rotationFromTo()
staticrotationFromTo(from,to):quat
Creates a quaternion representing the rotation from one vector to another.
Parameters
Returns
quat
slerp()
staticslerp(a,b,time):quat
Spherically interpolates between two quaternions by factor t.
Parameters
| Parameter | Type |
|---|---|
a | quat |
b | quat |
time | number |
Returns
quat
toEulerAngles()
toEulerAngles():
vec3
Converts this quaternion to Euler angles in radians.
Returns
toString()
toString():
string
Returns a string representation of this quaternion.
Returns
string