Crate nalgebra [−] [src]
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] nalgebra = "0.11"
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 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); relative_eq!(b.axis().unwrap(), axis); 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 an homogeneous matrix:
Affine2
,Affine3
. - Projective (i.e. invertible) transformations stored as an homogeneous matrix:
Projective2
,Projective3
. - General transformations that does not have to be invertible, stored as an homogeneous matrix:
Transform2
,Transform3
. - 3D projections for computer graphics:
Perspective3
,Orthographic3
. - Linear algebra and data analysis operators: QR decomposition, eigen-decomposition.
- Implements traits from the alga crate for generic programming.
Reexports
pub use core::*; |
pub use geometry::*; |
Modules
core |
[Reexported at the root of this crate.] Data structures for vector and matrix computations. |
geometry |
[Reexported at the root of this crate.] Data structures for points and usual transformations (rotations, isometries, etc.) |
Structs
Id |
The universal identity element wrt. a given operator, usually noted |
Traits
Axpy |
Operation that combines scalar multiplication and vector addition. |
Functions
abs |
The absolute value of |
angle |
Computes the smallest angle between two vectors. |
center |
The center of two points. |
clamp |
Returns a reference to the input value clamped to the interval |
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 |
convert_unchecked⚠ |
Use with care! Same as |
dimension |
The dimension of the given algebraic entity seen as a vector space. |
distance |
The distance between two points. |
distance_squared |
The squared distance between two points. |
dot |
Computes the dot product of two vectors. |
id |
Gets the ubiquitous multiplicative identity element. |
inf |
Returns the infimum of |
inf_sup |
Returns simultaneously the infimum and supremum of |
inverse |
Computes the multiplicative inverse of an (always invertible) algebraic entity. |
is_convertible |
Indicates if |
max |
Same as |
min |
Same as |
norm |
Computes the L2 (euclidean) norm of a vector. |
norm_squared |
Computes the squared L2 (euclidean) norm of the vector |
normalize |
Computes the normalized version of the vector |
one |
Gets the multiplicative identity element. |
origin |
Gets the origin of the given point. |
partial_clamp |
Clamp |
partial_cmp |
Compare |
partial_ge |
Returns |
partial_gt |
Returns |
partial_le |
Returns |
partial_lt |
Returns |
partial_max |
Return the maximum of |
partial_min |
Return the minimum of |
partial_sort2 |
Sorts two values in increasing order using a partial ordering. |
sup |
Returns the supremum of |
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. |
try_inverse |
Tries to gets an inverted copy of a square matrix. |
try_normalize |
Computes the normalized version of the vector |
wrap |
Wraps |
zero |
Gets the additive identity element. |