make_tri_mesh#
- make_tri_mesh(points: NumpyArray[float], faces: NumpyArray[int]) PolyData[source]#
Construct a
pyvista.PolyDatamesh using points and faces arrays.Construct a mesh from an Nx3 array of points and an Mx3 array of triangle indices, resulting in a mesh with N vertices and M triangles. This function does not require the standard VTK “padding” column and simplifies mesh creation.
- Parameters:
- points
np.ndarray Array of points with shape
(N, 3)storing the vertices of the triangle mesh.- faces
np.ndarray Array of indices with shape
(M, 3)containing the triangle indices.
- points
- Returns:
pyvista.PolyDataPolyData instance containing the triangle mesh.
Examples#
This example discretizes the unit square into a triangle mesh with nine vertices and eight faces.
>>> import numpy as np
>>> import pyvista as pv
>>> points = np.array(
... [
... [0, 0, 0],
... [0.5, 0, 0],
... [1, 0, 0],
... [0, 0.5, 0],
... [0.5, 0.5, 0],
... [1, 0.5, 0],
... [0, 1, 0],
... [0.5, 1, 0],
... [1, 1, 0],
... ]
... )
>>> faces = np.array(
... [
... [0, 1, 4],
... [4, 7, 6],
... [2, 5, 4],
... [4, 5, 8],
... [0, 4, 3],
... [3, 4, 6],
... [1, 2, 4],
... [4, 8, 7],
... ]
... )
>>> tri_mesh = pv.make_tri_mesh(points, faces)
>>> tri_mesh.plot(show_edges=True, line_width=5)