File: ray_trace.py

package info (click to toggle)
python-pyvista 0.46.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176,968 kB
  • sloc: python: 94,346; sh: 216; makefile: 70
file content (37 lines) | stat: -rw-r--r-- 861 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
.. _ray_trace_example:

Ray Tracing
~~~~~~~~~~~

Single line segment ray tracing for :class:`~pyvista.PolyData` objects
using :meth:`~pyvista.PolyDataFilters.ray_trace`.
"""

from __future__ import annotations

import pyvista as pv

# Create source to ray trace
sphere = pv.Sphere(radius=0.85)

# Define line segment
start = [0, 0, 0]
stop = [0.25, 1, 0.5]

# Perform ray trace
points, ind = sphere.ray_trace(start, stop)

# Create geometry to represent ray trace
ray = pv.Line(start, stop)
intersection = pv.PolyData(points)

# Render the result
p = pv.Plotter()
p.add_mesh(sphere, show_edges=True, opacity=0.5, color='w', lighting=False, label='Test Mesh')
p.add_mesh(ray, color='blue', line_width=5, label='Ray Segment')
p.add_mesh(intersection, color='maroon', point_size=25, label='Intersection Points')
p.add_legend()
p.show()
# %%
# .. tags:: filter