pyvista.PolyDataFilters.multi_ray_trace#

PolyDataFilters.multi_ray_trace(origins, directions, first_point=False, retry=False)[source]#

Perform multiple ray trace calculations.

This requires a mesh with only triangular faces, an array of origin points and an equal sized array of direction vectors to trace along.

The embree library used for vectorization of the ray traces is known to occasionally return no intersections where the VTK implementation would return an intersection. If the result appears to be missing some intersection points, set retry=True to run a second pass over rays that returned no intersections, using PolyDataFilters.ray_trace().

Parameters:
originsarray_like[float]

Starting point for each trace.

directionsarray_like[float]

Direction vector for each trace.

first_pointbool, default: False

Returns intersection of first point only.

retrybool, default: False

Will retry rays that return no intersections using PolyDataFilters.ray_trace().

Returns:
intersection_pointsnumpy.ndarray

Location of the intersection points. Empty array if no intersections.

intersection_raysnumpy.ndarray

Indices of the ray for each intersection point. Empty array if no intersections.

intersection_cellsnumpy.ndarray

Indices of the intersection cells. Empty array if no intersections.

Examples

Compute the intersection between rays from the origin in directions [1, 0, 0], [0, 1, 0] and [0, 0, 1], and a sphere with radius 0.5 centered at the origin

>>> import pyvista as pv  
>>> sphere = pv.Sphere()  
>>> points, rays, cells = sphere.multi_ray_trace(
...     [[0, 0, 0]] * 3,
...     [[1, 0, 0], [0, 1, 0], [0, 0, 1]],
...     first_point=True,
... )  
>>> string = ", ".join(
...     [
...         f"({point[0]:.3f}, {point[1]:.3f}, {point[2]:.3f})"
...         for point in points
...     ]
... )  
>>> f'Rays intersected at {string}'  
'Rays intersected at (0.499, 0.000, 0.000), (0.000, 0.497, 0.000), (0.000, 0.000, 0.500)'