Quaternion
API for creating and manipulating quaternions.
Constants
Quaternion.IDENTITY
An identity quaternion is the inverse of itself (i.e. it performs no rotation).
Quaternion.IDENTITY: Quaternion
Functions
Quaternion.create
Creates a new quaternion.
Quaternion.create(imaginary: vector, scalar: number): Quaternion
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
imaginary | vector | Required | The imaginary part of the quaternion. |
scalar | number | Required | The scalar part of the quaternion. |
Returns
Name | Type | Description |
---|---|---|
quaternion | Quaternion | No description |
Quaternion.fromEuler
Creates a quaternion from Euler angles.
Quaternion.fromEuler(eulerAngle: vector): Quaternion
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
eulerAngle | vector | Required | No description |
Returns
Name | Type | Description |
---|---|---|
quaternion | Quaternion | No description |
Quaternion.fromAxisAngle
Creates a quaternion from an axis and an angle.
Quaternion.fromAxisAngle(axis: vector, angle: number): Quaternion
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
axis | vector | Required | The axis of rotation. |
angle | number | Required | The angle of rotation in radians about the axis. |
Returns
Name | Type | Description |
---|---|---|
quaternion | Quaternion | No description |
Quaternion.conjugate
Returns the conjugate of a quaternion.
Quaternion.conjugate(quaternion: Quaternion): Quaternion
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
quaternion | Quaternion | Required | No description |
Returns
Name | Type | Description |
---|---|---|
quaternion | Quaternion | No description |
Quaternion.inverse
Returns the inverse of a quaternion.
Quaternion.inverse(quaternion: Quaternion): Quaternion
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
quaternion | Quaternion | Required | No description |
Returns
Name | Type | Description |
---|---|---|
quaternion | Quaternion | No description |
Quaternion.rotate
Rotates a vector by a quaternion.
Quaternion.rotate(quaternion: Quaternion, vector: vector): vector
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
quaternion | Quaternion | Required | The quaternion to rotate by. |
vector | vector | Required | The vector to rotate. |
Returns
Name | Type | Description |
---|---|---|
vector | vector | The rotated vector. |
Quaternion.mul
Multiplies two quaternions. Quaternion multiplication is not commutative.
Quaternion.mul(a: Quaternion, b: Quaternion): Quaternion
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
a | Quaternion | Required | The first quaternion. |
b | Quaternion | Required | The second quaternion. |
Returns
Name | Type | Description |
---|---|---|
quaternion | Quaternion | The product of the two quaternions. |
Types
Quaternion
Rotation represented by imaginary and scalar components which does not suffer from gimbal lock.
type Quaternion = { [1]: vector, [2]: number }
Properties
Field | Type | Description |
---|---|---|
1 | vector | The imaginary part of the quaternion. |
2 | number | The scalar part of the quaternion. |