#vector #quaternions #matrix #matrix-vector #algebra

no-std lin_alg

Vector, matrix, and quaternion operations for general purposes

7 stable releases

new 1.0.6 Feb 14, 2025
1.0.5 Feb 4, 2025
1.0.4 Jan 25, 2025
1.0.0 Nov 23, 2024

#259 in Rendering

Download history 2/week @ 2024-11-03 42/week @ 2024-11-17 107/week @ 2024-11-24 4/week @ 2024-12-01 9/week @ 2024-12-08 125/week @ 2024-12-29 30/week @ 2025-01-05 168/week @ 2025-01-12 156/week @ 2025-01-19 45/week @ 2025-01-26 141/week @ 2025-02-02 90/week @ 2025-02-09

501 downloads per month
Used in 2 crates

MIT license

62KB
1K SLoC

Vectors and quaternions, and matrices for general purposes, and computer graphics.

Crate Docs

Vector, matrix, and quaternion data structures and operations. Uses f32 or f64 based types.

Example use cases:

  • Computer graphics
  • Biomechanics
  • Robotics and unmanned aerial vehicles.
  • Structural chemistry and biochemistry
  • Cosmology modeling
  • Various scientific and engineering applications
  • Aircraft attitude systems and autopilots

Vector and Quaternion types are copy.

For Compatibility with no_std tgts, e.g. embedded. Use the no_std feature. This feature ommits std::fmt::Display implementations. For computer-graphics functionality (e.g. specialty matrix constructors, and [de]serialization to byte arrays for passing to and from GPUs), use the computer_graphics For bincode binary encoding and decoding, use the encode feature.

Do not run cargo fmt on this code base; the macro used to prevent duplication of code between f32 and f64` mules causes undesirable behavior.

For information on practical quaternion operations: Quaternions: A practical guide

The From trait is implemented for most types, for converting between f32 and f64 variants using the into() syntax.

See the official documention (Linked above) for details. Below is a brief, impractical syntax overview:

use core::f32::consts::TAU;

use lin_alg::f32::{Vec3, Quaternion};

fn main() {
    let _ = Vec3::new_zero();
    
    let a = Vec3::new(1., 1., 1.);
    let b = Vec3::new(0., -1., 10.);
    
    let c = a + b;
    
    let mut d = a.dot(b);
    
    d.normalize();
    let e = c.to_normalized();
    
    a.magnitude();
    
    let f = a.cross(b);
    
    let g = Quaternion::from_unit_vecs(d, e);
    
    let h = g.inverse();
    
    let k = Quaternion::new_identity();
    
    let l = k.rotate_vec(c);
    
    l.magnitude();
    
    let quaternion = Quaternion::from_axis_angle(Vec3::new(1., 0., 0.), TAU / 16.);
}

Dependencies

~92–270KB