Expand description
Quaternion library written in Rust.
This crate provides Quaternion operations and conversions between several rotation
representations. Functions are generic and support f32 and f64.
§Generics
Functions implementing the QuaternionOps trait can take both Quaternion<T>
and Vector3<T> types as arguments (How convenient…!!).
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];
let added_v = add(v1, v2); // <--- [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]);
let added_q = add(q1, q2); // <--- (1.1, [2.2, 3.3, 4.4])§What is Versor?
Versor denotes a Quaternion representing rotation, with a norm of 1. This is precisely what is meant by a Unit Quaternion.
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 Vector3s:
a + b - conj
- Calculate the conjugate of a Quaternion.
- cross
- Cross product of two Quaternions or Vector3s:
a × b - dot
- Dot product of two Quaternions or Vector3s:
a · b - exp
- Exponential function of a Quaternion or Pure Quaternion (Vector3).
- frame_
rotation - Rotates a frame by the Versor (Frame Rotation - Point Fixed)
- from_
axis_ angle - Generate Versor by specifying rotation
angle[rad] andaxisvector. - from_
dcm - Converts a Direction Cosine Matrix (DCM) into a Versor
- from_
euler_ angles - Converts a Euler Angles into a Versor.
- from_
rotation_ vector - Converts a Rotation Vector into a Versor.
- hadamard
- Calculate the element-wise product of two Quaternions or Vector3s.
- hadamard_
add - Hadamard product and addition in one step.
- identity
- Generate identity quaternion.
- inv
- Calculate the inverse of a Quaternion or Pure Quaternion (Vector3).
- lerp
- Lerp (Linear interpolation)
- ln
- Natural logarithm of a Quaternion.
- ln_
versor - Natural logarithm of a Versor.
- matrix_
product - Product of Direction Cosine Matrix (DCM) and Vector3
- mul
- Multiplication of two Quaternions or Pure Quaternoins (Vector3).
- negate
- Invert the sign of a Vector3s or Quaternions.
- norm
- Calculate L2 norm of Vector3s or Quaternions.
- normalize
- Normalize a Vector3 or Quaternion.
- point_
rotation - Rotates a point by the Versor (Point Rotation - Frame Fixed)
- pow
- Power function of a Quaternion.
- pow_
versor - Power function of a Versor.
- rotate_
a_ to_ b - Calculate the Versor to rotate from vector
ato vectorb(Without singularity!). - rotate_
a_ to_ b_ shortest - Calculate the versor to rotate from vector
ato vectorbby the shortest path. - scale
- Scaling a Quaternion or Vector3 by a scalar factor:
s * a - scale_
add - Scaling and addition in one step:
s * a + b - slerp
- Slerp (Spherical linear interpolation)
- sqrt
- Square root of a Quaternion.
- sqrt_
versor - Square root of a Versor.
- sub
- Subtraction of two Quaternions or Vector3s:
a - b - sum
- Sum all elements of a Quaternion or Vector3.
- to_
axis_ angle - Extracts the rotation
axisand the rotationanglearound theaxisfrom the Versor. - to_dcm
- Converts a Versor into a Direction Cosine Matrix (DCM).
- to_
euler_ angles - Converts a Versor into a Euler Angles.
- to_
rotation_ vector - Converts a Versor into a Rotation Vector.
Type Aliases§
- DCM
- Direction Cosine Matrix
- Quaternion
- Quaternion
- Vector3
- Three dimensional vector (Pure Quaternion)