quaternions

simple quaternion arithmetic with traits

2 releases

0.5.0-a2 May 14, 2022

MIT/Apache

10KB
230 lines

Quaternions

crate quaternions

got some inspirations from quaternion and a lot of code generated by Copilot.

Docs https://docs.rs/crate/quaternions .

License

Licensed under either of

at your option.

Contributions are welcome.


lib.rs:

a simpler quaternion math library with traits.

extern crate quaternions;
use quaternions::{Quaternion, q, qi};

let a = Quaternion { w: 1.0, x: 2.0, y: 3.0, z: 4.0 };
a.w;

// quick creates
let b1 = q::<f32>(1.0, 2.0, 3.0, 4.0);

// quick creates with integers
let b2 = qi::<f32>(1, 2, 3, 4);

b1 + b2;
b1 - b2;
b1 * b2;
b1 / b2;
b1.conjugate();
b1.scale(1.5);
b1.square_length();
b1.length();
b1.inverse();

There are also mutable APIs:

extern crate quaternions;
use quaternions::{Quaternion, q, qi};

let mut c = Quaternion::id();
let b = qi::<f32>(1, 2, 3, 4);

c += b;
c -= b;
c *= b;
// no division
c.inverse_mut();
c.conjugate_mut();
c.scale_mut(1.5);

Dependencies

~150KB