Crate quaternion_core

Source
Expand description

Quaternion library written in Rust.

This provides Quaternion operations and interconversion with several attitude representations as generic functions (supports f32 & f64).

§Generics

Functions implementing the QuaternionOps trait can take both Quaternion<T> and Vector3<T> as arguments. In this case, Vector3<T> is treated as a Pure Quaternion.

For example:

use quaternion_core::{Vector3, Quaternion, add};
 
// --- Vector3 --- //
let v1: Vector3<f32> = [1.0, 2.0, 3.0];
let v2: Vector3<f32> = [0.1, 0.2, 0.3];
println!("{:?}", add(v1, v2));  // <--- It's [1.1, 2.2, 3.3]
 
// --- Quaternion --- //
let q1: Quaternion<f64> = (1.0, [2.0, 3.0, 4.0]);
let q2: Quaternion<f64> = (0.1, [0.2, 0.3, 0.4]);
println!("{:?}", add(q1, q2));  // <--- It's (1.1, [2.2, 3.3, 4.4])

§Versor

Versor refers to a Quaternion representing a rotation, the norm of which is 1.

The documentation for this crate basically writes Versor instead of Unit Quaternion, but the difference in usage is not clear. Please think Versor = Unit Quaternion.

Enums§

RotationSequence
Specifies the rotation sequence of Euler angles.
RotationType
Specifies the rotation type of Euler angles.

Traits§

QuaternionOps
This trait provides operations common to Quaternions and Pure Quaternions (Vector3).

Functions§

add
Addition of two quaternions (or vectors): a + b
conj
Calculate the conjugate of Quaternion.
cross
Cross product of two quaternions (or vectors): a × b
dot
Dot product of two quaternions (or vectors): a · b
exp
Exponential function of Quaternion or Pure Quaternion (Vector3).
frame_rotation
Frame rotation by quaternion (Frame Rotation - Point Fixed)
from_axis_angle
Generate Versor by specifying rotation angle[rad] and axis vector.
from_dcm
Convert a DCM to a Versor representing the q v q* rotation (Point Rotation - Frame Fixed).
from_euler_angles
Convert euler angles to versor.
from_rotation_vector
Convert Rotation vector to Versor.
hadamard
Calculate the element-wise product of two quaternions (or vectors)
hadamard_add
Hadamard product and addition in one step.
identity
Generate identity quaternion.
inv
Calculate the inverse of Quaternion or Pure Quaternion (Vector3).
lerp
Lerp (Linear interpolation)
ln
Natural logarithm of Quaternion.
ln_versor
Natural logarithm of Versor.
matrix_product
Product of DCM and Vector3
mul
Multiplication of two quaternions (or vectors).
negate
Invert the sign of a Vector3 or Quaternion.
norm
Calculate L2 norm of Vector3 or Quaternion.
normalize
Normalization of Vector3 or Quaternion.
point_rotation
Point rotation by quaternion (Point Rotation - Frame Fixed)
pow
Power function of Quaternion.
pow_versor
Power function of Versor.
rotate_a_to_b
Calculate the versor to rotate from vector a to vector b (Without singularity!).
rotate_a_to_b_shortest
Calculate the versor to rotate from vector a to vector b by the shortest path.
scale
Multiplies each component of the quaternion (or vector) by a given real number, scaling the entire quaternion uniformly: s * a.
scale_add
Scaling and addition in one step: s * a + b
slerp
Slerp (Spherical linear interpolation)
sqrt
Square root of Quaternion.
sqrt_versor
Square root of Versor.
sub
Subtraction of two quaternions (or vectors): a - b
sum
Calculate the sum of each element of a quaternion (or vector).
to_axis_angle
Calculate the rotation axis (unit vector) and the rotation angle[rad] around the axis from the Versor.
to_dcm
Convert a Versor to a DCM representing the q v q* rotation (Point Rotation - Frame Fixed).
to_euler_angles
Convert versor to euler angles.
to_rotation_vector
Convert Versor to Rotation vector.

Type Aliases§

DCM
Direction Cosine Matrix
Quaternion
Quaternion
Vector3
Three dimensional vector (Pure Quaternion)