Module quat
A quaternion and associated utilities.
Functions
new (x, y, z, w) | The public constructor. |
from_angle_axis (angle, axis, y, z) | Create a quaternion from an angle/axis pair. |
from_direction (normal, up) | Create a quaternion from a normal/up vector pair. |
clone (a) | Clone a quaternion. |
add (a, b) | Add two quaternions. |
sub (a, b) | Subtract a quaternion from another. |
mul (a, b) | Multiply two quaternions. |
mul_vec3 (a, b) | Multiply a quaternion and a vec3. |
pow (a, s) | Raise a normalized quaternion to a scalar power. |
normalize (a) | Normalize a quaternion. |
dot (a, b) | Get the dot product of two quaternions. |
len (a) | Return the length of a quaternion. |
len2 (a) | Return the squared length of a quaternion. |
scale (a, s) | Multiply a quaternion by a scalar. |
rotate (angle, axis, y, z) | Alias of fromangleaxis. |
conjugate (a) | Return the conjugate of a quaternion. |
inverse (a) | Return the inverse of a quaternion. |
reciprocal (a) | Return the reciprocal of a quaternion. |
lerp (a, b, s) | Lerp between two quaternions. |
slerp (a, b, s) | Slerp between two quaternions. |
unpack (a) | Unpack a quaternion into individual components. |
is_quat (a) | Return a boolean showing if a table is or is not a quat. |
is_zero (a) | Return a boolean showing if a table is or is not a zero quat. |
is_real (a) | Return a boolean showing if a table is or is not a real quat. |
is_imaginary (a) | Return a boolean showing if a table is or is not an imaginary quat. |
has_nan (a) | Return whether any component is NaN |
to_angle_axis_unpack (a, vec3) | Convert a quaternion into an angle plus axis components. |
to_angle_axis (a, vec3) | Convert a quaternion into an angle/axis pair. |
to_vec3 (a) | Convert a quaternion into a vec3. |
to_string (a) | Return a formatted string. |
Tables
quat | Constants |
Functions
- new (x, y, z, w)
-
The public constructor.
Parameters:
- x Can be of two types: number x X component table {x, y, z, w} or {x=x, y=y, z=z, w=w}
- y number Y component
- z number Z component
- w number W component
Returns:
-
quat
out
- from_angle_axis (angle, axis, y, z)
-
Create a quaternion from an angle/axis pair.
Parameters:
- angle number Angle (in radians)
- axis /x -- Can be of two types, a vec3 axis, or the x component of that axis
- y axis -- y component of axis (optional, only if x component param used)
- z axis -- z component of axis (optional, only if x component param used)
Returns:
-
quat
out
- from_direction (normal, up)
-
Create a quaternion from a normal/up vector pair.
Parameters:
- normal vec3
- up vec3 (optional)
Returns:
-
quat
out
- clone (a)
-
Clone a quaternion.
Parameters:
- a quat Quaternion to clone
Returns:
-
quat
out
- add (a, b)
-
Add two quaternions.
Parameters:
Returns:
-
quat
out
- sub (a, b)
-
Subtract a quaternion from another.
Parameters:
Returns:
-
quat
out
- mul (a, b)
-
Multiply two quaternions.
Parameters:
Returns:
-
quat
quaternion equivalent to "apply b, then a"
- mul_vec3 (a, b)
-
Multiply a quaternion and a vec3.
Parameters:
- a quat Left hand operand
- b vec3 Right hand operand
Returns:
-
vec3
out
- pow (a, s)
-
Raise a normalized quaternion to a scalar power.
Parameters:
- a quat Left hand operand (should be a unit quaternion)
- s number Right hand operand
Returns:
-
quat
out
- normalize (a)
-
Normalize a quaternion.
Parameters:
- a quat Quaternion to normalize
Returns:
-
quat
out
- dot (a, b)
-
Get the dot product of two quaternions.
Parameters:
Returns:
-
number
dot
- len (a)
-
Return the length of a quaternion.
Parameters:
- a quat Quaternion to get length of
Returns:
-
number
len
- len2 (a)
-
Return the squared length of a quaternion.
Parameters:
- a quat Quaternion to get length of
Returns:
-
number
len
- scale (a, s)
-
Multiply a quaternion by a scalar.
Parameters:
- a quat Left hand operand
- s number Right hand operand
Returns:
-
quat
out
- rotate (angle, axis, y, z)
-
Alias of fromangleaxis.
Parameters:
- angle number Angle (in radians)
- axis /x -- Can be of two types, a vec3 axis, or the x component of that axis
- y axis -- y component of axis (optional, only if x component param used)
- z axis -- z component of axis (optional, only if x component param used)
Returns:
-
quat
out
- conjugate (a)
-
Return the conjugate of a quaternion.
Parameters:
- a quat Quaternion to conjugate
Returns:
-
quat
out
- inverse (a)
-
Return the inverse of a quaternion.
Parameters:
- a quat Quaternion to invert
Returns:
-
quat
out
- reciprocal (a)
-
Return the reciprocal of a quaternion.
Parameters:
- a quat Quaternion to reciprocate
Returns:
-
quat
out
- lerp (a, b, s)
-
Lerp between two quaternions.
Parameters:
Returns:
-
quat
out
- slerp (a, b, s)
-
Slerp between two quaternions.
Parameters:
Returns:
-
quat
out
- unpack (a)
-
Unpack a quaternion into individual components.
Parameters:
- a quat Quaternion to unpack
Returns:
- number x
- number y
- number z
- number w
- is_quat (a)
-
Return a boolean showing if a table is or is not a quat.
Parameters:
- a quat Quaternion to be tested
Returns:
-
boolean
is_quat
- is_zero (a)
-
Return a boolean showing if a table is or is not a zero quat.
Parameters:
- a quat Quaternion to be tested
Returns:
-
boolean
is_zero
- is_real (a)
-
Return a boolean showing if a table is or is not a real quat.
Parameters:
- a quat Quaternion to be tested
Returns:
-
boolean
is_real
- is_imaginary (a)
-
Return a boolean showing if a table is or is not an imaginary quat.
Parameters:
- a quat Quaternion to be tested
Returns:
-
boolean
is_imaginary
- has_nan (a)
-
Return whether any component is NaN
Parameters:
- a quat Quaternion to be tested
Returns:
-
boolean
if x,y,z, or w is NaN
- to_angle_axis_unpack (a, vec3)
-
Convert a quaternion into an angle plus axis components.
Parameters:
- a quat Quaternion to convert
- vec3 identityAxis of axis to use on identity/degenerate quaternions (optional, default returns 0,0,0,1)
Returns:
- number angle
- x axis-x
- y axis-y
- z axis-z
- to_angle_axis (a, vec3)
-
Convert a quaternion into an angle/axis pair.
Parameters:
- a quat Quaternion to convert
- vec3 identityAxis of axis to use on identity/degenerate quaternions (optional, default returns 0,vec3(0,0,1))
Returns:
- number angle
- vec3 axis
- to_vec3 (a)
-
Convert a quaternion into a vec3.
Parameters:
- a quat Quaternion to convert
Returns:
-
vec3
out
- to_string (a)
-
Return a formatted string.
Parameters:
- a quat Quaternion to be turned into a string
Returns:
-
string
formatted