3角形サーフェスを作成

3角形サーフェスを作成#

Delaunay三角形分割によって点の集合からサーフェスを作成します。この例では pyvista.PolyDataFilters.delaunay_2d() を使用しています。

from __future__ import annotations

import numpy as np

import pyvista as pv

# Seed random numbers for reproducibility
rng = np.random.default_rng(seed=0)

単純な軌道#

まず,表面のポイントをいくつか作成します.

# Define a simple Gaussian surface
n = 20
x = np.linspace(-200, 200, num=n) + rng.uniform(-5, 5, size=n)
y = np.linspace(-200, 200, num=n) + rng.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, :]
array([[-198.63038313, -204.71680329,    1.71090121],
       [-181.24950128, -204.71680329,    2.38012408],
       [-162.4850016 , -204.71680329,    3.28594053],
       [-141.67682891, -204.71680329,    4.5091358 ],
       [-112.65677129, -204.71680329,    6.52176016]])

これらのポイントを使用して,ポイントクラウドPyVistaデータオブジェクトを作成します.これは pyvista.PolyData オブジェクトに含まれます.

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

ポイントのPyVistaデータ構造ができたので,3角形分割を実行して,これらの退屈な個別のポイントを接続されたサーフェスに変えることができます.

surf = cloud.delaunay_2d()
surf.plot(show_edges=True)
create tri surface

マスクされた3角形#

x = np.arange(10, dtype=float)
xx, yy, zz = np.meshgrid(x, x, [0])
points = np.column_stack((xx.ravel(order='F'), yy.ravel(order='F'), zz.ravel(order='F')))
# Perturb the points
points[:, 0] += rng.random(len(points)) * 0.3
points[:, 1] += rng.random(len(points)) * 0.3
# Create the point cloud mesh to triangulate from the coordinates
cloud = pv.PolyData(points)
cloud
PolyDataInformation
N Cells100
N Points100
N Strips0
X Bounds2.520e-02, 9.288e+00
Y Bounds2.986e-03, 9.297e+00
Z Bounds0.000e+00, 0.000e+00
N Arrays0


これらの点で3角形分割を実行します

surf = cloud.delaunay_2d()
surf.plot(cpos='xy', show_edges=True)
create tri surface

外側のエッジの一部は拘束されておらず,3角形分割によって不要な3角形が追加されていることに注意してください.私たちは alpha パラメータでそれを緩和します.

surf = cloud.delaunay_2d(alpha=1.0)
surf.plot(cpos='xy', show_edges=True)
create tri surface

また, edge_source パラメータを使用して,3角形分割中に無視するポリゴンを追加することもできます.

# Define a polygonal hole with a clockwise polygon
ids = [22, 23, 24, 25, 35, 45, 44, 43, 42, 32]

# Create a polydata to store the boundary
polygon = pv.PolyData()
# Make sure it has the same points as the mesh being triangulated
polygon.points = points
# But only has faces in regions to ignore
polygon.faces = np.insert(ids, 0, len(ids))

surf = cloud.delaunay_2d(alpha=1.0, edge_source=polygon)

p = pv.Plotter()
p.add_mesh(surf, show_edges=True)
p.add_mesh(polygon, color='red', opacity=0.5)
p.show(cpos='xy')
create tri surface

Tags: load

Total running time of the script: (0 minutes 1.155 seconds)

Sphinx-Galleryによるギャラリー