differt.rt.first_triangles_hit_by_rays

differt.rt.first_triangles_hit_by_rays#

first_triangles_hit_by_rays(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 rays_intersect_triangles.

Parameters:
  • ray_origins (Float[ArrayLike, '*#batch 3']) – An array of origin vertices.

  • ray_directions (Float[ArrayLike, '*#batch 3']) – An array of ray direction. The ray ends should be equal to ray_origins + ray_directions.

  • triangle_vertices (Float[ArrayLike, '*#batch num_triangles 3 3']) – An array of triangle vertices.

  • active_triangles (Bool[ArrayLike, '*#batch num_triangles'] | None) –

    An optional array of boolean values indicating which triangles are active, i.e., should be considered for intersection.

    If not specified, all triangles are considered active.

  • batch_size (int | None) –

    The number of triangles to process in a single batch. This allows to make a trade-off between memory usage and performance.

    The batch size is automatically adjusted to be the minimum of the number of triangles and the specified batch size.

    If None, the batch size is set to the number of triangles.

  • kwargs (Any) – Keyword arguments passed to rays_intersect_triangles.

Return type:

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

Returns:

For each ray, return the index and to distance to the first triangle hit.

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