dhart.raytracer.IntersectForPoint

dhart.raytracer.IntersectForPoint(bvh: EmbreeBVH, origins: Iterable[Tuple[float, float, float]] | Tuple[float, float, float], directions: Iterable[Tuple[float, float, float]] | Tuple[float, float, float], max_distance: float = -1) List[Tuple[float, float, float] | None]
Cast one or more rays based on input origins and directions

and get the hit point.

To shoot multiple rays from one origin, or cast rays from multiple origins in a single direction, set origins OR directions to a single value. If they are both set to a single value then the ray will be cast as a single ray via CastRay.

Note

Accepts the following configurations:
  1. Single origin, single direction

  2. Multiple origins, multiple directions

  3. Single origin, multiple directions

  4. Multiple origins, single direction

Parameters:
  • origins – A list of origins or the origin point to shoot from

  • directions – A list of directions or the direction to shoot in

  • max_distance – Maximum distance that a ray can travel. Any hits beyond this point are not counted

Returns:

an ordered list containing None where rays did not intersect any geometry

and tuples of 3 floats where the rays did intersect geometry

Return type:

List

Raises:

TypeError – When the passed BVH is invalid

Examples

Cast a single ray straight downwards

>>> from dhart.geometry import LoadOBJ, CommonRotations, ConstructPlane
>>> from dhart.raytracer import EmbreeBVH, IntersectForPoint
>>> loaded_obj = ConstructPlane()
>>> loaded_obj.Rotate(CommonRotations.Yup_to_Zup)
>>> bvh = EmbreeBVH(loaded_obj)
>>> hit_point = IntersectForPoint(bvh, (0,0,1), (0,0,-1))
>>> print(hit_point)
(0.0, 0.0, 5.960464477539063e-08)