ray_trace#
- PolyDataFilters.ray_trace(origin, end_point, first_point=False, plot=False, off_screen=None)[source]#
Perform a single ray trace calculation.
This requires a mesh and a line segment defined by an origin and end_point.
- Parameters:
- origin
np.ndarray
orlist
Start of the line segment.
- end_point
np.ndarray
orlist
End of the line segment.
- first_pointbool,
optional
Returns intersection of first point only.
- plotbool,
optional
Whether to plot the ray trace results.
- off_screenbool,
optional
Plots off screen when
plot=True
. Used for unit testing.
- origin
- Returns:
- intersection_points
numpy.ndarray
Location of the intersection points. Empty array if no intersections.
- intersection_cells
numpy.ndarray
Indices of the intersection cells. Empty array if no intersections.
- intersection_points
Examples
Compute the intersection between a ray from the origin to
[1, 0, 0]
and a sphere with radius 0.5 centered at the origin.>>> import pyvista as pv >>> sphere = pv.Sphere() >>> point, cell = sphere.ray_trace([0, 0, 0], [1, 0, 0], first_point=True) >>> f'Intersected at {point[0]:.3f} {point[1]:.3f} {point[2]:.3f}' 'Intersected at 0.499 0.000 0.000'
Show a plot of the ray trace.
>>> point, cell = sphere.ray_trace([0, 0, 0], [1, 0, 0], plot=True)
See Ray Tracing for more examples using this filter.