Skip to content

Bounding Boxes¤

compas_model.geometry.bbox ¤

Functions:¤

aabb_from_points ¤

aabb_from_points(points: Iterable[Point]) -> Box

Compute an axis-aligned bounding box from points.

Parameters:

Returns:

  • Box –

    The axis-aligned bounding box. Degenerate boxes are permitted for planar, linear, and single-point inputs.

Raises:

combine_aabbs ¤

combine_aabbs(boxes: list[Box]) -> Box

Combine multiple axis-aligned bounding boxes into a single axis-aligned bounding box.

Parameters:

  • boxes (list[Box]) –

    A list of axis-aligned bounding boxes.

Returns:

  • Box –

    The combined axis-aligned bounding box.

combine_obbs ¤

combine_obbs(boxes: list[Box]) -> Box

Combine multiple oriented bounding boxes into a single oriented bounding box.

Parameters:

  • boxes (list[Box]) –

    A list of oriented bounding boxes.

Returns:

  • Box –

    The combined oriented bounding box.

pca_box ¤

pca_box(points: Iterable[Point]) -> Box

Compute an oriented bounding box for the given points based on the principle components of the XYZ coordinates.

Parameters:

Returns:

  • Box –

    The oriented bounding box.

See Also
Notes

The resulting box is not (necessarily) a minimum bounding volume. The box is computed by reprojecting the points onto the principle component vectors to identify the box extents. The origin of the box is found as the centroid of the points, corrected with the box extents.

Examples:

>>> import random
>>> import math
>>> from compas.geometry import Pointcloud
>>> from compas.geometry import Translation, Rotation
>>> from compas_model.geometry import pca_box

Construct a cloud of points.

>>> cloud = Pointcloud.from_bounds(8, 3, 1, 53)

Construct a random translation.

>>> vector = [10 * random.random(), 10 * random.random(), 10 * random.random()]
>>> T = Translation.from_vector(vector)

Construct a random rotation.

>>> axis = [random.random(), random.random(), random.random()]
>>> angle = math.radians(random.random() * 180)
>>> R = Rotation.from_axis_and_angle(axis, angle)

Transform the cloud and compute its PCA box.

>>> cloud.transform(T * R)
>>> box = pca_box(cloud)

Check.

>>> all(box.contains_point(point) for point in cloud)
True