aabb module

class aabb.AABB(limits=None)[source]

Bases: object

Axis aligned bounding box (AABB)

The AABB is a d-dimensional box.

Parameters:limits (iterable, optional) –

The limits of the box. These should be specified in the following manner:

limits = [(xmin, xmax), (ymin, ymax), (zmin, zmax), ...]

The default value is None.

classmethod merge(aabb1, aabb2)[source]

Merge AABB

Find the AABB of the union of AABBs.

Parameters:
  • aabb1 (AABB) – An AABB
  • aabb2 (AABB) – An AABB
Returns:

An AABB that contains both of the inputs

Return type:

AABB

overlaps(aabb)[source]

Determine if two AABBs overlap

Parameters:aabb (AABB) – The AABB to check for overlap
Returns:Flag set to true if the two AABBs overlap
Return type:bool
perimeter

Perimeter of AABB

The perimeter \(p_n\) of an AABB with side lengths \(l_1, ..., l_n\) is:

\[\begin{split}\begin{align} p_1 &= 0 \\ p_2 &= 2 (l_1 + l_2) \\ p_3 &= 2 (l_1 l_2 + l_2 l_3 + l_1 l_3) \\ p_n &= 2 \sum_{i=1}^n \prod_{j=1\neq i}^n l_j \end{align}\end{split}\]
class aabb.AABBTree(aabb=AABB(None), value=None, left=None, right=None)[source]

Bases: object

Python Implementation of the AABB Tree

This is a pure Python implementation of the static d-dimensional AABB tree. It is heavily based on Introductory Guide to AABB Tree Collision Detection from Azure From The Trenches.

Parameters:
  • aabb (AABB) – An AABB
  • value – The value associated with the AABB
  • left (AABBTree, optional) – The left branch of the tree
  • right (AABBTree, optional) – The right branch of the tree
add(aabb, value=None)[source]

Add node to tree

This function inserts a node into the AABB tree.

Parameters:
  • aabb (AABB) – The AABB to add.
  • value – The value associated with the AABB. Defaults to None.
does_overlap(aabb)[source]

Check for overlap

This function checks if the limits overlap any leaf nodes in the tree. It returns true if there is an overlap.

Parameters:aabb (AABB) – The AABB to check.
Returns:True if overlaps with a leaf node of tree.
Return type:bool
overlap_values(aabb)[source]

Get values of overlapping AABBs

This function gets the value field of each overlapping AABB.

Parameters:aabb (AABB) – The AABB to check.
Returns:Value fields of each node that overlaps.
Return type:list
is_leaf

returns True if is leaf node

Type:bool