trimesh.ray.ray_triangle¶
A basic slow implementation of ray- triangle queries.
- class trimesh.ray.ray_triangle.RayMeshIntersector(mesh)¶
- Bases: - object- An object to query a mesh for ray intersections. Precomputes an r-tree for each triangle on the mesh. - __init__(mesh)¶
 - contains_points(points)¶
- Check if a mesh contains a list of points, using ray tests. - If the point is on the surface of the mesh the behavior is undefined. - Parameters:
- points ((n, 3) float) – Points in space 
- Returns:
- contains – Whether point is inside mesh or not 
- Return type:
- (n,) bool 
 
 - intersects_any(ray_origins, ray_directions, **kwargs)¶
- Find out if each ray hit any triangle on the mesh. - Parameters:
- ray_origins ((m, 3) float) – Ray origin points 
- ray_directions ((m, 3) float) – Ray direction vectors 
 
- Returns:
- hit – Whether any ray hit any triangle on the mesh 
- Return type:
- (m,) bool 
 
 - intersects_first(ray_origins, ray_directions, **kwargs)¶
- Find the index of the first triangle a ray hits. - Parameters:
- ray_origins ((n, 3) float) – Origins of rays 
- ray_directions ((n, 3) float) – Direction (vector) of rays 
 
- Returns:
- triangle_index – Index of triangle ray hit, or -1 if not hit 
- Return type:
- (n,) int 
 
 - intersects_id(ray_origins, ray_directions, return_locations=False, multiple_hits=True, **kwargs)¶
- Find the intersections between the current mesh and an array of rays. - Parameters:
- ray_origins ((m, 3) float) – Ray origin points 
- ray_directions ((m, 3) float) – Ray direction vectors 
- multiple_hits (bool) – Consider multiple hits of each ray or not 
- return_locations (bool) – Return hit locations or not 
 
- Returns:
- index_triangle ((h,) int) – Index of triangles hit 
- index_ray ((h,) int) – Index of ray that hit triangle 
- locations ((h, 3) float) – [optional] Position of intersection in space 
 
 
 - intersects_location(ray_origins, ray_directions, **kwargs)¶
- Return unique cartesian locations where rays hit the mesh. If you are counting the number of hits a ray had, this method should be used as if only the triangle index is used on- edge hits will be counted twice. - Parameters:
- ray_origins ((m, 3) float) – Ray origin points 
- ray_directions ((m, 3) float) – Ray direction vectors 
 
- Returns:
- locations ((n) sequence of (m,3) float) – Intersection points 
- index_ray ((n,) int) – Array of ray indexes 
- index_tri ((n,) int) – Array of triangle (face) indexes 
 
 
 
- trimesh.ray.ray_triangle.ray_bounds(ray_origins, ray_directions, bounds, buffer_dist=1e-05)¶
- Given a set of rays and a bounding box for the volume of interest where the rays will be passing through, find the bounding boxes of the rays as they pass through the volume. - Parameters:
- ray_origins ((m,3) float, ray origin points) 
- ray_directions ((m,3) float, ray direction vectors) 
- bounds ((2,3) bounding box (min, max)) 
- buffer_dist (float, distance to pad zero width bounding boxes) 
 
- Returns:
- ray_bounding 
- Return type:
- set of AABB of rays passing through volume 
 
 
- trimesh.ray.ray_triangle.ray_triangle_candidates(ray_origins, ray_directions, tree)¶
- Do broad- phase search for triangles that the rays may intersect. - Does this by creating a bounding box for the ray as it passes through the volume occupied by the tree - Parameters:
- ray_origins ((m, 3) float) – Ray origin points. 
- ray_directions ((m, 3) float) – Ray direction vectors 
- tree (rtree object) – Ccontains AABB of each triangle 
 
- Returns:
- ray_candidates ((n,) int) – Triangle indexes 
- ray_id ((n,) int) – Corresponding ray index for a triangle candidate 
 
 
- trimesh.ray.ray_triangle.ray_triangle_id(triangles, ray_origins, ray_directions, triangles_normal=None, tree=None, multiple_hits=True)¶
- Find the intersections between a group of triangles and rays - Parameters:
- triangles ((n, 3, 3) float) – Triangles in space 
- ray_origins ((m, 3) float) – Ray origin points 
- ray_directions ((m, 3) float) – Ray direction vectors 
- triangles_normal ((n, 3) float) – Normal vector of triangles, optional 
- tree (rtree.Index) – Rtree object holding triangle bounds 
 
- Returns:
- index_triangle ((h,) int) – Index of triangles hit 
- index_ray ((h,) int) – Index of ray that hit triangle 
- locations ((h, 3) float) – Position of intersection in space