Given a mesh (vertices, edges, faces), I need to calculate the volume of the formed mesh. By volume, I mean the amount of space that a substance or object occupies. The resulting volume does not include any unoccupied space in or outside of the mesh.
- The given mesh may or may not be closed, that is;
- The given mesh may or may not have holes on its surface
- The given mesh may or may not be hollow/partially hollow
- The given mesh may or may not be a primitive shape
- The given mesh may or may not be composite
This wireframe of a 5x5 cube has been "crushed" and has a partial hole in its center. I'm looking for the volume of this mesh without the unoccupied/hollow space.
Every vertex is defined by its 3D coordinates and normal, both of which are floating-point. Though, a 2D solution would work just as well with extension.
As described here and here, the volume of a closed mesh can be calculated fairly easily. My research hasn't brought any information on non-closed (open?) meshes.
One possible solution would be to brute-force it by checking each coordinate to a certain precision. With space partitioning, I could also determine whether a coordinate is within the solid bounds of any vertices. This provides a ratio that could be used on the rectangular bounding box volume. The main downside to this is speed, like all brute-force techniques. I'm hoping for a particularly more efficient solution.


If any three vertices (defined by vectors $A$, $B$, $C$) form a triangle as a part of the skin of a volume, then the volume of the triangle pyramid is formed by the three vertices, and the origin is
$${\rm volume}(A,B,C) = \frac{ A \cdot ( B \times C) }{6}$$
Here $\cdot$ is the vector dot product, and $\times$ the vector cross product. The above is often called the vector triple product.
To find the total volume, split the object into triangles and add up all the volumes from above. If a face normal is away from the origin it will count as positive volume, and towards the origin, it will be negative. This way due to Green's theorem in total only the volume enclosed by the mesh will be counted.
Please also note the area of the triangle is
$${\rm area}(A,B,C)=\tfrac{1}{2}\|A\times B+B\times C+C\times A\|$$
Here is a simple example with
$$ \begin{aligned}{A} & =\begin{pmatrix}40\\ 0\\ 0 \end{pmatrix} & {B} & =\begin{pmatrix}0\\ 25\\ 0 \end{pmatrix} & {C} & =\begin{pmatrix}0\\ 0\\ 8 \end{pmatrix}\end{aligned}$$
The volume is
$$ V=\tfrac{1}{6}\begin{pmatrix}40\\ 0\\ 0 \end{pmatrix}\cdot\left(\begin{pmatrix}0\\ 25\\ 0 \end{pmatrix}\times\begin{pmatrix}0\\ 0\\ 8 \end{pmatrix}\right)=\tfrac{1}{6}\begin{pmatrix}40\\ 0\\ 0 \end{pmatrix}\cdot\begin{pmatrix}200\\ 0\\ 0 \end{pmatrix}=\frac{8000}{6}=1333.3\overline{3}\;\checkmark$$
Which is the value that matches with CAD.
And here is a more complex example
which I matched with CAD also. The STL file contained 5088 vertices and 1696 triangular faces. The CAD model gave me a volume of
46085.4and a Fortran program I checked with gave me the value46086.1Now granted the Fortran program was intended to derive the mass properties from an STL file, such as volume, the center of mass, and mass moment of inertia tensor.
In the code there is clearly visible the line
i_V = dot(A, cross(B, C))/6which computes the volume for each triangle.For completeness here is the processing code