| 1 |
extern crate nalgebra as na; |
| 2 |
|
| 3 |
use na::{Matrix4, Point3, Vector3, Vector4}; |
| 4 |
|
| 5 |
fn main() { |
| 6 |
let mut m = Matrix4::new_rotation_wrt_point(Vector3::x() * 1.57, Point3::new(1.0, 2.0, 1.0)); |
| 7 |
m.append_scaling_mut(2.0); |
| 8 |
|
| 9 |
let point1 = Point3::new(2.0, 3.0, 4.0); |
| 10 |
let homogeneous_point2 = Vector4::new(2.0, 3.0, 4.0, 1.0); |
| 11 |
|
| 12 |
// First option: use the dedicated `.transform_point(...)` method. |
| 13 |
let transformed_point1 = m.transform_point(&point1); |
| 14 |
// Second option: use the homogeneous coordinates of the point. |
| 15 |
let transformed_homogeneous_point2 = m * homogeneous_point2; |
| 16 |
|
| 17 |
// Recover the 3D point from its 4D homogeneous coordinates. |
| 18 |
let transformed_point2 = Point3::from_homogeneous(transformed_homogeneous_point2); |
| 19 |
|
| 20 |
// Check that transforming the 3D point with the `.transform_point` method is |
| 21 |
// indeed equivalent to multiplying its 4D homogeneous coordinates by the 4x4 |
| 22 |
// matrix. |
| 23 |
assert_eq!(transformed_point1, transformed_point2.unwrap()); |
| 24 |
} |