differt.rt.first_triangle_hit_by_ray

differt.rt.first_triangle_hit_by_ray#

first_triangle_hit_by_ray(ray_origins, ray_directions, triangle_vertices, active_triangles=None, batch_size=512, **kwargs)[source]#

Return the first triangle hit by each ray.

This function should be used when allocating an array of size *batch num_triangles 3 (or bigger) is not possible, and you are only interested in getting the first triangle hit by the ray.

If two or more triangles are hit at the same distance, the one with the closest center to the ray origin is selected. Two triangles are considered to be hit at the same distance if their distances differ by less than 100 * eps, or ten times the epsilon keyword argument passed to ray_intersect_triangle.

Note

This function has a faster and more memory-efficient equivalent method: TriangleMesh.first_triangle_hit_by_ray, as long as smoothing is not required.

Parameters:
Return type:

tuple[Int[Array, '*batch'], Float[Array, '*batch']]

Returns:

Index of and distance to the first triangle hit by each ray.

If no triangle is hit, the index is set to -1 and the distance is set to inf.