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

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
  • Generate identity quaternion.
  • 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 the versor to rotate from vector a to vector b (Without singularity!).
  • Calculate the versor to rotate from vector a to vector b by the shortest path.
  • s * a
  • s * a + b
  • Slerp (Spherical linear interpolation)
  • Square root of Quaternion.
  • Square root of Versor.
  • 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.

Type Aliases