2

我在平面中有一组 2D 顶点坐标(假设 xy 平面),我想在 z 方向上挤压它以形成一个PolyData可以变换和渲染的对象。

理想的函数将采用 nx2 ndarray 顶点和高度并返回 a PolyData

一个备用解决方案是在 VTK 中执行此操作并将结果包装为 PyVista 对象。

4

1 回答 1

4

将 2d 顶点嵌入 3d 以创建实际多边形并进行拉伸的直接解决方案:

import numpy as np
import pyvista as pv

rng = np.random.default_rng()

# create dummy data
N = 10
angles = np.linspace(0, 2*np.pi, N, endpoint=False)
radii = rng.uniform(0.5, 1.5, N)
coords = np.array([np.cos(angles), np.sin(angles)]) * radii
points_2d = coords.T  # shape (N, 2)

# embed in 3d, create polygon
points_3d = np.pad(points_2d, [(0, 0), (0, 1)])  # shape (N, 3)
polygon = pv.lines_from_points(points_3d, close=True)

# extrude along z and plot
body = polygon.extrude((0, 0, 0.5))
body.plot(color='white', specular=1, screenshot='extruded.png')

成功挤出表面:带有随机多边形底座的墙

如果在挤压后需要封闭曲面,则必须从实心多边形(即面而不是线)开始:

# embed in 3d, create filled polygon
points_3d = np.pad(points_2d, [(0, 0), (0, 1)])  # shape (N, 3)
face = [N + 1] + list(range(N)) + [0]  # cell connectivity for a single cell
polygon = pv.PolyData(points_3d, faces=face)

# extrude along z and plot
body = polygon.extrude((0, 0, 0.5))
body.plot(color='white', specular=1, screenshot='extruded.png')

与之前类似,但表面被覆盖

于 2021-03-30T00:11:21.283 回答