我有一个由顶点和三角形面定义的对象。
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]]
我可以使用Poly3DCollection创建网格
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
mesh = Poly3DCollection(verts[faces])
我可以使用mesh
以3D绘制对象。 python中是否有一种方法可以找到该对象的体积?纸张(here,here和here)表示有可能。如果不是在python中,是否有其他语言的方法可以做到这一点(即您所知道的)。预先感谢!
在C ++中,CGAL可以使用此函数来计算三角网格的体积:https://doc.cgal.org/latest/Polygon_mesh_processing/group__measure__grp.html#ga85cebf8fbc7cb8930fd16aeee2878c7e
可悲的是,我不认为它已在python中移植。
我使用meshplex
解决了此问题>
import meshplex
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 = 0
for vol in mesh.cell_volumes:
V+=vol
print('Volume = ",V)
# Volume = 5.6118446