#quaternions #vector-math #vector

no-std quaternion-core

Provides quaternion operations and interconversion with several attitude representations

12 unstable releases (4 breaking)

0.5.0 Nov 30, 2023
0.4.2 Jun 2, 2023
0.4.0 Feb 4, 2023
0.3.5 Dec 25, 2022
0.3.4 Jul 27, 2022

#86 in Math

Download history 576/week @ 2024-02-26 407/week @ 2024-03-04 401/week @ 2024-03-11 492/week @ 2024-03-18 552/week @ 2024-03-25 534/week @ 2024-04-01 743/week @ 2024-04-08 423/week @ 2024-04-15 370/week @ 2024-04-22 389/week @ 2024-04-29 384/week @ 2024-05-06 528/week @ 2024-05-13 548/week @ 2024-05-20 264/week @ 2024-05-27 379/week @ 2024-06-03 340/week @ 2024-06-10

1,545 downloads per month
Used in quaternion-wrapper




Latest version Documentation Minimum rustc License

Quaternion library written in Rust.

This provides Quaternion operations and interconversion with several attitude representations as generic functions (supports f32 & f64).

Additionally, it also works in a no_std environment!


Add this to your Cargo.toml:

quaternion-core = "0.5"

For use in a no_std environment:

version = "0.5"
default-features = false
features = ["libm"]



Interconversion with 24 different euler angles (12 each of Intrinsic and Extrinsic) is possible!!

Other interconversions with axis/angle and rotation vector are also possible.



When this feature is enabled, the mul_add method will be used internally as much as possible. That is, (s * a) + b will be expanded as s.mul_add(a, b) at compile time.

This crate uses the mul_add method mainly to improve calculation speed, but if the CPU does not support the FMA (Fused Multiply-Add) instruction or if the libm feature is enabled, then the calculation is performed by the software implementation. In this case, it may be rather slower than if the fma feature is not enabled.


If you set default-features=false (do not import std), you must enable this feature.

In this case, mathematical functions (e.g. sin, cos, sqrt ...) are provided by libm crate.


When this feature is enabled, the default norm(a) implementation is compiled with dot(a, a).sqrt() instead.

By default, the norm(a) function is implemented in such a way that overflow and underflow are less likely to occur than with dot(a, a).sqrt(). However, if extremely large values are not input and underflow is not that much of a concern, dot(a, a).sqrt() is sufficient (and dot(a, a).sqrt() is faster than the default implementation in most cases).


When this feature is enabled, RotationSequence and RotationType will both implement serde::Serialize and serde::Deserialize.



use quaternion_core as quat;

const PI: f64 = std::f64::consts::PI;
const EPSILON: f64 = 1e-12;

fn main() {
    // Generates a quaternion representing the
    // rotation of π/2[rad] around the y-axis.
    let q = quat::from_axis_angle([0.0, 1.0, 0.0], PI/2.0);

    // Rotate the point.
    let r = quat::point_rotation(q, [2.0, 2.0, 0.0]);

    // Check if the calculation is correct.
    let diff = quat::sub([0.0, 2.0, -2.0], r);
    for val in diff {
        assert!( val.abs() < EPSILON );


Release notes are available in RELEASES.md.


Licensed under either of Apache License, Version 2.0 or MIT License at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.