Module math.quat
A quaternion and associated utilities.
this is apart of the LEEF-math module
Functions
new (x, y, z, w) | The public constructor. |
from_angle_axis (angle, x, 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_vec3 (a, v) | 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, x, y, z) | Alias of from_angle_axis. |
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, identityAxis) | Convert a quaternion into an angle plus axis components. |
to_angle_axis (a, identityAxis) | Convert a quaternion into an angle/axis pair. |
set_matrix_rot (q, m) | set a matrix's rotation fields from a quaternion. |
from_matrix (m) | create a new quaternion from a matrix. |
get_rot_luanti_entity () | alias of get_euler_zxy |
from_euler_zxy (X, Y, Z) | create a quaternion from euler angles in the ZXY rotation order. |
get_rot_luanti_entity () | alias of from_euler_zxy |
get_euler_xyz (q) | convert a quaternion to an xyz euler angles. |
get_rot_irrlicht_bone () | alias of get_euler_xyz |
from_euler_xyz (X, Y, Z) | create a quaternion from euler angles in the xyz rotation order. |
get_rot_irrlicht_bone () | alias of quat.from_euler_zxy |
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, x, y, z)
-
Create a quaternion from an angle/axis pair.
Parameters:
- angle float Angle (in radians)
- x (float | vec3) Can be of two types, a vec3 axis, or the x component of that axis
- y float component of axis (only used if x is float)
- z float component of axis (only used if x is float)
Returns:
-
quat
out
- from_direction (normal, up)
-
Create a quaternion from a normal/up vector pair. (accepts minetest vectors)
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_vec3 (a, v)
-
Multiply a quaternion and a vec3. Equivalent to rotating the vector (a) by the quaternion (v)
Parameters:
- a quat Left hand operand
- v 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, x, y, z)
-
Alias of
from_angle_axis.
Parameters:
- angle float Angle (in radians)
- x (float | vec3) Can be of two types, a vec3 axis, or the x component of that axis
- y float component of axis (only used if x is float)
- z float component of axis (only used if x is float)
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, identityAxis)
-
Convert a quaternion into an angle plus axis components.
Parameters:
- a quat Quaternion to convert
- identityAxis vec3 of axis to use on identity/degenerate quaternions (optional, default returns 0,0,0,1)
Returns:
- float angle
- float x
- float y
- float z
- to_angle_axis (a, identityAxis)
-
Convert a quaternion into an angle/axis pair.
Parameters:
- a quat Quaternion to convert
- identityAxis vec3 of axis to use on identity/degenerate quaternions (optional, default returns 0,0,0,1)
Returns:
- number angle
- vec3 axis
- set_matrix_rot (q, m)
-
set a matrix's rotation fields from a quaternion. Uses mat4.setrotfrom_quaternion
Parameters:
- q quat to convert
- m mat4 the mat4 to apply to.
Returns:
-
mat4
- from_matrix (m)
-
create a new quaternion from a matrix. Uses mat4.to_quaternion
Parameters:
- m mat4 the matrix to use
Returns:
- get_rot_luanti_entity ()
-
alias of
get_euler_zxy
- from_euler_zxy (X, Y, Z)
-
create a quaternion from euler angles in the ZXY rotation order. This is the rotation order Luanti Entities use
Parameters:
- X float
- Y float
- Z float
Returns:
-
quat
q
- get_rot_luanti_entity ()
-
alias of
from_euler_zxy
- get_euler_xyz (q)
-
convert a quaternion to an xyz euler angles. This is the rotation order used by irrlicht bones.
Parameters:
- q quat quaternion to convert
Returns:
- X
- Y
- Z
- get_rot_irrlicht_bone ()
-
alias of
get_euler_xyz
- from_euler_xyz (X, Y, Z)
-
create a quaternion from euler angles in the xyz rotation order. This is the rotation order irrlicht bones use
Parameters:
- X float
- Y float
- Z float
Returns:
-
quat
q
- get_rot_irrlicht_bone ()
-
alias of
quat.from_euler_zxy
- 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