-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: working with nalgebra #65
Comments
I would recommend that you read through the hard sphere section of dimensioned-examples. It covers using dimensioned with vectors -- if you find anything confusing or lacking there, please open a ticket. I would be happy to try to make it more clear! It is likely that you will have more luck by placing units on the outside of That said, you can make that code compile by adding some trait bounds. The compiler tells you you need This code compiles: fn dim_vector3<L, R>(unit_const: L, arr: [R; 3]) -> na::Vector3<dim::typenum::Prod<L, R>>
where
L: std::ops::Mul<R> + Copy,
R: Copy,
dim::typenum::Prod<L, R>: na::Scalar,
{
na::Vector3::new(
unit_const * arr[0],
unit_const * arr[1],
unit_const * arr[2],
)
} |
And, for fun, you can clean it up a bit with the #[macro_use] extern crate typenum;
fn dim_vector3<L, R>(unit_const: L, arr: [R; 3]) -> na::Vector3<op!(L*R)>
where
L: std::ops::Mul<R> + Copy,
R: Copy,
op!(L*R): na::Scalar,
{
na::Vector3::new(
unit_const * arr[0],
unit_const * arr[1],
unit_const * arr[2],
)
} This reminds me that I need to make that macro 2018 edition compatible.... |
One of the things that makes combining dimensioned and nalgebra hard is that there are cases where the units of matrices are non-homogeneous. For example, if you have a 2D
I've struggled in the past trying to put units inside nalgebra types, like use dimensioned::si;
use nalgebra as na;
fn main() {
let position = si::Meter::new(na::Point2::new(2.0, 0.0));
let velocity = si::MeterPerSecond::new(na::Vector2::new(3.0, 1.0));
let time = 12.0 * si::S;
let rotation = si::Unitless::new(na::Rotation2::new(std::f64::consts::FRAC_PI_2));
println!("Position: {}", position);
println!("Velocity: {}", velocity);
println!("Time: {}", time);
println!("Rotation: {}", rotation);
println!("End position: {}", position + rotation * velocity * time);
} |
Thank you both! |
BTW if you just want a 3D vector type that works well with dimensioned, you could try https://crates.io/crates/vector3d Which I created for that purpose. |
That would be great! |
Thanks a lot for the guidance on using dimensioned with nalgebra. Did someone figure out how to use a "Isometry3" with dimensioned? I think the challenge here is that it consists of a rotation and a translation so simply wrapping it in sth like "Meter" breaks as soon as i want to multiply the Isometry with sth else... |
I feel so inept at this. I appreciate the help.
I'm trying to create a helper function that will take an array slice and create a dimensioned
nalgebra::Vector3
out of it... but i'm failing. This is what I've got so far:any insight appreciated :)
The text was updated successfully, but these errors were encountered: