nalgebra/examples/transform_vector_point.rs

21 lines
712 B
Rust
Raw Permalink Normal View History

2017-02-13 01:17:09 +08:00
#[macro_use]
extern crate approx;
extern crate nalgebra as na;
2018-02-02 19:26:35 +08:00
use na::{Isometry2, Point2, Vector2};
2018-10-22 13:00:10 +08:00
use std::f32;
2017-02-13 01:17:09 +08:00
fn main() {
let t = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI);
let p = Point2::new(1.0, 0.0); // Will be affected by te rotation and the translation.
2018-02-02 19:26:35 +08:00
let v = Vector2::x(); // Will *not* be affected by the translation.
2017-02-13 01:17:09 +08:00
assert_relative_eq!(t * p, Point2::new(-1.0 + 1.0, 1.0));
// ^^^^ │ ^^^^^^^^
// rotated │ translated
assert_relative_eq!(t * v, Vector2::new(-1.0, 0.0));
// ^^^^^
// rotated only
}