Crate quaternion_core

Crate quaternion_core 

Source
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§

RotationSequence
Specifies the rotation sequence of Euler angles.
RotationType
Specifies the rotation type of Euler angles.

Traits§

QuaternionOps
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] and axis vector.
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 a to vector b (Without singularity!).
rotate_a_to_b_shortest
Calculate the versor to rotate from vector a to vector b by 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 axis and the rotation angle around the axis from 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)