AxisAlignedBoundingBox.compute_intersect

giant.ray_tracer.shapes.axis_aligned_bounding_box:

AxisAlignedBoundingBox.compute_intersect(self, ray, return_distances=False)

This python method traces a single ray with the AABB and returns the results as a boolean value (True if intersected) as well as the minimum and maximum distance to the intersect as a length 2 double numpy array (if requested).

This is done by making a call to the c version of this method.

If this box has been rotated a copy of the ray is first rotated into the box’s frame and then traced (because AABB only works when it is in the original frame). Once we have the ray in the AABB frame, we then use the equations from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection to both check if the bounding box is intersected, and to get the minimum and maximum intersect distance. The results are returned as a boolean and optionally a numpy array, where the first is True when the ray struck the surface and False otherwise and the optional second (if return_distances=True) is a length 2 array of doubles where the first column has the closest intersect distance, and the second column has the further intersect distance. These numbers are only valid when the first return is True.

Parameters:

ray (Rays) – The ray to trace through the bounding box.

Returns:

The boolean value whether the ray hit the bounding box and optionally the length 2 double array containing the near/far distance of the intersect for the ray (only valid when the ray actually hits the box)

Return type:

Union[bool, Tuple[bool, np.ndarray]]