dimforge / nalgebra

Linear algebra library for Rust.
https://nalgebra.org
Apache License 2.0
3.87k stars 463 forks source link

Can't Multiply Two Vectors. #768

Closed HackerWithoutACause closed 3 years ago

HackerWithoutACause commented 3 years ago

I have to following code:

Vector2::new(1.0, 1.0) * Vector2::new(1.0, 1.0)

when I try to compile it get the error:

the trait `rapier3d::nalgebra::constraint::DimEq<rapier3d::nalgebra::U1, rapier3d::nalgebra::U2>` is not implemented for `rapier3d::nalgebra::constraint::ShapeConstraint`

I am using rapier3d version 0.1.5 and importing nalgebra from there.

sebcrozet commented 3 years ago

For component-wise multiplication, you need to use v1.component_mul(&v2). The * operator can only be used for multiplications that make sense from a linear algebra point of view. Here you are trying to multiply a 2x1 matrix (which is a 2D vector) to another 2x1 matrix. This is why you are getting a dimension mismatch error.

HackerWithoutACause commented 3 years ago

Thank you.