# 1.4. Spatial Acceleration¶

class raysect.core.boundingbox.BoundingBox2D

Axis-aligned 2D bounding box.

Parameters: lower (Point2D) – (optional) starting point for lower box corner upper (Point2D) – (optional) starting point for upper box corner
contains()

Returns true if the given 2D point lies inside the bounding box.

Parameters: point (Point2D) – A given test point. boolean
extend()

Enlarge this bounding box to enclose the given point.

The resulting bounding box will be larger so as to just enclose the existing bounding box and the new point. This class instance will be edited in place to have the new bounding box dimensions.

Parameters: point (Point2D) – the point to use for extending the bounding box. padding (float) – optional padding parameter, gives extra margin around the new point.
extent()

Returns the spatial extend of this bounding box along the given dimension.

Parameters: axis (int) – specifies the axis to return, {0: X axis, 1: Y axis}. float
largest_axis()

Find the largest axis of this bounding box.

Returns: an int specifying the longest axis, {0: X axis, 1: Y axis}. int
largest_extent()

Find the largest spatial extent across all axes.

Returns: distance along the largest bounding box axis. float
lower

The point defining the lower corner of the bounding box.

Return type: Point2D
pad()

Makes the bounding box larger by the specified amount of padding.

Every bounding box axis will end up larger by a factor of 2 x padding.

surface_area()

Returns the surface area of the bounding box.

Return type: float
union()

Union this bounding box instance with the input bounding box.

The resulting bounding box will be larger so as to just enclose both bounding boxes. This class instance will be edited in place to have the new bounding box dimensions.

Parameters: box (BoundingBox2D) – A bounding box instance to union with this bounding box instance.
upper

The point defining the upper corner of the bounding box.

Return type: Point2D
vertices()

Get the list of vertices for this bounding box.

Returns: A list of Point2D’s representing the corners of the bounding box. list
class raysect.core.boundingbox.BoundingBox3D

Axis-aligned bounding box.

Represents a bounding box around a primitive’s surface. The points defining the lower and upper corners of the box must be specified in world space.

Axis aligned bounding box ray intersections are extremely fast to evaluate compared to intersections with more general geometry. Prior to testing a primitives hit() method the hit() method of the bounding box is called. If the bounding box is not hit, then the expensive primitive hit() method is avoided.

Combined with a spatial subdivision acceleration structure, the cost of ray- primitive evaluations can be heavily reduced (O(n) -> O(log n)).

For optimal speed the bounding box is aligned with the world space axes. As rays are propagated in world space, co-ordinate transforms can be avoided.

Parameters: lower (Point3D) – (optional) starting point for lower box corner upper (Point3D) – (optional) starting point for upper box corner
centre

The point defining the geometric centre of the bounding box.

Return type: Point3D
contains()

Returns true if the given 3D point lies inside the bounding box.

Parameters: point (Point3D) – A given test point. boolean
enclosing_sphere()

Returns a BoundingSphere3D guaranteed to enclose the bounding box.

The sphere is centred at the box centre. A small degree of padding is added to avoid numerical accuracy issues.

Returns: A BoundingSphere3D object. BoundingSphere3D
extend()

Enlarge this bounding box to enclose the given point.

The resulting bounding box will be larger so as to just enclose the existing bounding box and the new point. This class instance will be edited in place to have the new bounding box dimensions.

Parameters: point (Point3D) – the point to use for extending the bounding box. padding (float) – optional padding parameter, gives extra margin around the new point.
extent()

Returns the spatial extend of this bounding box along the given dimension.

Parameters: axis (int) – specifies the axis to return, {0: X axis, 1: Y axis, 2: Z axis}. float
full_intersection()

Returns full intersection information for an intersection between a ray and a bounding box.

The first value is a boolean which is true if an intersection has occured, false otherwise. Each intersection with a bounding box will produce two intersections, one on the front and back of the box. The remaining two tuple parameters are floats representing the distance along the ray path to the respective intersections.

Parameters: ray – The ray to test for intersection A tuple of intersection parameters, (hit, front_intersection, back_intersection). tuple
hit()

Returns true if the ray hits the bounding box.

Parameters: ray (Ray) – The ray to test for intersection. boolean
largest_axis()

Find the largest axis of this bounding box.

Returns: an int specifying the longest axis, {0: X axis, 1: Y axis, 2: Z axis}. int
largest_extent()

Find the largest spatial extent across all axes.

Returns: distance along the largest bounding box axis. float
lower

The point defining the lower corner of the bounding box.

Return type: Point3D
pad()

Makes the bounding box larger by the specified amount of padding.

Every bounding box axis will end up larger by a factor of 2 x padding.

surface_area()

Returns the surface area of the bounding box.

Return type: float
union()

Union this bounding box instance with the input bounding box.

The resulting bounding box will be larger so as to just enclose both bounding boxes. This class instance will be edited in place to have the new bounding box dimensions.

Parameters: box (BoundingBox3D) – A bounding box instance to union with this bounding box instance.
upper

The point defining the upper corner of the bounding box.

Return type: Point3D
vertices()

Get the list of vertices for this bounding box.

Returns: A list of Point3D’s representing the corners of the bounding box. list
volume()

Returns the volume of the bounding box.

Return type: float