Skip to content

Axis-Aligned Bounding Box

AABB(p_min, p_max)

Axis Aligned Bounding Box in n dimensions.

Parameters:

Name Type Description Default
p_min Iterable

minimal values for each dimension

required
p_max Iterable

maximal values for each dimension

required

Raises:

Type Description
Exception

fails if p_min and p_max have different sizes (inconsistent dimension)

center: Vec property

Coordinates of the center point

Returns:

Name Type Description
Vec Vec

center point

dim: int property

Dimension of the axis-aligned bounding box

Returns:

Name Type Description
int int

dimension

maxi: Vec property

Maximum coordinates of any point inside the box. The box is an axis-aligned hexahedron which opposite corners are mini and maxi

Returns:

Name Type Description
Vec Vec

maximum coordinates

mini: Vec property

Minimum coordinates of any point inside the box The box is an axis-aligned hexahedron which opposite corners are mini and maxi

Returns:

Name Type Description
Vec Vec

minimum coordinates

span: Vec property

Dimensions of the box

Returns:

Name Type Description
Vec Vec

dimensions of the box

contains_point(pt)

Point - bounding box intersection predicate. If the point is on the boundary of the box, the convention is as follows: inclusive if the point touches the min coordinates, exclusive for the max coordinates

Parameters:

Name Type Description Default
pt Vec

a query position

required

Raises:

Type Description
IncompatibleDimensionError

fails if the point has a different dimension than the bounding box.

Returns:

Name Type Description
bool bool

whether the point 'pt' is inside the bounding box.

distance(pt, which='l2')

Computes the distance from a point to the bounding box.

Parameters:

Name Type Description Default
pt Vec

coordinates of the point

required
which str

which distance to consider. Choices are 'l2', 'l1' or 'linf'. Defaults to "l2".

'l2'

Raises:

Type Description
IncompatibleDimensionError

fails if the point has a different dimension than the bounding box.

Returns:

Name Type Description
float float

the distance from the point to the bounding box

do_intersect(b1, b2) staticmethod

Intersection test between two bounding boxes

Parameters:

Name Type Description Default
b1 AABB

first bounding box

required
b2 AABB

second bounding box

required

Raises:

Type Description
IncompatibleDimensionError

fails if b1 and b2 have different dimensions

Returns:

Name Type Description
bool bool

whether the two BB intersect

infinite(dim) classmethod

Computes a bounding box with bounds at infinity, containing the whole space R^n

Parameters:

Name Type Description Default
dim int

dimension of the BB to build

required

Returns:

Name Type Description
AABB AABB

A bounding box containing all of R^n

intersection(b1, b2) staticmethod

Computes the intersection bounding box of two bounding boxes

Parameters:

Name Type Description Default
b1 AABB

first bounding box

required
b2 AABB

second bounding box

required

Raises:

Type Description
IncompatibleDimensionError

fails if b1 and b2 have different dimensions

Returns:

Name Type Description
AABB AABB

a bounding box representing the intersection (may be empty).

is_empty()

Tests if the bounding box encloses an empty domain

Returns:

Name Type Description
bool bool

whether the bounding box is empty

of_mesh(mesh, padding=0.0) classmethod

Computes the 3D bounding box of all vertices of a mesh

Parameters:

Name Type Description Default
mesh Mesh

input mesh. Can be of any type (only the 'vertices' container is accessed)

required
padding float

slack to be added between the mesh and the box. Defaults to 0 for a tight bounding box.

0.0

Returns:

Name Type Description
AABB AABB

3D bounding box of the vertices of the mesh

of_points(points, padding=0.0) classmethod

Computes the bounding box of a set of nD points.

Parameters:

Name Type Description Default
points ndarray

input points

required
padding float

slack to be added between the mesh and the box. Defaults to 0 for a tight bounding box.

0.0

Returns:

Name Type Description
AABB AABB

nD bounding box of the points

pad(pad)

Enlarges the bounding box by adding pad on each dimension on each side. Does nothing if the padding values are negative.

Parameters:

Name Type Description Default
pad float | iterable

Additional dimensions to be added. If a float is provided, will assume that padding is the same for each dimensions. If an array is provided, its size should match the dimension of the box. Values are clamped to be >=0.

required

project(pt)

Computes the closest point from point 'pt' in the bounding box in Euclidean distance

Parameters:

Name Type Description Default
pt Vec

the point to project

required

Raises:

Type Description
IncompatibleDimensionError

fails if the point has a different dimension than the bounding box.

Returns:

Name Type Description
Vec Vec

the projected point

union(b1, b2) staticmethod

Computes the union bounding box of two bounding boxes

Parameters:

Name Type Description Default
b1 AABB

first bounding box

required
b2 AABB

second bounding box

required

Raises:

Type Description
IncompatibleDimensionError

fails if b1 and b2 have different dimensions

Returns:

Name Type Description
AABB AABB

a bounding box representing the union

unit_cube(dim, centered=False) classmethod

Computes the unit bounding box [0,1]^n or [-0.5, 0.5]^n

Parameters:

Name Type Description Default
dim int

dimension of the BB to build

required
centered bool

whether to generate [0,1]^n (False) or [-0.5;0.5]^n (True). Defaults to False.

False

Returns:

Name Type Description
AABB AABB

a hypercube of side length 1