// // Polyhedral Mass Properties // - Volume // - Center Of Mass // - Inertial Tensor // by: S Melax // // // Routines for calculating physical properties of a mesh. // Input vertices and index triangle lists. // The interfaces were designed so you could steal these functions // and incorporate into your own environment extremely quickly. // // // The Inertial Tensor routine Inertia() does its summation // with respect to the center of mass which it assumes is [0,0,0] if // none is provided. // // Note, There are cases where you actually want the inertial properties // from a point other than the center of mass. In particular, when // combining (possibly interpenetrating) geometries with different // masses and mass densities into a compound rigid body. // Inertia tensors can be rotated and translated after the fact, but // the operation is different than the usual matrix transforms. // // From a triangle with vertices v1,v2 and v3 // the 4 vertices of the tetrahedron are v0,v1,v2,v3 // where v0=[0 0 0]. // These algorithems are based on tetrahedral summation. // See http://www.melax.com/volint/ for more discussion. // // float Volume(const float3 *vertices, const int3 *tris, const int count) { // count is the number of triangles (tris) float volume=0; for(int i=0; i