# Evaluating mesh volume from surface

One of the first tests one needs to implement when generating meshes is a volume test. The main idea like in many other tests is to evaluate the same quantity in two different ways and then compare the results. If everything is correct the results should be close up to some rounding precision error.

When dealing with surface vs volume calculation a familiar method from mutivariable calculus is the Divergence theorem [1] :

\[\int_\Omega div(g)\, dv = \int_{\partial\Omega} g \cdot \mathbf{n}\, ds\]In other words, we can evaluate a quantity related to the whole volume just by using information on the boundary of the domain which is exactly our goal in this case.

In [2], one can find more details about deriving formulas about volume moments of inertia and center of mass (that can also be expressed via integrals). Although there are plenty of derivations in the paper it all boils down to a single sentence in the conclusion of the paper.

An integral over a polyhedron $Q = (F,E,V)$ equals the sum of the appropriately signed integrals over cones formed by faces of Q with respect to the origin.

Where, $F,E,V$ is the set of face,edges and vertices respectively.

In order words, picking an arbitrary point $P$ in space and summing the signed volumes of the tetrahedra formed by each face triangle and $P$ will give us the volume of the domain.

Of interest is also their final remark

Note that the numerical accuracy of this method can be improved by shifting the origin of the coordinate system to the barycenter of the object, especially to prevent the occurrence of long, thin tetrahedra when an object is far removed from the origin.

## References

[1] https://www.encyclopediaofmath.org/index.php/Divergence_theorem

[2] S. Lien and J. T. Kajiya, “A symbolic method for calculating the integral properties of arbitrary nonconvex polyhedra,” IEEE Computer Graphics and Applications, vol. 4, no. 10, pp. 35–42, Oct. 1984. https://doi.org/10.1109/MCG.1984.6429334

* Tagged : *
#mesh,
#utilities