0
votes

I have an object defined by vertices and triangular faces.

verts = [[0.1, 1.,  1. ]  [1.,  1.,  0.1]  [1.,  0.1, 1. ]  [1.,  1.,  1.9]  [1.,  1.9, 1. ]
 [1.9, 1.,  1. ] ]

And triangular faces, which define the vertices composing each faces:

faces = [[ 2,  1,  0]  [ 0,  3,  2]  [ 1,  4,  0]  [ 0,  4,  3]  [ 5,  1,  2]  [ 3,  5,  2]
 [ 5,  4,  1]  [ 4,  5,  3]]

I can create a mesh using Poly3DCollection

from mpl_toolkits.mplot3d.art3d import Poly3DCollection
mesh = Poly3DCollection(verts[faces])

I can use mesh to plot the object in 3D. Is there a way in python to then find the volume of this object? Papers (here, here, and here) indicate it is possible. If not in python, are there methods in other languages that make this possible (i.e. that you know of). Thanks in advance!

2

2 Answers

2
votes

I solved this using meshplex

import meshplex
import numpy as np

verts = [[0.1, 1.,  1. ],  [1.,  1.,  0.1],  [1.,  0.1, 1. ],  [1.,  1.,  1.9],  [1.,  1.9, 1. ], [1.9, 1.,  1. ]]
faces = [[ 2,  1,  0],  [ 0,  3,  2],  [ 1,  4,  0],  [ 0,  4,  3],  [ 5,  1,  2],  [ 3,  5,  2], [ 5,  4,  1],  [ 4,  5,  3]]

mesh = meshplex.MeshTri(np.array(points), np.array(faces))

V = np.sum(mesh.cell_volumes)

print("Volume =", V)
# Volume = 5.6118446
1
votes

In C++, CGAL is able to compute the volume of a triangulated mesh with this function : https://doc.cgal.org/latest/Polygon_mesh_processing/group__measure__grp.html#ga85cebf8fbc7cb8930fd16aeee2878c7e

Sadly I don't think it has been ported in python.