The following describes and calculates a number of useful properties of an object defined by a triangular surface mesh. Specifically, we consider:
, where is an infinitesimal area on the surface
The volume is given by If the density is uniform, mass is just density times volume.
Assuming its a uniformly dense solid (as opposed to a thin shell, e.g.) the centroid is defined as
In tensor notation we have
In general the above integral give the moment of inertia about axes passing through the origin of the coordinate system. To get the body centered moment of inertia we can use the parallel-axis theorem:
where is the mass of the object and is the centroid.
This is defined using tensor notation as
The trace of will be equal to the surface area of the mesh.
This only works if all the triangle facets have to be oriented consistently. That is, in the face data, for each face the vertices have to be listed in a counter-clockwise order, while looking at the face from outside the mesh. If the vertices are consistently clockwise, that would result in a negative value for volume. In such a case, switching any two columns in the face data will make it oriented properly. The surface integrals are evaluated exactly directly on the triangles. So, the total surface area and the area tensor can be calculated in each face and added up.
, where is the area of the face. The area of each triangle is calculated by taking cross product of two edges of a triangle. Half the magnitude of this vector is the area of the triangle. This step also gives us the normal to the triangle face, which will be needed later on.
The volume integrals can be done directly by decomposing the mesh into tetrahedrons and evaluating the integral for each tetrahedron. An elegant alternative is to use the Gauss Divergence Theorem. We can use it to recast the volume integrals as surface integrals.
The surface integral can then be written as a summation of the integral evaluated per face.
The integrand is calculated exactly on each triangular face. There are 10 functions whose volume integrals need to be evaluated-- 1 for volume, 3 for centroid and 6 for the moment of inertia.
For obtaining the integral that gives us the volume, the function has to be such that , so that the right hand side in the Divergence Theorem equation equals volume. For example, it can be taken to be . In the code I take where , whose divergence is also unity. This is done because this particular function is needed later in calculating the other integrals.
Plugging the latter into the equation of the divergence theorem, we get
where lies on the surface, and are the components of the outward facing normal at . As mentioned earlier, the surface integral can be written as sum of exact per-face integrals.
The others are calculated similarly. The
python code follows. The sample program calculates the the mass properties for triangulated unit cube of unit density.