AxisAlignedBoundingBox

giant.ray_tracer.shapes.axis_aligned_bounding_box:

class giant.ray_tracer.shapes.axis_aligned_bounding_box.AxisAlignedBoundingBox(self, min_sides, max_sides, _rotation=None)

This class provides an efficient implementation of an axis aligned bounding box.

An axis aligned bounding box is defined by 6 floats plus a rotation. The first 3 floats specify the minimum values of the contained data for each axis (x, y, z) while the second 3 specify the maximum values for each axis. The rotation defines the rotation from the current frame to the original frame the bounding box was built for, since the axis aligned bounding box is only valid in the original frame.

The benefit to using an axis aligned bounding box is that it is very efficient to check intersection with a ray, which makes it a good choice for building acceleration structures (as is done in the KDTree).

Typically a user doesn’t create an AABB by themselves, especially since an AABB is not actually renderable (that is, you can’t use it as a target in a scene). Instead, each object has its own bounding_box attribute which is used internally by the ray tracer.

To trace the bounding box, simply use the compute_intersect() or trace() methods. These will check whether the provided rays hit the bounding box, as well as the minimum/maximum distance from the ray origin that the intersection occurs at (if requested). Note that this is different than other shapes in the ray tracer, hence why it can’t be used for rendering.

Additionally, users may find use for the vertices attribute. This gives the 8 vertices of the corners of the AABB in the current frame, which can be useful for determining which pixels actually need to be traced for a given object.

Parameters:
  • min_sides (ARRAY_LIKE) – A length 3 array specifying the minimum values for each axis.

  • max_sides (ARRAY_LIKE) – A length 3 array specifying the maximum values for each axis.

  • _rotation (Optional[Rotation]) – The current rotation of the bounding box (primarily used for pickling/unpickling)

max_sides

The maximum axes of the axis aligned bounding box in the translated (but not rotated) frame as a numpy array of length 3 [x, y, z] as double numpy array.

min_sides

The minimum axes of the axis aligned bounding box in the translated (but not rotated) frame as a numpy array of length 3 [x, y, z] as double numpy array.

vertices

This property provides the vertices of the bounding box in the current frame (rotated/translated) as a double numpy array.

The vertices are returned as an array of shape 3x6 where each column represents a new vertex. column 0 is the origin (min) of the AABB, column 1 is +x, column 2 is +y, column 3 is +z, column 4 is +xy, column 5 is +yz, column 6 is +xz, and column 7 is +xyz.

This is done by a call to min_max_to_bounding_box() and then rotating into the current frame using the _rotation attribute.

Summary of Methods

compute_intersect

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).

rotate

This method is used to rotate the axis aligned bound box.

trace

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).

translate

This method translates the AABB.