PolyDataFilters.multi_ray_trace(origins, directions, first_point=False, retry=False)

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().


Starting point for each trace.


Direction vector for each trace.

first_pointbool, optional

Returns intersection of first point only.

retrybool, optional

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


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


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


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


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)'