113 releases
0.33.2 | Oct 29, 2024 |
---|---|
0.33.0 | Jun 23, 2024 |
0.32.5 | Mar 28, 2024 |
0.32.3 | Jul 9, 2023 |
0.1.0 | Nov 22, 2014 |
#5 in Math
805,585 downloads per month
Used in 2,517 crates
(954 directly)
2MB
36K
SLoC
Linear algebra library for the Rust programming language.
lib.rs
:
nalgebra
nalgebra is a linear algebra library written for Rust targeting:
- General-purpose linear algebra (still lacks a lot of features…)
- Real-time computer graphics.
- Real-time computer physics.
Using nalgebra
You will need the last stable build of the rust compiler and the official package manager: cargo.
Simply add the following to your Cargo.toml
file:
[dependencies]
// TODO: replace the * by the latest version.
nalgebra = "*"
Most useful functionalities of nalgebra are grouped in the root module nalgebra::
.
However, the recommended way to use nalgebra is to import types and traits
explicitly, and call free-functions using the na::
prefix:
#[macro_use]
extern crate approx; // For the macro assert_relative_eq!
extern crate nalgebra as na;
use na::{Vector3, Rotation3};
fn main() {
let axis = Vector3::x_axis();
let angle = 1.57;
let b = Rotation3::from_axis_angle(&axis, angle);
assert_relative_eq!(b.axis().unwrap(), axis);
assert_relative_eq!(b.angle(), angle);
}
Features
nalgebra is meant to be a general-purpose, low-dimensional, linear algebra library, with an optimized set of tools for computer graphics and physics. Those features include:
- A single parametrizable type
Matrix
for vectors, (square or rectangular) matrices, and slices with dimensions known either at compile-time (using type-level integers) or at runtime. - Matrices and vectors with compile-time sizes are statically allocated while dynamic ones are allocated on the heap.
- Convenient aliases for low-dimensional matrices and vectors:
Vector1
toVector6
andMatrix1x1
toMatrix6x6
, including rectangular matrices likeMatrix2x5
. - Points sizes known at compile time, and convenience aliases:
Point1
toPoint6
. - Translation (seen as a transformation that composes by multiplication):
Translation2
,Translation3
. - Rotation matrices:
Rotation2
,Rotation3
. - Quaternions:
Quaternion
,UnitQuaternion
(for 3D rotation). - Unit complex numbers can be used for 2D rotation:
UnitComplex
. - Algebraic entities with a norm equal to one:
Unit<T>
, e.g.,Unit<Vector3<f32>>
. - Isometries (translation ⨯ rotation):
Isometry2
,Isometry3
- Similarity transformations (translation ⨯ rotation ⨯ uniform scale):
Similarity2
,Similarity3
. - Affine transformations stored as a homogeneous matrix:
Affine2
,Affine3
. - Projective (i.e. invertible) transformations stored as a homogeneous matrix:
Projective2
,Projective3
. - General transformations that does not have to be invertible, stored as a homogeneous matrix:
Transform2
,Transform3
. - 3D projections for computer graphics:
Perspective3
,Orthographic3
. - Matrix factorizations:
Cholesky
,QR
,LU
,FullPivLU
,SVD
,Schur
,Hessenberg
,SymmetricEigen
. - Insertion and removal of rows of columns of a matrix.
Dependencies
~0.8–4.5MB
~101K SLoC