2014-01-14 16:52:18 +08:00
|
|
|
# nalgebra
|
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
**nalgebra** is a linear algebra library written for Rust targeting:
|
|
|
|
|
|
|
|
* general-purpose linear algebra (still misses a lot of features…).
|
|
|
|
* real time computer graphics.
|
|
|
|
* real time computer physics.
|
|
|
|
|
2014-06-10 03:48:24 +08:00
|
|
|
An on-line version of this documentation is available [here](http://nalgebra.org).
|
2013-10-08 08:10:35 +08:00
|
|
|
|
2013-10-07 01:32:31 +08:00
|
|
|
## Using **nalgebra**
|
2013-10-06 22:54:09 +08:00
|
|
|
All the functionalities of **nalgebra** are grouped in one place: the `na` module.
|
2013-10-14 17:22:38 +08:00
|
|
|
This module re-exports everything and includes free functions for all traits methods doing
|
|
|
|
out-of-place modifications.
|
2013-10-06 22:54:09 +08:00
|
|
|
|
2014-01-14 16:52:18 +08:00
|
|
|
* You can import the whole prelude using:
|
2013-10-06 22:54:09 +08:00
|
|
|
|
2014-01-19 23:16:12 +08:00
|
|
|
```
|
2013-10-07 01:36:59 +08:00
|
|
|
use nalgebra::na::*;
|
2013-10-06 22:54:09 +08:00
|
|
|
```
|
|
|
|
|
2014-01-14 16:52:18 +08:00
|
|
|
The preferred way to use **nalgebra** is to import types and traits explicitly, and call
|
2013-10-14 17:22:38 +08:00
|
|
|
free-functions using the `na::` prefix:
|
|
|
|
|
|
|
|
```.rust
|
2014-06-08 08:07:03 +08:00
|
|
|
extern crate nalgebra;
|
2013-10-14 17:22:38 +08:00
|
|
|
use nalgebra::na::{Vec3, Rot3, Rotation};
|
|
|
|
use nalgebra::na;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a = Vec3::new(1.0f64, 1.0, 1.0);
|
|
|
|
let mut b = Rot3::new(na::zero());
|
|
|
|
|
|
|
|
b.append_rotation(&a);
|
|
|
|
|
2014-01-14 16:52:18 +08:00
|
|
|
assert!(na::approx_eq(&na::rotation(&b), &a));
|
2013-10-14 17:22:38 +08:00
|
|
|
}
|
|
|
|
```
|
2013-06-13 22:06:05 +08:00
|
|
|
|
2013-09-28 06:12:18 +08:00
|
|
|
## Features
|
|
|
|
**nalgebra** is meant to be a general-purpose linear algebra library (but is very far from that…),
|
|
|
|
and keeps an optimized set of tools for computational graphics and physics. Those features include:
|
2013-06-13 22:06:05 +08:00
|
|
|
|
2013-10-08 07:22:56 +08:00
|
|
|
* Vectors with static sizes: `Vec0`, `Vec1`, `Vec2`, `Vec3`, `Vec4`, `Vec5`, `Vec6`.
|
|
|
|
* Square matrices with static sizes: `Mat1`, `Mat2`, `Mat3`, `Mat4`, `Mat5`, `Mat6 `.
|
2013-10-06 22:54:09 +08:00
|
|
|
* Rotation matrices: `Rot2`, `Rot3`, `Rot4`.
|
|
|
|
* Isometries: `Iso2`, `Iso3`, `Iso4`.
|
2013-09-28 06:15:44 +08:00
|
|
|
* Dynamically sized vector: `DVec`.
|
|
|
|
* Dynamically sized (square or rectangular) matrix: `DMat`.
|
2013-10-07 01:32:31 +08:00
|
|
|
* A few methods for data analysis: `Cov`, `Mean`.
|
2014-05-17 01:55:20 +08:00
|
|
|
* Some matrix factorization algorithms: QR decomposition, ...
|
2013-10-07 01:20:39 +08:00
|
|
|
* Almost one trait per functionality: useful for generic programming.
|
2013-10-07 01:32:31 +08:00
|
|
|
* Operator overloading using the double trait dispatch
|
|
|
|
[trick](http://smallcultfollowing.com/babysteps/blog/2012/10/04/refining-traits-slash-impls/).
|
2013-10-08 07:22:56 +08:00
|
|
|
For example, the following works:
|
2013-09-28 06:12:18 +08:00
|
|
|
|
|
|
|
```rust
|
2014-06-08 08:07:03 +08:00
|
|
|
extern crate nalgebra;
|
2013-10-06 22:54:09 +08:00
|
|
|
use nalgebra::na::{Vec3, Mat3};
|
2013-10-08 07:59:15 +08:00
|
|
|
use nalgebra::na;
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
fn main() {
|
2013-10-08 07:59:15 +08:00
|
|
|
let v: Vec3<f64> = na::zero();
|
|
|
|
let m: Mat3<f64> = na::one();
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
let _ = m * v; // matrix-vector multiplication.
|
|
|
|
let _ = v * m; // vector-matrix multiplication.
|
|
|
|
let _ = m * m; // matrix-matrix multiplication.
|
|
|
|
let _ = v * 2.0; // vector-scalar multiplication.
|
|
|
|
}
|
2013-09-28 06:12:18 +08:00
|
|
|
```
|
2013-05-15 05:19:58 +08:00
|
|
|
|
2013-06-13 22:06:05 +08:00
|
|
|
## Compilation
|
2014-07-14 23:56:35 +08:00
|
|
|
You will need the last nightly build of the [rust compiler](http://www.rust-lang.org)
|
|
|
|
and the official package manager: [cargo](https://github.com/rust-lang/cargo).
|
2013-05-15 03:20:52 +08:00
|
|
|
|
2014-07-14 23:56:35 +08:00
|
|
|
Simply add the following to your `Cargo.toml` file:
|
2013-09-28 06:12:18 +08:00
|
|
|
|
2014-01-19 23:16:12 +08:00
|
|
|
```
|
2014-07-14 23:56:35 +08:00
|
|
|
[dependencies.nalgebra]
|
|
|
|
git = "https://github.com/sebcrozet/nalgebra"
|
2013-10-06 22:54:09 +08:00
|
|
|
```
|
2013-10-07 01:32:31 +08:00
|
|
|
|
2014-07-14 23:56:35 +08:00
|
|
|
|
2013-10-07 01:32:31 +08:00
|
|
|
## **nalgebra** in use
|
|
|
|
Here are some projects using **nalgebra**.
|
|
|
|
Feel free to add your project to this list if you happen to use **nalgebra**!
|
|
|
|
|
2014-06-10 03:48:24 +08:00
|
|
|
* [nphysics](http://nphysics-dev.org): a real-time physics engine.
|
|
|
|
* [ncollide](http://ncollide.org): a collision detection library.
|
2014-07-14 23:56:35 +08:00
|
|
|
* [kiss3d](http://kiss3d.org): a minimalistic graphics engine.
|