注釈
Go to the end to download the full example code.
メッシュの表面上の点をピックします#
この例では, enable_surface_point_picking()
を使用してメッシュをピックする方法を示します.
これにより,メッシュの表面上のポイントをピックすることができます.
from __future__ import annotations
import pyvista as pv
メッシュを作成し,デフォルトの設定でピッキングを有効にします.
cube = pv.Cube()
pl = pv.Plotter()
pl.add_mesh(cube, show_edges=True)
pl.enable_surface_point_picking()
pl.show()

右クリックしたポイントにキューブを作成するコールバックを有効にし,そのポイントにラベルも追加します.
def callback(point):
"""Create a cube and a label at the click point."""
mesh = pv.Cube(center=point, x_length=0.05, y_length=0.05, z_length=0.05)
pl.add_mesh(mesh, style='wireframe', color='r')
pl.add_point_labels(point, [f'{point[0]:.2f}, {point[1]:.2f}, {point[2]:.2f}'])
pl = pv.Plotter()
pl.add_mesh(cube, show_edges=True)
pl.enable_surface_point_picking(callback=callback, show_point=False)
pl.show()

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