FormDiagram.volume
- FormDiagram.volume(copy=True, unify_cycles=True)
Calculate the volume of the mesh.
- Parameters:
- copybool, optional
If True, a copy of the mesh is made before computation to avoid modifying the original. Default is True.
- unify_cyclesbool, optional
If True, face cycles are unified to ensure consistent orientation. Default is True.
- Returns:
- float | None
The volume of the mesh if the mesh is closed, None otherwise.
Notes
The volume is computed using the signed volume of tetrahedra formed by each triangulated face and the origin. This method works for both convex and non-convex meshes, as long as they are closed and properly oriented.
The volume is only meaningful for closed meshes. For open meshes, this method returns None.
When faces are non-convex, the triangulation might not be correct, since it uses the centroid of the face. For accurate results with non-convex faces, consider using a mesh with triangulated faces.
By default, the mesh is copied internally and face cycles are unified to ensure correct orientation before computing the volume. These operations can be disabled by setting
copy=Falseandunify_cycles=Falsefor performance in cases where the mesh is already correctly oriented or when the original mesh can be modified.Examples
>>> from compas.datastructures import Mesh >>> mesh = Mesh.from_polyhedron(6) # Create a cube >>> volume = mesh.volume() >>> volume is not None True