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§

  • Addition of two quaternions (or vectors): a + b
  • Calculate the conjugate of Quaternion.
  • Cross product of two quaternions (or vectors): a × b
  • Dot product of two quaternions (or vectors): a · b
  • Exponential function of Quaternion or Pure Quaternion (Vector3).
  • Frame rotation by quaternion (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.
  • Calculate the element-wise product of two quaternions (or vectors)
  • Hadamard product and addition in one step.
  • 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
  • Multiplication of two quaternions (or vectors).
  • Invert the sign of a Vector3 or Quaternion.
  • Calculate L2 norm of Vector3 or Quaternion.
  • Normalization of Vector3 or Quaternion.
  • Point rotation by quaternion (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.
  • Multiplies each component of the quaternion (or vector) by a given real number, scaling the entire quaternion uniformly: s * a.
  • Scaling and addition in one step: s * a + b
  • Slerp (Spherical linear interpolation)
  • Square root of Quaternion.
  • Square root of Versor.
  • Subtraction of two quaternions (or vectors): a - b
  • Calculate the sum of each element of a quaternion (or vector).
  • 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§