Skip to content
Advertisement

PyVista mesh triangulation – vertex indices

I have a triangulated mesh that I generated with the Delaunay 3D function in PyVista. I would like to calculate the surface area of the mesh adding up the areas of all the triangles. Is there a way to obtain the indices of the simplices triangles from the delaunay result?

JavaScript

I know I can do it with Scipy but for whatever reason Scipy generates an incorrect mesh (and does not have attributes I can adjust in the Delaunay method):

JavaScript

My goal is to loop through the triangles and calculate the surface area of the mesh.

Advertisement

Answer

PyVista PolyData objects already have an area property that adds up the cell areas.

For example, consider random points on the unit sphere:

JavaScript

For me this printed

JavaScript

The first value is the total area of our triangulated point cloud on a sphere, and the second value is the exact surface of a perfect unit sphere. Looks good.

Additionally, there are other similar attributes, for instance volume for watertight surfaces (which you have):

JavaScript

In other words, you don’t need the vertex indices if you’re only looking for the total area.

(If you do still want the vertices, the information is accessible via triangulated.faces. My recommendation would be to look at triangulated.faces.reshape(-1, 4)[:, 1:] which is a 2d array of shape (n_cells, 3), where each row corresponds to a given triangle and the three integers in the row are the indices of the three points forming the corresponding triangle.)

Advertisement