pca_box
- compas_model.geometry.pca_box(points)
Compute an oriented bounding box for the given points based on the principle components of the XYZ coordinates.
- Parameters:
- pointslist[
compas.geometry.Point
] A list of 3D points.
- pointslist[
- Returns:
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