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
Represents 12 different rotations.
Specify the rotation type of Euler angles.
Traits
This trait provides operations common to Quaternions and Pure Quaternions (Vector3).
Functions
a + b
Calculate the conjugate of Quaternion.
Cross product (vector product): a × b
a · b
Exponential function of Quaternion or Pure Quaternion (Vector3).
Rotation of frame (Frame Rotation - Point Fixed)
Generate Versor by specifying rotation angle
[rad] and axis
vector.
Convert a DCM to a Versor representing
the q v q*
rotation (Point Rotation - Frame Fixed).
Convert Euler angles to Versor.
Convert Rotation vector to Versor.
a ∘ b
a ∘ b + c
Calculate the inverse of Quaternion or Pure Quaternion (Vector3).
Lerp (Linear interpolation)
Natural logarithm of Quaternion.
Natural logarithm of Versor.
Product of DCM and Vector3
Hamilton product (Product of Quaternion or Pure Quaternion)
Invert the sign of a Vector3 or Quaternion.
Calculate L2 norm of Vector3 or Quaternion.
Normalization of Vector3 or Quaternion.
Rotation of point (Point Rotation - Frame Fixed)
Power function of Quaternion.
Power function of Versor.
Calculate a Versor to rotate from vector a
to b
.
Calculate a Versor to rotate from vector a
to b
.
s * a
s * a + b
Slerp (Spherical linear interpolation)
a - b
Calculate the sum of each element of Quaternion or Vector3.
Calculate the rotation axis
(unit vector) and the rotation angle
[rad]
around the axis
from the Versor.
Convert a Versor to a DCM representing
the q v q*
rotation (Point Rotation - Frame Fixed).
Convert Versor to Euler angles.
Convert Versor to Rotation vector.