Crate oxygengine_physics_2d::prelude::nalgebra
source · 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
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.
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
andVecStorage
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
orSimilarity
. - Trait alias for
Add
andAddAssign
with result of typeSelf
. - Trait alias for
Div
andDivAssign
with result of typeSelf
. - Trait alias for
Mul
andMulAssign
with result of typeSelf
. - Trait alias for
Sub
andSubAssign
with result of typeSelf
. - 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 fromU1
. - 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 specificTransform
category thanOther
. - Indicates that
Self
is a more generalTransform
category thanOther
. - 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 categoriesSelf
andOther
.
Functions
- absDeprecatedThe 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.
- infDeprecatedReturns the infimum of
a
andb
. - inf_supDeprecatedReturns simultaneously the infimum and supremum of
a
andb
. - 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
betweenmin
andmax
. ReturnsNone
ifvalue
is not comparable tomin
ormax
. - Compare
a
andb
using a partial ordering relation. - Returns
true
iffa
andb
are comparable anda >= b
. - Returns
true
iffa
andb
are comparable anda > b
. - Returns
true
iffa
andb
are comparable anda <= b
. - Returns
true
iffa
andb
are comparable anda < b
. - Return the maximum of
a
andb
if they are comparable. - Return the minimum of
a
andb
if they are comparable. - Sorts two values in increasing order using a partial ordering.
- supDeprecatedReturns the supremum of
a
andb
. - 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 ofmatrix
. - 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
- A 2D affine transformation. Stored as a homogeneous 3x3 matrix.
- A 3D affine transformation. Stored as a homogeneous 4x4 matrix.
- The column-stride of the owned data storage for a buffer of dimension
(R, C)
. - A column compressed sparse vector.
- A dynamically sized column-major matrix.
- A column-major matrix slice dynamic numbers of rows and columns.
- A column-major matrix slice dynamic numbers of rows and columns.
- A dynamically sized column vector.
- A column vector slice dynamic numbers of rows and columns.
- A column vector slice dynamic numbers of rows and columns.
- A 2-dimensional direct isometry using a unit complex number for its rotational part.
- A 3-dimensional direct isometry using a unit quaternion for its rotational part.
- A 2-dimensional direct isometry using a rotation matrix for its rotational part.
- A 3-dimensional direct isometry using a rotation matrix for its rotational part.
- A stack-allocated, column-major, 1x1 square matrix.
- A stack-allocated, column-major, 1x2 matrix.
- A stack-allocated, column-major, 1x3 matrix.
- A stack-allocated, column-major, 1x4 matrix.
- A stack-allocated, column-major, 1x5 matrix.
- A stack-allocated, column-major, 1x6 matrix.
- A heap-allocated, row-major, matrix with 1 rows and a dynamic number of columns.
- A stack-allocated, column-major, 2x2 square matrix.
- A stack-allocated, column-major, 2x1 matrix.
- A stack-allocated, column-major, 2x3 matrix.
- A stack-allocated, column-major, 2x4 matrix.
- A stack-allocated, column-major, 2x5 matrix.
- A stack-allocated, column-major, 2x6 matrix.
- A heap-allocated, row-major, matrix with 2 rows and a dynamic number of columns.
- A stack-allocated, column-major, 3x3 square matrix.
- A stack-allocated, column-major, 3x1 matrix.
- A stack-allocated, column-major, 3x2 matrix.
- A stack-allocated, column-major, 3x4 matrix.
- A stack-allocated, column-major, 3x5 matrix.
- A stack-allocated, column-major, 3x6 matrix.
- A heap-allocated, row-major, matrix with 3 rows and a dynamic number of columns.
- A stack-allocated, column-major, 4x4 square matrix.
- A stack-allocated, column-major, 4x1 matrix.
- A stack-allocated, column-major, 4x2 matrix.
- A stack-allocated, column-major, 4x3 matrix.
- A stack-allocated, column-major, 4x5 matrix.
- A stack-allocated, column-major, 4x6 matrix.
- A heap-allocated, row-major, matrix with 4 rows and a dynamic number of columns.
- A stack-allocated, column-major, 5x5 square matrix.
- A stack-allocated, column-major, 5x1 matrix.
- A stack-allocated, column-major, 5x2 matrix.
- A stack-allocated, column-major, 5x3 matrix.
- A stack-allocated, column-major, 5x4 matrix.
- A stack-allocated, column-major, 5x6 matrix.
- A heap-allocated, row-major, matrix with 5 rows and a dynamic number of columns.
- A stack-allocated, column-major, 6x6 square matrix.
- A stack-allocated, column-major, 6x1 matrix.
- A stack-allocated, column-major, 6x2 matrix.
- A stack-allocated, column-major, 6x3 matrix.
- A stack-allocated, column-major, 6x4 matrix.
- A stack-allocated, column-major, 6x5 matrix.
- A heap-allocated, row-major, matrix with 6 rows and a dynamic number of columns.
- The type of the result of a matrix cross product.
- MatrixMNDeprecatedAn owned matrix column-major matrix with
R
rows andC
columns. - MatrixNDeprecatedAn owned matrix column-major matrix with
D
columns. - A matrix slice.
- A column-major 1x1 matrix slice.
- A column-major 1x2 matrix slice.
- A column-major 1x3 matrix slice.
- A column-major 1x4 matrix slice.
- A column-major 1x5 matrix slice.
- A column-major 1x6 matrix slice.
- A column-major matrix slice with 1 row and a number of columns chosen at runtime.
- A column-major 2x2 matrix slice.
- A column-major 2x1 matrix slice.
- A column-major 2x3 matrix slice.
- A column-major 2x4 matrix slice.
- A column-major 2x5 matrix slice.
- A column-major 2x6 matrix slice.
- A column-major matrix slice with 2 rows and a number of columns chosen at runtime.
- A column-major 3x3 matrix slice.
- A column-major 3x1 matrix slice.
- A column-major 3x2 matrix slice.
- A column-major 3x4 matrix slice.
- A column-major 3x5 matrix slice.
- A column-major 3x6 matrix slice.
- A column-major matrix slice with 3 rows and a number of columns chosen at runtime.
- A column-major 4x4 matrix slice.
- A column-major 4x1 matrix slice.
- A column-major 4x2 matrix slice.
- A column-major 4x3 matrix slice.
- A column-major 4x5 matrix slice.
- A column-major 4x6 matrix slice.
- A column-major matrix slice with 4 rows and a number of columns chosen at runtime.
- A column-major 5x5 matrix slice.
- A column-major 5x1 matrix slice.
- A column-major 5x2 matrix slice.
- A column-major 5x3 matrix slice.
- A column-major 5x4 matrix slice.
- A column-major 5x6 matrix slice.
- A column-major matrix slice with 5 rows and a number of columns chosen at runtime.
- A column-major 6x6 matrix slice.
- A column-major 6x1 matrix slice.
- A column-major 6x2 matrix slice.
- A column-major 6x3 matrix slice.
- A column-major 6x4 matrix slice.
- A column-major 6x5 matrix slice.
- A column-major matrix slice with 6 rows and a number of columns chosen at runtime.
- A mutable matrix slice.
- A column-major 1x1 matrix slice.
- A column-major 1x2 matrix slice.
- A column-major 1x3 matrix slice.
- A column-major 1x4 matrix slice.
- A column-major 1x5 matrix slice.
- A column-major 1x6 matrix slice.
- A column-major matrix slice with 1 row and a number of columns chosen at runtime.
- A column-major 2x2 matrix slice.
- A column-major 2x1 matrix slice.
- A column-major 2x3 matrix slice.
- A column-major 2x4 matrix slice.
- A column-major 2x5 matrix slice.
- A column-major 2x6 matrix slice.
- A column-major matrix slice with 2 rows and a number of columns chosen at runtime.
- A column-major 3x3 matrix slice.
- A column-major 3x1 matrix slice.
- A column-major 3x2 matrix slice.
- A column-major 3x4 matrix slice.
- A column-major 3x5 matrix slice.
- A column-major 3x6 matrix slice.
- A column-major matrix slice with 3 rows and a number of columns chosen at runtime.
- A column-major 4x4 matrix slice.
- A column-major 4x1 matrix slice.
- A column-major 4x2 matrix slice.
- A column-major 4x3 matrix slice.
- A column-major 4x5 matrix slice.
- A column-major 4x6 matrix slice.
- A column-major matrix slice with 4 rows and a number of columns chosen at runtime.
- A column-major 5x5 matrix slice.
- A column-major 5x1 matrix slice.
- A column-major 5x2 matrix slice.
- A column-major 5x3 matrix slice.
- A column-major 5x4 matrix slice.
- A column-major 5x6 matrix slice.
- A column-major matrix slice with 5 rows and a number of columns chosen at runtime.
- A column-major 6x6 matrix slice.
- A column-major 6x1 matrix slice.
- A column-major 6x2 matrix slice.
- A column-major 6x3 matrix slice.
- A column-major 6x4 matrix slice.
- A column-major 6x5 matrix slice.
- A column-major matrix slice with 6 rows and a number of columns chosen at runtime.
- A column-major matrix slice with
R
rows andC
columns. - A column-major matrix slice with
D
rows and columns. - A column-major matrix slice with a number of rows chosen at runtime and 1 column.
- A column-major matrix slice with a number of rows chosen at runtime and 2 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 3 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 4 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 5 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 6 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 1 column.
- A column-major matrix slice with a number of rows chosen at runtime and 2 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 3 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 4 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 5 columns.
- A column-major matrix slice with a number of rows chosen at runtime and 6 columns.
- The type of the result of a matrix sum.
- MatrixVecDeprecatedRenamed to
VecStorage
. - A heap-allocated, column-major, matrix with a dynamic number of rows and 1 columns.
- A heap-allocated, column-major, matrix with a dynamic number of rows and 2 columns.
- A heap-allocated, column-major, matrix with a dynamic number of rows and 3 columns.
- A heap-allocated, column-major, matrix with a dynamic number of rows and 4 columns.
- A heap-allocated, column-major, matrix with a dynamic number of rows and 5 columns.
- A heap-allocated, column-major, matrix with a dynamic number of rows and 6 columns.
- An owned matrix column-major matrix with
R
rows andC
columns. - An owned D-dimensional column vector.
- The owned data storage that can be allocated from
S
. - The owned data storage that can be allocated from
S
. - A point with
D
elements. - A statically sized 1-dimensional column point.
- A statically sized 2-dimensional column point.
- A statically sized 3-dimensional column point.
- A statically sized 4-dimensional column point.
- A statically sized 5-dimensional column point.
- A statically sized 6-dimensional column point.
- An invertible 2D general transformation. Stored as a homogeneous 3x3 matrix.
- An invertible 3D general transformation. Stored as a homogeneous 4x4 matrix.
- The row-stride of the owned data storage for a buffer of dimension
(R, C)
. - A 1-dimensional reflection.
- A 2-dimensional reflection.
- A 3-dimensional reflection.
- A 4-dimensional reflection.
- A 5-dimensional reflection.
- A 6-dimensional reflection.
- A 2-dimensional rotation matrix.
- A 3-dimensional rotation matrix.
- A dynamically sized row vector.
- An owned D-dimensional row vector.
- A statically sized D-dimensional row vector.
- A matrix with one row and
D
columns . - A stack-allocated, 1-dimensional row vector.
- A stack-allocated, 2-dimensional row vector.
- A stack-allocated, 3-dimensional row vector.
- A stack-allocated, 4-dimensional row vector.
- A stack-allocated, 5-dimensional row vector.
- A stack-allocated, 6-dimensional row vector.
- A statically sized column-major matrix with
R
rows andC
columns. - A column-major matrix slice with dimensions known at compile-time.
- A column-major matrix slice with dimensions known at compile-time.
- A statically sized D-dimensional column vector.
- A column vector slice with dimensions known at compile-time.
- A column vector slice with dimensions known at compile-time.
- The data storage for the sum of two matrices with dimensions
(R1, C1)
and(R2, C2)
. - A 2-dimensional similarity.
- A 3-dimensional similarity.
- A 2-dimensional similarity using a rotation matrix for its rotation part.
- A 3-dimensional similarity using a rotation matrix for its rotation part.
- A square matrix.
- A 2D general transformation that may not be invertible. Stored as a homogeneous 3x3 matrix.
- A 3D general transformation that may not be inversible. Stored as a homogeneous 4x4 matrix.
- A 1-dimensional translation.
- A 2-dimensional translation.
- A 3-dimensional translation.
- A 4-dimensional translation.
- A 5-dimensional translation.
- A 6-dimensional translation.
- An owned matrix with uninitialized data.
- An owned matrix with uninitialized data.
- A 2D rotation represented as a complex number with magnitude 1.
- A unit quaternions. May be used to represent a rotation followed by a translation.
- A unit quaternions. May be used to represent a rotation.
- A stack-allocated, 1-dimensional unit vector.
- A stack-allocated, 2-dimensional unit vector.
- A stack-allocated, 3-dimensional unit vector.
- A stack-allocated, 4-dimensional unit vector.
- A stack-allocated, 5-dimensional unit vector.
- A stack-allocated, 6-dimensional unit vector.
- A matrix with one column and
D
rows. - A stack-allocated, 1-dimensional column vector.
- A stack-allocated, 2-dimensional column vector.
- A stack-allocated, 3-dimensional column vector.
- A stack-allocated, 4-dimensional column vector.
- A stack-allocated, 5-dimensional column vector.
- A stack-allocated, 6-dimensional column vector.
- VectorNDeprecatedAn owned matrix column-major matrix with
R
rows andC
columns. - A column vector slice with dimensions known at compile-time.
- A 1D column vector slice.
- A 2D column vector slice.
- A 3D column vector slice.
- A 4D column vector slice.
- A 5D column vector slice.
- A 6D column vector slice.
- A column vector slice with dimensions known at compile-time.
- A 1D column vector slice.
- A 2D column vector slice.
- A 3D column vector slice.
- A 4D column vector slice.
- A 5D column vector slice.
- A 6D column vector slice.
- The type of the result of a matrix sum.