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§
- Rotation
Sequence - Specifies the rotation sequence of Euler angles.
- Rotation
Type - Specifies the rotation type of Euler angles.
Traits§
- Quaternion
Ops - 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] andaxis
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 vectorb
(Without singularity!). - rotate_
a_ to_ b_ shortest - Calculate the versor to rotate from vector
a
to vectorb
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 rotationangle
[rad] around theaxis
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)