Crate nalgebra [−] [src]
nalgebra
nalgebra is a low-dimensional 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.10.*"Run
All the functionality of nalgebra is grouped in one place: the root module nalgebra::. This
module re-exports everything and includes free functions for all traits methods performing
out-of-place operations.
Thus, you can import the whole prelude using:
use nalgebra::*;Run
However, the recommended way to use nalgebra is to import types and traits
explicitly, and call free-functions using the na:: prefix:
extern crate nalgebra as na; use na::{Vector3, Rotation3, Rotation}; fn main() { let a = Vector3::new(1.0f64, 1.0, 1.0); let mut b = Rotation3::new(na::zero()); b.append_rotation_mut(&a); assert!(na::approx_eq(&na::rotation(&b), &a)); }Run
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:
- Vectors with predefined static sizes:
Vector1,Vector2,Vector3,Vector4,Vector5,Vector6. - Vector with a user-defined static size:
VectorN(available only with thegeneric_sizesfeature). - Points with static sizes:
Point1,Point2,Point3,Point4,Point5,Point6. - Square matrices with static sizes:
Matrix1,Matrix2,Matrix3,Matrix4,Matrix5,Matrix6. - Rotation matrices:
Rotation2,Rotation3 - Quaternions:
Quaternion,Unit<Quaternion>. - Unit-sized values (unit vectors, unit quaternions, etc.):
Unit<T>, e.g.,Unit<Vector3<f32>>. - Isometries (translation ⨯ rotation):
Isometry2,Isometry3 - Similarity transformations (translation ⨯ rotation ⨯ uniform scale):
Similarity2,Similarity3. - 3D projections for computer graphics:
Persp3,PerspMatrix3,Ortho3,OrthoMatrix3. - Dynamically sized heap-allocated vector:
DVector. - Dynamically sized stack-allocated vectors with a maximum size:
DVector1toDVector6. - Dynamically sized heap-allocated (square or rectangular) matrix:
DMatrix. - Linear algebra and data analysis operators:
Covariance,Mean,qr,cholesky. - Almost one trait per functionality: useful for generic programming.
Macros
| assert_approx_eq_eps |
Asserts approximate equality within a given tolerance of two values with the
|
| assert_approx_eq_ulps |
Asserts approximate equality within a given tolerance of two values with the
|
Structs
| DMatrix |
Matrix with dimensions unknown at compile-time. |
| DMatrix1 |
A stack-allocated dynamically sized matrix with at most one row and column. |
| DMatrix2 |
A stack-allocated dynamically sized square or rectangular matrix with at most 2 rows and columns. |
| DMatrix3 |
A stack-allocated dynamically sized square or rectangular matrix with at most 3 rows and columns. |
| DMatrix4 |
A stack-allocated dynamically sized square or rectangular matrix with at most 4 rows and columns. |
| DMatrix5 |
A stack-allocated dynamically sized square or rectangular matrix with at most 5 rows and columns. |
| DMatrix6 |
A stack-allocated dynamically sized square or rectangular matrix with at most 6 rows and columns. |
| DVector |
Heap allocated, dynamically sized vector. |
| DVector1 |
Stack-allocated, dynamically sized vector with a maximum size of 1. |
| DVector2 |
Stack-allocated, dynamically sized vector with a maximum size of 2. |
| DVector3 |
Stack-allocated, dynamically sized vector with a maximum size of 3. |
| DVector4 |
Stack-allocated, dynamically sized vector with a maximum size of 4. |
| DVector5 |
Stack-allocated, dynamically sized vector with a maximum size of 5. |
| DVector6 |
Stack-allocated, dynamically sized vector with a maximum size of 6. |
| Identity |
Special identity matrix. All its operation are no-ops. |
| Isometry2 |
Two dimensional direct isometry. |
| Isometry3 |
Three dimensional direct isometry. |
| Matrix1 |
Square matrix of dimension 1. |
| Matrix2 |
Square matrix of dimension 2. |
| Matrix3 |
Square matrix of dimension 3. |
| Matrix4 |
Square matrix of dimension 4. |
| Matrix5 |
Square matrix of dimension 5. |
| Matrix6 |
Square matrix of dimension 6. |
| Orthographic3 |
A 3D orthographic projection stored without any matrix. |
| OrthographicMatrix3 |
A 3D orthographic projection stored as a 4D matrix. |
| Perspective3 |
A 3D perspective projection stored without any matrix. |
| PerspectiveMatrix3 |
A 3D perspective projection stored as a 4D matrix. |
| Point1 |
Point of dimension 1. |
| Point2 |
Point of dimension 2. |
| Point3 |
Point of dimension 3. |
| Point4 |
Point of dimension 4. |
| Point5 |
Point of dimension 5. |
| Point6 |
Point of dimension 6. |
| Quaternion |
A quaternion. See the |
| Rotation2 |
Two dimensional rotation matrix. |
| Rotation3 |
Three dimensional rotation matrix. |
| Similarity2 |
A two-dimensional similarity transformation. |
| Similarity3 |
A three-dimensional similarity transformation. |
| Unit |
A wrapper that ensures the undelying algebraic entity has a unit norm. |
| Vector1 |
Vector of dimension 1. |
| Vector2 |
Vector of dimension 2. |
| Vector3 |
Vector of dimension 3. |
| Vector4 |
Vector of dimension 4. |
| Vector5 |
Vector of dimension 5. |
| Vector6 |
Vector of dimension 6. |
Enums
| PartialOrdering |
Result of a partial ordering. |
Traits
| Absolute |
Trait of objects having an absolute value. This is useful if the object does not have the same type as its absolute value. |
| AbsoluteRotate |
Composition of a rotation and an absolute value. |
| ApproxEq |
Trait for testing approximate equality |
| Axpy |
Trait of objects implementing the |
| BaseFloat |
Basic floating-point number numeric trait. |
| BaseNum |
Basic integral numeric trait. |
| Basis |
Traits of objects which can form a basis (typically vectors). |
| Bounded |
Types that have maximum and minimum value. |
| Cast |
Traits of objects which can be created from an object of type |
| Column |
Trait to access columns of a matrix or vector. |
| ColumnSlice |
Trait to access part of a column of a matrix |
| Covariance |
Trait for computing the covariance of a set of data. |
| Cross |
Trait of elements having a cross product. |
| CrossMatrix |
Trait of elements having a cross product operation which can be expressed as a matrix. |
| Determinant |
Trait of objects having a determinant. Typically used by square matrices. |
| Diagonal |
Trait to get the diagonal of square matrices. |
| Dimension |
Trait of objects having a spacial dimension known at compile time. |
| Dot |
Traits of objects having a dot product. |
| EigenQR |
Trait for computing the eigenvector and eigenvalues of a square matrix usin the QR algorithm. |
| Eye |
Trait for constructing the identity matrix |
| FloatPoint |
Trait of points with components implementing the |
| FloatVector |
Trait of vector with components implementing the |
| FromHomogeneous |
Traits of objects which can be build from an homogeneous coordinate form. |
| Indexable |
This is a workaround of current Rust limitations. |
| Inverse |
Trait of objects having an inverse. Typically used to implement matrix inverse. |
| Iterable |
This is a workaround of current Rust limitations. |
| IterableMut |
This is a workaround of current Rust limitations. |
| Matrix |
Trait of matrices. |
| Mean |
Trait for computing the mean of a set of data. |
| Norm |
Traits of objects having an euclidian norm. |
| NumPoint |
Trait grouping most common operations on points. |
| NumVector |
Trait grouping most common operations on vectors. |
| Origin |
The zero element of a vector space, seen as an element of its embeding affine space. |
| Outer |
Traits of objects having an outer product. |
| PartialOrder |
Pointwise ordering operations. |
| PointAsVector |
Trait that relates a point of an affine space to a vector of the associated vector space. |
| Repeat |
Trait for constructiong an object repeating a value. |
| Rotate |
Trait of objects able to rotate other objects. |
| Rotation |
Trait of object which can represent a rotation, and to which new rotations can be appended. A rotation is assumed to be an isometry without translation and without reflexion. |
| RotationMatrix |
Trait of transformation having a rotation extractable as a rotation matrix. This can typically be implemented by quaternions to convert them to a rotation matrix. |
| RotationTo |
Trait of object that can be rotated to be superimposed with another one of the same nature. |
| RotationWithTranslation |
Various composition of rotation and translation. |
| Row |
Trait to access rows of a matrix or a vector. |
| RowSlice |
Trait to access part of a row of a matrix |
| Shape |
The shape of an indexable object. |
| SquareMatrix |
Trait implemented by square matrices. |
| ToHomogeneous |
Traits of objects which can be put in homogeneous coordinates form. |
| Transform |
Trait of objects able to transform other objects. |
| Transformation |
Trait of object which represent a transformation, and to which new transformations can be appended. |
| Translate |
Trait of objects able to translate other objects. This is typically implemented by vectors to translate points. |
| Translation |
Trait of object which represent a translation, and to wich new translation can be appended. |
| Transpose |
Trait of objects which can be transposed. |
| UniformSphereSample |
Trait of vectors able to sample a unit sphere. |
Functions
| abs |
Computes a component-wise absolute value. |
| absolute_rotate |
Applies a rotation using the absolute values of its components. |
| angle_between |
Computes the angle of the rotation needed to transfom |
| append_rotation |
Applies the rotation |
| append_rotation_wrt_center |
Rotates a copy of |
| append_rotation_wrt_point |
Rotates a copy of |
| append_transformation |
Gets a transformed copy of |
| append_translation |
Applies the translation |
| approx_eq |
Tests approximate equality. |
| approx_eq_eps |
Tests approximate equality using a custom epsilon. |
| canonical_basis |
Computes the canonical basis for a given dimension. |
| canonical_basis_element |
Gets the (0-based) i-th element of the canonical basis of V. |
| cast |
Converts an object from one type to another. |
| center |
Returns the center of two points. |
| cholesky |
Cholesky decomposition G of a square symmetric positive definite matrix A, such that A = G * GT |
| clamp |
Change the input value to ensure it is on the range |
| covariance |
Computes the covariance of a set of observations. |
| cross |
Computes the cross product of two vectors. |
| cross_matrix |
Given a vector, computes the matrix which, when multiplied by another vector, computes a cross product. |
| determinant |
Computes the determinant of a square matrix. |
| diagonal |
Gets the diagonal of a square matrix. |
| dimension |
Gets the dimension an object lives in. |
| distance |
Returns the distance between two points. |
| distance_squared |
Returns the squared distance between two points. |
| dot |
Computes the dot product of two vectors. |
| eigen_qr |
Computes the eigenvalues and eigenvectors of a square matrix usin the QR algorithm. |
| from_homogeneous |
Converts a matrix or vector from homogeneous coordinates. |
| hessenberg |
Hessenberg Returns the matrix m in Hessenberg form and the corresponding similarity transformation |
| householder_matrix |
Get the householder matrix corresponding to a reflexion to the hyperplane
defined by |
| identity |
Create a special identity object. |
| inf |
Returns the infimum of |
| inverse |
Gets an inverted copy of a matrix. |
| inverse_rotate |
Applies an inverse rotation to a vector. |
| inverse_rotation |
Gets the inverse rotation applicable by |
| inverse_transform |
Applies an inverse transformation to a vector. |
| inverse_transformation |
Gets the inverse transformation applicable by |
| inverse_translate |
Applies an inverse translation to a point. |
| inverse_translation |
Gets the inverse translation applicable by |
| is_zero |
Tests is a value is iqual to zero. |
| max |
Same as |
| mean |
Computes the mean of a set of observations. |
| min |
Same as |
| new_identity |
Construct the identity matrix for a given dimension |
| norm |
Computes the L2 norm of a vector. |
| norm_squared |
Computes the squared L2 norm of a vector. |
| normalize |
Gets the normalized version of a vector. |
| one |
Create a one-valued value. |
| origin |
Returns the trivial origin of an affine space. |
| orthonormal_subspace_basis |
Computes the basis of the orthonormal subspace of a given vector. |
| outer |
Computes the outer product of two vectors. |
| 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 |
| prepend_rotation |
Pre-applies the rotation |
| qr |
QR decomposition using Householder reflections. |
| repeat |
Create an object by repeating a value. |
| rotate |
Applies a rotation to a vector. |
| rotation |
Gets the rotation applicable by |
| rotation_between |
Computes the rotation needed to transform |
| sample_sphere |
Samples the unit sphere living on the dimension as the samples types. |
| shape |
Gets the indexable range of an object. |
| sup |
Returns the supremum of |
| to_homogeneous |
Converts a matrix or vector to homogeneous coordinates. |
| to_rotation_matrix |
Builds a rotation matrix from |
| transform |
Applies a transformation to a vector. |
| transformation |
Gets the transformation applicable by |
| translate |
Applies a translation to a point. |
| translation |
Gets the translation applicable by |
| transpose |
Gets a transposed copy of a matrix. |
| try_normalize |
Gets the normalized version of a vector or |
| zero |
Create a zero-valued value. |
Type Definitions
| UnitQuaternion |
A unit quaternions. May be used to represent a rotation. |