Namespace: quat
Table of contents
Type aliases
Functions
- add
- calculateW
- clone
- conjugate
- copy
- create
- dot
- equals
- exactEquals
- fromMat3
- fromValues
- getAxisAngle
- identity
- invert
- length
- lerp
- multiply
- normalize
- rotateX
- rotateY
- rotateZ
- rotationTo
- scale
- set
- setAxes
- setAxisAngle
- slerp
- sqlerp
- squaredLength
- str
Type aliases
valueType
Ƭ valueType: quattype
Functions
add
▸ Const add(out: vec4type, a: vec4type, b: vec4type): vec4type
Adds two quat's
function
Parameters
| Name | Type | Description |
|---|---|---|
out |
vec4type | the receiving quaternion |
a |
vec4type | the first operand |
b |
vec4type | the second operand |
Returns: vec4type
out
calculateW
▸ calculateW(out: quattype, a: quattype): quattype
Calculates the W component of a quat from the X, Y, and Z components. Assumes that quaternion is 1 unit in length. Any existing W component will be ignored.
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | the receiving quaternion |
a |
quattype | quat to calculate W component of |
Returns: quattype
out
clone
▸ Const clone(a: vec4type): vec4type
Creates a new quat initialized with values from an existing quaternion
function
Parameters
| Name | Type | Description |
|---|---|---|
a |
vec4type | quaternion to clone |
Returns: vec4type
a new quaternion
conjugate
▸ conjugate(out: quattype, a: quattype): quattype
Calculates the conjugate of a quat If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | the receiving quaternion |
a |
quattype | quat to calculate conjugate of |
Returns: quattype
out
copy
▸ Const copy(out: vec4type, a: vec4type): vec4type
Copy the values from one quat to another
function
Parameters
Returns: vec4type
out
create
▸ create(): quattype
Creates a new identity quat
Returns: quattype
a new quaternion
dot
▸ Const dot(a: vec4type, b: vec4type): number
Calculates the dot product of two quat's
function
Parameters
Returns: number
dot product of a and b
equals
▸ Const equals(a: vec4type, b: vec4type): boolean
Returns whether or not the quaternions have approximately the same elements in the same position.
Parameters
Returns: boolean
True if the vectors are equal, false otherwise.
exactEquals
▸ Const exactEquals(a: vec4type, b: vec4type): boolean
Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)
Parameters
Returns: boolean
True if the vectors are equal, false otherwise.
fromMat3
▸ fromMat3(out: quattype, m: mat3type): quattype
Creates a quaternion from the given 3x3 rotation matrix.
NOTE: The resultant quaternion is not normalized, so you should be sure to renormalize the quaternion yourself where necessary.
function
Parameters
Returns: quattype
out
fromValues
▸ Const fromValues(x: number, y: number, z: number, w: number): vec4type
Creates a new quat initialized with the given values
function
Parameters
| Name | Type | Description |
|---|---|---|
x |
number | X component |
y |
number | Y component |
z |
number | Z component |
w |
number | W component |
Returns: vec4type
a new quaternion
getAxisAngle
▸ getAxisAngle(outAxis: vec3type, q: quattype): number
Gets the rotation axis and angle for a given quaternion. If a quaternion is created with setAxisAngle, this method will return the same values as providied in the original parameter list OR functionally equivalent values. Example: The quaternion formed by axis [0, 0, 1] and angle -90 is the same as the quaternion formed by [0, 0, 1] and 270. This method favors the latter.
Parameters
| Name | Type | Description |
|---|---|---|
outAxis |
vec3type | Vector receiving the axis of rotation |
q |
quattype | Quaternion to be decomposed |
Returns: number
Angle, in radians, of the rotation
identity
▸ identity(out: quattype): quattype
Set a quat to the identity quaternion
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | the receiving quaternion |
Returns: quattype
out
invert
▸ invert(out: quattype, a: quattype): quattype
Calculates the inverse of a quat
Parameters
Returns: quattype
out
length
▸ Const length(a: vec4type): number
Calculates the length of a quat
function
Parameters
| Name | Type | Description |
|---|---|---|
a |
vec4type | vector to calculate length of |
Returns: number
length of a
lerp
▸ Const lerp(out: vec4type, a: vec4type, b: vec4type, t: number): vec4type
Performs a linear interpolation between two quat's
function
Parameters
| Name | Type | Description |
|---|---|---|
out |
vec4type | the receiving quaternion |
a |
vec4type | the first operand |
b |
vec4type | the second operand |
t |
number | interpolation amount between the two inputs |
Returns: vec4type
out
multiply
▸ multiply(out: quattype, a: quattype, b: quattype): quattype
Multiplies two quat's
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | the receiving quaternion |
a |
quattype | the first operand |
b |
quattype | the second operand |
Returns: quattype
out
normalize
▸ Const normalize(out: vec4type, a: vec4type): vec4type
Normalize a quat
function
Parameters
Returns: vec4type
out
rotateX
▸ rotateX(out: quattype, a: quattype, rad: number): quattype
Rotates a quaternion by the given angle about the X axis
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | quat receiving operation result |
a |
quattype | quat to rotate |
rad |
number | angle (in radians) to rotate |
Returns: quattype
out
rotateY
▸ rotateY(out: quattype, a: quattype, rad: number): quattype
Rotates a quaternion by the given angle about the Y axis
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | quat receiving operation result |
a |
quattype | quat to rotate |
rad |
number | angle (in radians) to rotate |
Returns: quattype
out
rotateZ
▸ rotateZ(out: quattype, a: quattype, rad: number): quattype
Rotates a quaternion by the given angle about the Z axis
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | quat receiving operation result |
a |
quattype | quat to rotate |
rad |
number | angle (in radians) to rotate |
Returns: quattype
out
rotationTo
▸ rotationTo(out: quattype, a: vec3type, b: vec3type): quattype
Sets a quaternion to represent the shortest rotation from one vector to another.
Both vectors are assumed to be unit length.
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | the receiving quaternion. |
a |
vec3type | the initial vector |
b |
vec3type | the destination vector |
Returns: quattype
out
scale
▸ Const scale(out: vec4type, a: vec4type, b: number): vec4type
Scales a quat by a scalar number
function
Parameters
| Name | Type | Description |
|---|---|---|
out |
vec4type | the receiving vector |
a |
vec4type | the vector to scale |
b |
number | amount to scale the vector by |
Returns: vec4type
out
set
▸ Const set(out: vec4type, x: number, y: number, z: number, w: number): vec4type
Set the components of a quat to the given values
function
Parameters
| Name | Type | Description |
|---|---|---|
out |
vec4type | the receiving quaternion |
x |
number | X component |
y |
number | Y component |
z |
number | Z component |
w |
number | W component |
Returns: vec4type
out
setAxes
▸ setAxes(out: quattype, view: vec3type, right: vec3type, up: vec3type): quattype
Sets the specified quaternion with values corresponding to the given axes. Each axis is a vec3 and is expected to be unit length and perpendicular to all other specified axes.
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | - |
view |
vec3type | the vector representing the viewing direction |
right |
vec3type | the vector representing the local "right" direction |
up |
vec3type | the vector representing the local "up" direction |
Returns: quattype
out
setAxisAngle
▸ setAxisAngle(out: quattype, axis: vec3type, rad: number): quattype
Sets a quat from the given angle and rotation axis, then returns it.
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | the receiving quaternion |
axis |
vec3type | the axis around which to rotate |
rad |
number | the angle in radians |
Returns: quattype
out
slerp
▸ slerp(out: quattype, a: quattype, b: quattype, t: number): quattype
Performs a spherical linear interpolation between two quat
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | the receiving quaternion |
a |
quattype | the first operand |
b |
quattype | the second operand |
t |
number | interpolation amount between the two inputs |
Returns: quattype
out
sqlerp
▸ sqlerp(out: quattype, a: quattype, b: quattype, c: quattype, d: quattype, t: number): quattype
Performs a spherical linear interpolation with two control points
Parameters
| Name | Type | Description |
|---|---|---|
out |
quattype | the receiving quaternion |
a |
quattype | the first operand |
b |
quattype | the second operand |
c |
quattype | the third operand |
d |
quattype | the fourth operand |
t |
number | interpolation amount |
Returns: quattype
out
squaredLength
▸ Const squaredLength(a: vec4type): number
Calculates the squared length of a quat
function
Parameters
| Name | Type | Description |
|---|---|---|
a |
vec4type | vector to calculate squared length of |
Returns: number
squared length of a
str
▸ str(a: quattype): string
Returns a string representation of a quatenion
Parameters
| Name | Type | Description |
|---|---|---|
a |
quattype | vector to represent as a string |
Returns: string
string representation of the vector