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 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 to Vector6 and Matrix1x1 to Matrix6x6, including rectangular matrices like Matrix2x5.
  • Points sizes known at compile time, and convenience aliases: Point1 to Point6.
  • 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.

Modules

  • [Reexported at the root of this crate.] Data structures for vector and matrix computations.
  • [Reexported at the root of this crate.] Data structures for points and usual transformations (rotations, isometries, etc.)
  • [Reexported at the root of this crate.] Factorization of real matrices.
  • Sparse matrices.

Macros

  • Construct a dynamic matrix directly from data.
  • Construct a dynamic column vector directly from data.
  • Construct a fixed-size matrix directly from data.
  • Construct a fixed-size point directly from data.
  • Construct a fixed-size column vector directly from data.

Structs

  • A array-based statically sized matrix data storage.
  • The bidiagonalization of a general matrix.
  • The Cholesky decomposition of a symmetric-definite-positive matrix.
  • The QR decomposition (with column pivoting) of a general matrix.
  • A complex number in Cartesian form.
  • The cholesky decomposition of a column compressed sparse matrix.
  • A compressed sparse column matrix.
  • A storage of column-compressed sparse matrix based on a Vec.
  • An allocator based on GenericArray and VecStorage for statically-sized and dynamically-sized matrices respectively.
  • A dual quaternion.
  • Dim of dynamically-sized algebraic entities.
  • Euclidean norm.
  • LU decomposition with full row and column pivoting.
  • Hessenberg decomposition of a general matrix.
  • A direct isometry, i.e., a rotation followed by a translation (aka. a rigid-body motion).
  • LU decomposition with partial (row) pivoting.
  • Lp norm.
  • The most generic column-major matrix (and vector) type.
  • A point in an euclidean space.
  • A 3D orthographic projection stored as a homogeneous 4x4 matrix.
  • A sequence of row or column permutations.
  • A 3D perspective projection stored as a homogeneous 4x4 matrix.
  • The QR decomposition of a general matrix.
  • A quaternion. See the type alias UnitQuaternion = Unit<Quaternion> for a quaternion that may be used as a rotation.
  • A reflection wrt. a plane.
  • A rotation matrix.
  • Singular Value Decomposition of a general matrix.
  • Schur decomposition of a square matrix.
  • A similarity, i.e., an uniform scaling, followed by a rotation, followed by a translation.
  • A matrix data storage for a matrix slice. Only contains an internal reference to another matrix data storage.
  • A mutable matrix data storage for mutable matrix slice. Only contains an internal mutable reference to another matrix data storage.
  • Eigendecomposition of a symmetric matrix.
  • Tridiagonalization of a symmetric matrix.
  • A transformation matrix in homogeneous coordinates.
  • A translation.
  • UDU factorization.
  • L-infinite norm aka. Chebytchev norm aka. uniform norm aka. suppremum norm.
  • A wrapper that ensures the underlying algebraic entity has a unit norm.
  • A Vec-based matrix data storage. It may be dynamically-sized.

Enums

  • Tag representing an affine Transform. Its bottom-row is equal to (0, 0 ... 0, 1).
  • Tag representing the most general (not necessarily inversible) Transform type.
  • Tag representing the most general inversible Transform type.

Traits

  • Trait implemented by rotations that can be used inside of an Isometry or Similarity.
  • Trait alias for Add and AddAssign with result of type Self.
  • Trait alias for Div and DivAssign with result of type Self.
  • Trait alias for Mul and MulAssign with result of type Self.
  • Trait alias for Sub and SubAssign with result of type Self.
  • Trait shared by all complex fields and its subfields (like real numbers).
  • Trait for compressed column sparse matrix storage.
  • Trait for iterable compressed-column matrix storage.
  • Trait for mutably iterable compressed-column sparse matrix storage.
  • Trait for compressed column sparse matrix mutable storage.
  • Trait implemented by any type that can be used as a dimension. This includes type-level integers and Dynamic (for dimensions not known at compile-time).
  • Trait implemented exclusively by type-level integers.
  • Trait implemented by fields, i.e., complex numbers and floats.
  • Marker trait indicating that a storage is stored contiguously in memory.
  • Trait implemented by Dynamic.
  • Trait implemented by Dynamic and type-level integers different from U1.
  • A trait for abstract matrix norms.
  • Trait implemented by entities scan be be normalized and put in an Unit struct.
  • The trait shared by all matrix data storage.
  • Trait implemented by matrix data storage that can provide a mutable access to its elements.
  • Trait shared by all reals.
  • A matrix storage that can be reshaped in-place.
  • The basic scalar type for all structures of nalgebra.
  • Lane-wise generalization of bool for SIMD booleans.
  • Lane-wise generalisation of ComplexField for SIMD complex fields.
  • Lane-wise generalization of the standard PartialOrd for SIMD values.
  • Lanewise generalization of RealField for SIMD reals.
  • Base trait for every SIMD types.
  • A range with a size that may be known at compile-time.
  • Trait shared by all matrix data storage that don’t contain any uninitialized elements.
  • Trait shared by all mutable matrix data storage that don’t contain any uninitialized elements.
  • Indicates that Self is a more specific Transform category than Other.
  • Indicates that Self is a more general Transform category than Other.
  • Trait implemented by phantom types identifying the projective transformation type.
  • Traits that gives the Transform category that is compatible with the result of the multiplication of transformations with categories Self and Other.

Functions

  • absDeprecated
    The absolute value of a.
  • The center of two points.
  • Returns a reference to the input value clamped to the interval [min, max].
  • Converts an object from one type to an equivalent or more general one.
  • Converts an object from one type to an equivalent or more general one.
  • Use with care! Same as try_convert but without any property checks.
  • Use with care! Same as try_convert but without any property checks.
  • The distance between two points.
  • The squared distance between two points.
  • infDeprecated
    Returns the infimum of a and b.
  • inf_supDeprecated
    Returns simultaneously the infimum and supremum of a and b.
  • Indicates if try_convert will succeed without actually performing the conversion.
  • Same as cmp::max.
  • Same as cmp::min.
  • Gets the multiplicative identity element.
  • Clamp value between min and max. Returns None if value is not comparable to min or max.
  • Compare a and b using a partial ordering relation.
  • Returns true iff a and b are comparable and a >= b.
  • Returns true iff a and b are comparable and a > b.
  • Returns true iff a and b are comparable and a <= b.
  • Returns true iff a and b are comparable and a < b.
  • Return the maximum of a and b if they are comparable.
  • Return the minimum of a and b if they are comparable.
  • Sorts two values in increasing order using a partial ordering.
  • supDeprecated
    Returns the supremum of a and b.
  • Attempts to convert an object to a more specific one.
  • Attempts to convert an object to a more specific one.
  • Performs a LU decomposition to overwrite out with the inverse of matrix.
  • Computes the wilkinson shift, i.e., the 2x2 symmetric matrix eigenvalue to its tailing component tnn.
  • Wraps val into the range [min, max] using modular arithmetics.
  • Gets the additive identity element.

Type Aliases