1. 创建三角面(Triangulated Surface)

首先是一堆离散的点,然后使用pv.PolyData(points)函数生成三角面。

import pyvista as pv
import numpy as np

# Define a simple Gaussian surface
n = 20
x = np.linspace(-200, 200, num=n) + np.random.uniform(-5, 5, size=n)
y = np.linspace(-200, 200, num=n) + np.random.uniform(-5, 5, size=n)
xx, yy = np.meshgrid(x, y)
A, b = 100, 100
zz = A * np.exp(-0.5 * ((xx / b) ** 2.0 + (yy / b) ** 2.0))

# Get the points as a 2D NumPy array (N by 3)
points = np.c_[xx.reshape(-1), yy.reshape(-1), zz.reshape(-1)]
points[0:5, :]

# simply pass the numpy points to the PolyData constructor
cloud = pv.PolyData(points)
cloud.plot(point_size=15)

然后生成面:

surf = cloud.delaunay_2d()
surf.plot(show_edges=True)

指定alpha=1.0参数可以把多余的点去除:surf = cloud.delaunay_2d(alpha=1.0),具体示意图就不放了。