| 1 |
""" |
| 2 |
.. _ray_trace_example: |
| 3 |
|
| 4 |
Ray Tracing |
| 5 |
~~~~~~~~~~~ |
| 6 |
|
| 7 |
Single line segment ray tracing for :class:`~pyvista.PolyData` objects |
| 8 |
using :meth:`~pyvista.PolyDataFilters.ray_trace`. |
| 9 |
""" |
| 10 |
|
| 11 |
import pyvista as pv |
| 12 |
|
| 13 |
# Create source to ray trace |
| 14 |
sphere = pv.Sphere(radius=0.85) |
| 15 |
|
| 16 |
# Define line segment |
| 17 |
start = [0, 0, 0] |
| 18 |
stop = [0.25, 1, 0.5] |
| 19 |
|
| 20 |
# Perform ray trace |
| 21 |
points, ind = sphere.ray_trace(start, stop) |
| 22 |
|
| 23 |
# Create geometry to represent ray trace |
| 24 |
ray = pv.Line(start, stop) |
| 25 |
intersection = pv.PolyData(points) |
| 26 |
|
| 27 |
# Render the result |
| 28 |
pl = pv.Plotter() |
| 29 |
pl.add_mesh( |
| 30 |
sphere, show_edges=True, opacity=0.5, color='w', lighting=False, label='Test Mesh' |
| 31 |
) |
| 32 |
pl.add_mesh(ray, color='blue', line_width=5, label='Ray Segment') |
| 33 |
pl.add_mesh(intersection, color='maroon', point_size=25, label='Intersection Points') |
| 34 |
pl.add_legend() |
| 35 |
pl.show() |
| 36 |
# %% |
| 37 |
# .. tags:: filter |