Expand description
§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.
Re-exports§
pub use base as core;
pub use crate::base::*;
pub use crate::geometry::*;
pub use crate::linalg::*;
pub use crate::sparse::*;
Modules§
- base
- [Reexported at the root of this crate.] Data structures for vector and matrix computations.
- debug
- Various tools useful for testing/debugging/benchmarking.
- geometry
- [Reexported at the root of this crate.] Data structures for points and usual transformations (rotations, isometries, etc.)
- io
- Parsers for various matrix formats.
- linalg
- [Reexported at the root of this crate.] Factorization of real matrices.
- proptest
proptest
-related features fornalgebra
data structures.- sparse
- Sparse matrices.
Macros§
- dmatrix
- Construct a dynamic matrix directly from data.
- dvector
- Construct a dynamic column vector directly from data.
- matrix
- Construct a fixed-size matrix directly from data.
- point
- Construct a fixed-size point directly from data.
- stack
- Construct a new matrix by stacking matrices in a block matrix.
- vector
- Construct a fixed-size column vector directly from data.
Structs§
- Complex
- A complex number in Cartesian form.
Traits§
- Closed
AddAssign - Trait alias for
Add
andAddAssign
with result of typeSelf
. - Closed
DivAssign - Trait alias for
Div
andDivAssign
with result of typeSelf
. - Closed
MulAssign - Trait alias for
Mul
andMulAssign
with result of typeSelf
. - Closed
SubAssign - Trait alias for
Sub
andSubAssign
with result of typeSelf
. - Complex
Field - Trait shared by all complex fields and its subfields (like real numbers).
- Field
- Trait implemented by fields, i.e., complex numbers and floats.
- Real
Field - Trait shared by all reals.
- Simd
Bool - Lane-wise generalization of
bool
for SIMD booleans. - Simd
Complex Field - Lane-wise generalisation of
ComplexField
for SIMD complex fields. - Simd
Partial Ord - Lane-wise generalization of the standard
PartialOrd
for SIMD values. - Simd
Real Field - Lanewise generalization of
RealField
for SIMD reals. - Simd
Value - Base trait for every SIMD types.
Functions§
- abs
Deprecated - The absolute value of
a
. - center
- The center of two points.
- clamp
- Returns a reference to the input value clamped to the interval
[min, max]
. - convert
- Converts an object from one type to an equivalent or more general one.
- convert_
ref - Converts an object from one type to an equivalent or more general one.
- convert_
ref_ unchecked - Use with care! Same as
try_convert()
but without any property checks. - convert_
unchecked - Use with care! Same as
try_convert()
but without any property checks. - distance
- The distance between two points.
- distance_
squared - The squared distance between two points.
- inf
Deprecated - Returns the infimum of
a
andb
. - inf_sup
Deprecated - Returns simultaneously the infimum and supremum of
a
andb
. - is_
convertible - Indicates if
try_convert()
will succeed without actually performing the conversion. - max
- Same as
cmp::max
. - min
- Same as
cmp::min
. - one
- Gets the multiplicative identity element.
- partial_
clamp - Clamp
value
betweenmin
andmax
. ReturnsNone
ifvalue
is not comparable tomin
ormax
. - partial_
cmp - Compare
a
andb
using a partial ordering relation. - partial_
ge - Returns
true
iffa
andb
are comparable anda >= b
. - partial_
gt - Returns
true
iffa
andb
are comparable anda > b
. - partial_
le - Returns
true
iffa
andb
are comparable anda <= b
. - partial_
lt - Returns
true
iffa
andb
are comparable anda < b
. - partial_
max - Return the maximum of
a
andb
if they are comparable. - partial_
min - Return the minimum of
a
andb
if they are comparable. - partial_
sort2 - Sorts two values in increasing order using a partial ordering.
- sup
Deprecated - Returns the supremum of
a
andb
. - try_
convert - Attempts to convert an object to a more specific one.
- try_
convert_ ref - Attempts to convert an object to a more specific one.
- wrap
- Wraps
val
into the range[min, max]
using modular arithmetics. - zero
- Gets the additive identity element.