Expand description
§nalgebra 代数
nalgebra is a linear algebra library written for Rust targeting:
nalgebra 是为 Rust 编写的线性代数库:
- 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.
您需要 rust 编译器的最新稳定版和官方软件包管理器:cargo.
Simply add the following to your Cargo.toml
file:
只需在 Cargo.toml
文件中添加以下内容即可:
[dependencies]
// TODO: replace the * by the latest version.
nalgebra = "*"
Most useful functionalities of nalgebra are grouped in the root module nalgebra::
.
nalgebra 的大部分有用功能都集中在根模块 nalgebra::
中。
However, the recommended way to use nalgebra is to import types and traits
explicitly, and call free-functions using the na::
prefix:
不过,使用 nalgebra 的推荐方法是显式导入类型和性状,并使用 na::
前缀调用自由函数:
#[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:
nalgebra 是一个通用、低维、线性代数库,并为计算机图形学和物理学提供了一套优化工具。这些功能包括
- 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.
单一可参数化类型Matrix
用于向量、(正方形或矩形)矩阵和切片,其尺寸在编译时(使用类型级整数)或运行时已知。 - 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
.
低维矩阵和向量的方便别名:Vector1
到Vector6
和Matrix1x1
到Matrix6x6
、包括矩形矩阵,如Matrix2x5
。 - Points sizes known at compile time, and convenience aliases:
Point1
toPoint6
.
编译时已知的点尺寸,以及方便的别名:Point1
到Point6
。 - Translation (seen as a transformation that composes by multiplication):
Translation2
,Translation3
.
翻译(被视为通过乘法合成的转换):Translation2
,Translation3
. - Rotation matrices:
Rotation2
,Rotation3
.
旋转矩阵:Rotation2
,Rotation3
. - Quaternions:
Quaternion
,UnitQuaternion
(for 3D rotation).
四元数Quaternion
,UnitQuaternion
(用于 3D 旋转)。 - Unit complex numbers can be used for 2D rotation:
UnitComplex
.
单位复数可用于二维旋转:UnitComplex
. - Algebraic entities with a norm equal to one:
Unit<T>
, e.g.,Unit<Vector3<f32>>
.
规范等于 1 的代数实体:Unit<T>
, 例如,Unit<Vector3<f32>>
. - Isometries (translation ⨯ rotation):
Isometry2
,Isometry3
等距(平移 ⨯ 旋转):Isometry2
,Isometry3
- Similarity transformations (translation ⨯ rotation ⨯ uniform scale):
Similarity2
,Similarity3
.
相似性变换(平移 ⨯ 旋转 ⨯ 均匀缩放):Similarity2
,Similarity3
. - Affine transformations stored as a homogeneous matrix:
Affine2
,Affine3
.
以均质矩阵形式存储的仿射变换:Affine2
,Affine3
. - Projective (i.e. invertible) transformations stored as a homogeneous matrix:
Projective2
,Projective3
.
以同质矩阵存储的投影(即可逆)变换:Projective2
,Projective3
. - General transformations that does not have to be invertible, stored as a homogeneous matrix:
Transform2
,Transform3
.
不一定是可逆的一般变换,存储为同质矩阵:Transform2
,Transform3
. - 3D projections for computer graphics:
Perspective3
,Orthographic3
.
用于计算机制图的 3D 投影:Perspective3
,Orthographic3
. - Matrix factorizations:
Cholesky
,QR
,LU
,FullPivLU
,SVD
,Schur
,Hessenberg
,SymmetricEigen
.
矩阵因式分解: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 模块§
- [Reexported at the root of this crate.] Data structures for vector and matrix computations.
[用于向量和矩阵计算的数据结构。 - Various tools useful for testing/debugging/benchmarking.
各种有用的测试/调试/基准测试工具。 - [Reexported at the root of this crate.] Data structures for points and usual transformations (rotations, isometries, etc.)
[点和常规变换(旋转、等距等)的数据结构) - Parsers for various matrix formats.
各种矩阵格式的解析器 - [Reexported at the root of this crate.] Factorization of real matrices.
[实矩阵的因式分解。 proptest
-related features fornalgebra
data structures.针对
相关功能。代数
数据结构的测试- 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 new matrix by stacking matrices in a block matrix.
通过在分块矩阵中堆叠矩阵来构建新矩阵。 - Construct a fixed-size column vector directly from data.
直接从数据中构建固定大小的列向量。
Structs 结构§
- A complex number in Cartesian form.
笛卡尔形式的复数。
Traits 特质§
- Trait alias for
Add
andAddAssign
with result of typeSelf
.
用于Add
和AddAssign
的特质 alias 的类型Self
的结果。 - Trait alias for
Div
andDivAssign
with result of typeSelf
.
用于Div
和DivAssign
的特质 alias 的类型Self
的结果。 - Trait alias for
Mul
andMulAssign
with result of typeSelf
.
用于Mul
和MulAssign
的特质 别名,结果类型为Self
。 - Trait alias for
Sub
andSubAssign
with result of typeSelf
.
用于Sub
和SubAssign
的特质 alias 的类型Self
的结果。 - Trait shared by all complex fields and its subfields (like real numbers).
所有复数领域及其子领域(如实数)的共同特征。 - Trait implemented by fields, i.e., complex numbers and floats.
字段实现的特征,即复数和浮点数。 - Trait shared by all reals.
所有真人的共同特征。 - Lane-wise generalization of
bool
for SIMD booleans.
针对 SIMD 布尔运算的bool
的车道泛化。 - Lane-wise generalisation of
ComplexField
for SIMD complex fields.
针对 SIMD 复数字段的ComplexField
的车道广义化。 - Lane-wise generalization of the standard
PartialOrd
for SIMD values.
针对 SIMD 值的标准PartialOrd
的车道广义化。 - Lanewise generalization of
RealField
for SIMD reals.
用于 SIMD 实数的RealField
的 Lanewise 通用化。 - Base trait for every SIMD types.
每种 SIMD 类型的基本特性。
Functions 功能§
- The absolute value of
a
.a
的绝对值。 - The center of two points.
两点的中心。 - Returns a reference to the input value clamped to the interval
[min, max]
.
返回箝位在[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.
谨慎使用!与try_convert()
相同,但不进行任何属性检查。 - Use with care! Same as
try_convert()
but without any property checks.
谨慎使用!与try_convert()
相同,但不进行任何属性检查。 - The distance between two points.
两点之间的距离。 - The squared distance between two points.
两点间距离的平方。 - Returns the infimum of
a
andb
.
返回a
和b
的最小值。 - Returns simultaneously the infimum and supremum of
a
andb
.
同时返回a
和b
的下确值和上确值。 - Indicates if
try_convert()
will succeed without actually performing the conversion.
指示try_convert()
是否会成功,而不实际执行转换。 - Same as
cmp::max
.
与cmp::max
相同。 - Same as
cmp::min
.
与cmp::min
相同。 - Gets the multiplicative identity element.
获取乘法同位元素。 - Clamp
value
betweenmin
andmax
. ReturnsNone
ifvalue
is not comparable tomin
ormax
.
将value
夹在min
和max
之间。如果value
与min
或max
不匹配,则返回None
。 - Compare
a
andb
using a partial ordering relation.
使用部分排序关系对a
和b
进行比较。 - Returns
true
iffa
andb
are comparable anda >= b
.
如果a
和b
具有可比性,并且a >= b
返回true
。 - Returns
true
iffa
andb
are comparable anda > b
.
如果a
和b
具有可比性,并且a > b
返回true
。 - Returns
true
iffa
andb
are comparable anda <= b
.
如果a
和b
具有可比性,并且a <= b
返回true
。 - Returns
true
iffa
andb
are comparable anda < b
.
如果a
和b
具有可比性并且a < b
返回true
。 - Return the maximum of
a
andb
if they are comparable.
如果a
和b
具有可比性,则返回它们的最大值。 - Return the minimum of
a
andb
if they are comparable.
如果a
和b
具有可比性,则返回它们的最小值。 - Sorts two values in increasing order using a partial ordering.
使用部分排序将两个值按递增顺序排序。 - Returns the supremum of
a
andb
.
返回a
和b
的上数。 - Attempts to convert an object to a more specific one.
尝试将对象转换为更具体的对象。 - Attempts to convert an object to a more specific one.
尝试将对象转换为更具体的对象。 - Wraps
val
into the range[min, max]
using modular arithmetics.
使用模块化算术将val
包入范围[min, max]
中。 - Gets the additive identity element.
获取加法标识元素。