I'm supposed to calculate the inertia tensor of an asteroid defined by a bunch of vertices in matlab, assuming constant density.
The specifics of the integral are not important, it all boils down to calculating $$\int_{D}{f(x,y,z)\ dxdydz}$$ where $D$ is the body defined in Matlab by a set of vertices.
Anyone's got any idea of how to approach this? I guess I could use integral3 and create a function that decides wheather or not I'm inside the body or not, but I don't really know how that function would work. Sources on how to do that would be greatly appreciated too!
Thanks!
Suppose that the asteroid is star-shaped*, that is there exists a point $P_0$ inside of it such that for any vertex $v$ the line segment from $P_0$ to $v$ is contained in the asteroid. In this case the asteroid is the union of tetrahedra with one vertex at $P_0$ and other vertices on the boundary. (I'm assuming the boundary is triangulated). The moments of inertia of a tetrahedron of constant density can be written out explicitly, as is done here. So you don't actually need integration, just a sum over all triangular faces on the boundary.
(*) no pun intended