-
-
Notifications
You must be signed in to change notification settings - Fork 121
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
extensions for 2D convex shape #31
Conversation
@@ -62,6 +62,21 @@ fn tetrahedron_unit_inertia_tensor_wrt_point<P, I>(point: &P, p1: &P, p2: &P, p3 | |||
res | |||
} | |||
|
|||
#[allow(non_snake_case)] | |||
fn triangle_unit_inertia_tensor_wrt_point2D<P>(point: &P, p1: &P, p2: &P, p3: &P) -> <P::Vect as Vect>::Scalar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to allow non_snake_case
as this is non-idiomatic. Instead the "convention" I tend to use is to append the dimension number without the D
. For example: triangle_unit_inertia_tensor_wrt_point2
.
Is it possible that crates.io needs a while to update to the newest version of ncollide? |
And yes, I will squash the commits in the end. ;) To speed things up I squashed my master branch and added another branch fullHistory with all the individual commits. |
Last thing before a merge: I don't think your computations for the 2D triangle moment of inertia is correct. I think it should be |
Indeed, I also think my calculation is wrong. I'm still trying to wrap my head around the math. |
This is how far I came: After some digging I found a planar moment of inertia cheat sheet: I then started to develop an algorithm but soon ended up with a lot of trigonometric function calls - and that's not the type of operations you would typically see in such a code. Lots of refinement and optimization would be necessary to get this approach into shape. What do you think about the general approach? |
I'm a bit stuck right now with the tests. Using the test crate requires rust nightly due to the experimental feature status and ncollide does not compile with rust nightly (it seems it has problems with inferring types). Looking at the errors it's not clear to me whether changes in ncollide are needed or whether this is a compiler regression. Could be this one: |
26ca4ea
to
aea07ea
Compare
It seems like the test crate is not needed at the moment. So I commented it out to get the tests to work with stable rust. I can now test square, rectangle and triangle inertia calculation - and they all pass. Note: I had to break your design by introducing an additional function Now that the tests pass and the demo works, I'm happy with my changes and done for the moment. Please take a look at it, comment and merge if you like it. |
The dimensions of the input point let mut i: I = na::zero();
i[(0, 0)] = na::cast(42.0); // the 2D inertia momentum. In your case, the following should work: pub fn convex_hull_unit_angular_inertia<P, I>(dim: usize, points: &[P]) -> I
where P: Point,
I: Zero +
Add<I, Output = I> +
Mul<<P::Vect as Vect>::Scalar, Output = I> +
IndexMut<(usize, usize), Output = <P::Vect as Vect>::Scalar>,
P::Vect: Outer,
<P::Vect as Outer>::OuterProductType: EigenQR<<P::Vect as Vect>::Scalar, P::Vect> +
Mul<P, Output = P> +
Add<<P::Vect as Outer>::OuterProductType, Output = <P::Vect as Outer>::OuterProductType> +
Zero + Copy {
assert!(dim == 2 || dim == 3);
match dim {
2 => {
let convex_mesh = transformation::convex_hull2(points);
unsafe {
let (area, _, i): (_, _, <P::Vect as Vect>::Scalar) = convex_mesh_mass_properties2(&convex_mesh, na::one());
let mut tensor: I = na::zero();
tensor[(0, 0)] = i * (na::one::<<P::Vect as Vect>::Scalar>() / area);
tensor
}
}
3 => {
let convex_mesh = transformation::convex_hull3(points);
unsafe {
let (vol, _, i): (_, _, I) = convex_mesh_mass_properties(&convex_mesh, na::one());
i * (na::one::<<P::Vect as Vect>::Scalar>() / vol)
}
}
_ => {
unimplemented!()
}
}
} And you cloud do the same to get rid of |
Wow! I still got a lot to learn about rust. Thanks for the hint! Now I could realize your first suggestion but with the second |
You're right, I forgot about the Okay, so as soon as you remove the commented code (that you left to show me what could go wrong), and squash the commits, I will merge this! |
Done. |
extensions for 2D convex shape
Thanks for all this work and your tenacity! |
Darn! I just realized that the picking in the demo is broken. I had by mistake (C)SFML 2.3 installed instead of 2.1. The demos compiled with 2.3 but picking didn't work at all, so I didn't noticed the regression with convex shapes. I'm looking at the code now looking for a fix, but it looks deeply mathematical and complex. I hope I get somewhere. |
If you are talking about a panic like "Attempted to translate the identity matrix" whenever you try to grab a convex object, don't worry about that. It's a bug independent from your work (originating from this line)! I did not notice this either because I was running SFML 2.3 as well, but now that you spotted it, I should be able to fix this. |
This might be a bit tricky to fix actually. I need to modify a couple of algorithms to make it work without adding an overhead wrt. the current (bugged anyway) implementation. I opened the issue #35 for this. |
Yes, I'm referring to the 'Attempted to translate the identity matrix.' panic. Still no solution from my side so far. :-/ |
I created the issue #35 on the wrong repository. It is now there: dimforge/ncollide#87, with a comment about how I am going to fix it. |
Hello Sébastien,
I tried to play around with 2D convex shapes and noticed that they are not completely supported yet. Then I tried to patch in what's missing and to my surprise succeeded in getting a basic 2D convex demo up and running. Maybe you want to take a look at it, comment and - if everything is ok - merge?
This pull request contains the parts of nphysics.
Note: I also created "demo2Dconvex" branches in my github repositories. They have the dependencies properly set so that they compile and can be tested.
Michi