How can I compute the mass and moment of inertia of a polyhedron?
Asked Answered
G

5

6

For use in a rigid body simulation, I want to compute the mass and inertia tensor (moment of inertia), given a triangle mesh representing the boundary of the (not necessarily convex) object, and assuming constant density in the interior.

Ganja answered 1/5, 2009 at 1:9 Comment(1)
S
11

Assuming your trimesh is closed (whether convex or not) there is a way!

As dmckee points out, the general approach is building tetrahedrons from each surface triangle, then applying the obvious math to total up the mass and moment contributions from each tet. The trick comes in when the surface of the body has concavities that make internal pockets when viewed from whatever your reference point is.

So, to get started, pick some reference point (the origin in model coordinates will work fine), it doesn't even need to be inside of the body. For every triangle, connect the three points of that triangle to the reference point to form a tetrahedron. Here's the trick: use the triangle's surface normal to figure out if the triangle is facing towards or away from the reference point (which you can find by looking at the sign of the dot product of the normal and a vector pointing at the centroid of the triangle). If the triangle is facing away from the reference point, treat its mass and moment normally, but if it is facing towards the reference point (suggesting that there is open space between the reference point and the solid body), negate your results for that tet.

Effectively what this does is over-count chunks of volume and then correct once those areas are shown to be not part of the solid body. If a body has lots of blubbery flanges and grotesque folds (got that image?), a particular piece of volume may be over-counted by a hefty factor, but it will be subtracted off just enough times to cancel it out if your mesh is closed. Working this way you can even handle internal bubbles of space in your objects (assuming the normals are set correctly). On top of that, each triangle can be handled independently so you can parallelize at will. Enjoy!

Afterthought: You might wonder what happens when that dot product gives you a value at or near zero. This only happens when the triangle face is parallel (its normal is perpendicular) do the direction to the reference point -- which only happens for degenerate tets with small or zero area anyway. That is to say, the decision to add or subtract a tet's contribution is only questionable when the tet wasn't going to contribute anything anyway.

Schmidt answered 1/5, 2009 at 2:18 Comment(1)
Nice. I should have seen this. It's an extension of the old "count the crossings" approach to learning if a point is interior or exterior to a shape.Discontent
D
2

Decompose your object into a set of tetrahedrons around the selected interior point. (That is solids using each triangular face element and the chosen center.)

You should be able to look up the volume of each element. The moment of inertia should also be available.

It gets to be rather more trouble if the surface is non-convex.


I seem to have miss-remembered by nomenclature and skew is not the adjective I wanted. I mean non-regular.

Discontent answered 1/5, 2009 at 1:18 Comment(2)
If the object isn't convex (and sometimes even if it is), tesselation into tets is much more complicated than just computing the mass directly.Sassoon
@Reed Copsey: I'll take your word for it. The solution I've offered is certainly naive.Discontent
A
2

This is covered in the book "Game Physics, Second Edition" by D. Eberly. The chapter 2.5.5 and sample code is available online. (Just found it, haven't tried it out yet.)

Also note that the polyhedron doesn't have to be convex for the formulas to work, it just has to be simple.

Aurita answered 13/3, 2011 at 10:19 Comment(0)
S
1

I'd take a look at vtkMassProperties. This is a fairly robust algorithm for computing this, given a surface enclosing a volume.

Sassoon answered 1/5, 2009 at 1:13 Comment(0)
E
1

If your polydedron is complicated, consider using Monte Carlo integration, which is often used for multidimensional integrals. You will need an enclosing hypercube, and you will need to be able to test whether a given point is inside or outside the polyhedron. And you will need to be patient, as Monte Carlo integration is slow.

Start as usual at Wikipedia, and then follow the external links pages for further reading.

(For those unfamiliar with Monte Carlo integration, here's how to compute a mass. Pick a point in the containing hypercube. Add to the point_total counter. Is it in the polyhedron? If yes, add to the point_internal counter. Do this lots (see the convergence and error bound estimates.) Then

mass_polyhedron/mass_hypercube \approx points_internal/points_total.

For a moment of inertia, you weight each count by the square of the distance of the point to the reference axis.

The tricky part is testing whether a point is inside or outside your polyhedron. I'm sure that there are computational geometry algorithms for that.

Electrometer answered 17/5, 2009 at 0:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.