AxisAlignedBoundingBox.trace

giant.ray_tracer.shapes.axis_aligned_bounding_box:

AxisAlignedBoundingBox.trace(self, rays, return_distances=False)

This python method traces multiple rays with the AABB and returns the results as a boolean array (True if intersected) as well as the minimum and maximum distance to the intersect for each ray (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 rays are 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 rays 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 intersect distance. The results are returned as 1 or 2 numpy arrays, where the first is a boolean array with True for each element where the corresponding ray struck the surface and False otherwise and the optional second (if return_distances=True) is a 2D 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 corresponding element in the hit check array (the first return) is True.

Parameters:

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

Returns:

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

Return type:

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