2017-02-13 01:17:09 +08:00
|
|
|
extern crate nalgebra as na;
|
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
use na::{Scalar, Vector3};
|
2020-03-22 06:44:24 +08:00
|
|
|
use simba::scalar::RealField;
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2021-04-11 17:00:38 +08:00
|
|
|
fn print_vector<T: Scalar>(m: &Vector3<T>) {
|
2018-02-02 19:26:35 +08:00
|
|
|
println!("{:?}", m)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2021-04-11 17:00:38 +08:00
|
|
|
fn print_norm<T: RealField>(v: &Vector3<T>) {
|
2018-02-02 19:26:35 +08:00
|
|
|
// NOTE: alternatively, nalgebra already defines `v.norm()`.
|
|
|
|
let norm = v.dot(v).sqrt();
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2021-04-11 17:00:38 +08:00
|
|
|
// The RealField bound implies that T is Display so we can
|
2018-02-02 19:26:35 +08:00
|
|
|
// use "{}" instead of "{:?}" for the format string.
|
|
|
|
println!("{}", norm)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2018-02-02 19:26:35 +08:00
|
|
|
let v1 = Vector3::new(1, 2, 3);
|
|
|
|
let v2 = Vector3::new(1.0, 2.0, 3.0);
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
print_vector(&v1);
|
|
|
|
print_norm(&v2);
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|