Calculate the center of mass of a solid 3d polyhedron made of discrete triangles

80 Views Asked by At

I am writing a physics simulator. The idea is that you load any 3d model into it and it simulates collisions.

(I am aware of the difficulties with colliding concave polyhedra, that's a different issue)

We can assume that the polyhedron is solid, closed-surface, but it may or may not be concave, and in general we may not make assumptions about the topology of the object. It is made up of air-tight connecting triangles. We can also assume the shape has uniform material/density.

My approach thus far:

  1. Calculate the area for each triangle. (array of weights)
  2. Get the center of each triangle. (array of 3d vectors)
  3. Piecewise, multiply the resulting arrays from step 1 and 2. This leaves us with an array of weighted 3d vectors. (you could inline step 1 to 3 in a single loop of course)
  4. Sum the array of weighted 3d vectors into a single 3d vector, then piecewise divide it by the count of triangles. We now have a center of mass.

But my physics teacher had the following comment on that: "So all polyhedrons are hollow?". He said that doing it this way would only work for hollow polyhedra, but he could not tell me how to do it for solids. I have tried searching this issue but it's left me completely stumped. Could you help?

My second approach, while technically possible, would be very, very slow. The testing (step 2) would be done with raytracing and checking wether the surface normal coincides.

  1. Generate a random point
  2. Check if it is inside the polyhedron, reject if not inside.
  3. Repeat a couple of thousand times
  4. We now have a point-cloud of the polyhedron, so just calculate the average point.