| 1 |
extern crate nalgebra as na; |
| 2 |
|
| 3 |
use na::{Point3, Vector3, Vector4}; |
| 4 |
|
| 5 |
fn main() { |
| 6 |
// Build using components directly. |
| 7 |
let p0 = Point3::new(2.0, 3.0, 4.0); |
| 8 |
|
| 9 |
// Build from a coordinates vector. |
| 10 |
let coords = Vector3::new(2.0, 3.0, 4.0); |
| 11 |
let p1 = Point3::from(coords); |
| 12 |
|
| 13 |
// Build by translating the origin. |
| 14 |
let translation = Vector3::new(2.0, 3.0, 4.0); |
| 15 |
let p2 = Point3::origin() + translation; |
| 16 |
|
| 17 |
// Build from homogeneous coordinates. The last component of the |
| 18 |
// vector will be removed and all other components divided by 10.0. |
| 19 |
let homogeneous_coords = Vector4::new(20.0, 30.0, 40.0, 10.0); |
| 20 |
let p3 = Point3::from_homogeneous(homogeneous_coords); |
| 21 |
|
| 22 |
assert_eq!(p0, p1); |
| 23 |
assert_eq!(p0, p2); |
| 24 |
assert_eq!(p0, p3.unwrap()); |
| 25 |
} |