#math #quaternion #vector

no-std quaternion-core

Provides quaternion operations and interconversion with several attitude representations

7 releases

new 0.3.3 Jul 7, 2022
0.3.2 Jul 2, 2022
0.3.1 Jun 22, 2022
0.2.1 Jun 12, 2022
0.1.0 May 7, 2022

#101 in Math

Download history 27/week @ 2022-05-03 19/week @ 2022-05-10 7/week @ 2022-05-17 7/week @ 2022-05-24 11/week @ 2022-05-31 45/week @ 2022-06-07 40/week @ 2022-06-14 39/week @ 2022-06-21 34/week @ 2022-06-28

162 downloads per month
Used in quaternion-wrapper

MIT/Apache

73KB
1K SLoC

quaternion-core

Quaternion library written in Rust.

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

Usage

Add this to your Cargo.toml:

[dependencies]
quaternion-core = "0.3"

Conversion

conversion

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.

Features

Cargo.toml:

[dependencies.quaternion-core]
version = "0.3"

# Uncomment if you wish to use FMA.
#features = ["fma"]

# Uncomment if you wish to use in "no_std" environment.
#default-features = false
#features = ["libm"]

fma

This library uses the mul_add method mainly to improve the performance, but by default it is replace with a unfused multiply-add (s*a + b) . If you wish to use mul_add method, enable the fma feature.

If your CPU does not support FMA instructions, or if you use libm (running in no_std environment), enabling the fma feature may cause slowdown of computation speed. Also, due to rounding error, results of s.mul_add(a, b) and s*a + b will not match perfectly.

libm & default-features = false

These options allow for use in the no_std environment. In this case, mathematical functions (e.g. sin, cos, sqrt ...) are provided by libm.

Example

src/main.rs:

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 );
    }
}

License

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

Contribution

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.

Dependencies

~215KB