pyblenderSDIC.meshes.TriangleMesh3D.compute_volume#
- TriangleMesh3D.compute_volume() None [source]#
Compute the volume of the mesh.
The volume is computed as the sum of the signed volumes of each triangle. The result is stored in the
volume
attribute as a float.The volume is compute by using the Green theorem for polyhedra. For each triangle, the signed volume is computed as:
\[V = \frac{1}{6} P_1 \cdot (P_2 \times P_3)\]where \(P_1\), \(P_2\), and \(P_3\) are the vertices of the triangle and \(\cdot\) and \(\times\) are the dot and cross products, respectively. The total volume is the sum of the absolute values of the signed volumes of all triangles.
from pyblenderSDIC.mesh import TriangleMesh3D # Create a TriangleMesh3D instance mesh = TriangleMesh3D(vertices=..., triangles=...) # Compute the volume of the mesh mesh.compute_volume() # The volume is now available in the `volume` attribute mesh.volume
Warning
The volume can only be computed if the mesh
is_watertight
.The volume is given as a signed value, which can be negative if the mesh is not oriented correctly.