# 11. minimalBoundingBox Python plugin

`minmimalBoundingBox` is a pure Python plugin built with CloudComPy.

This tool is provided as an example of CloudComPy pure Python extension.

The `findRotation` function finds a minimal bounding box, not oriented along the main axes, and the corresponding rotation. It is not proven that the solution meets to the minimum, and the performance and robustness can certainly be improved.

cloudComPy.minimalBoundingBox.dist2(a, b)

Euclidian square distance between two 3D points

cloudComPy.minimalBoundingBox.findRotation(cloud)

Finds the point cloud rotation that minimize the bounding box (built on Ox, Oy, Oz).

warning the cloud is supposed centered (bounding box center near the origin) TODO: test for robustness, add parameters to control the accuracy…

Parameters

cloud (ccPointCloud) – the point cloud

Returns

bounding box after rotation, inverse rotation, polyline defining the optimal bounding box of the point cloud, polyline cloud

Return type

tuple of 4 objects

cloudComPy.minimalBoundingBox.isocahedron()

isocahedron: defines 12 nodes equally distributed on the sphere. For each node, we keep the neighbours. The sphere is normalised.

Returns

the 12 nodes (tuple) and a dictionary of the neighbours indices for each node index

Return type

tuple

cloudComPy.minimalBoundingBox.section(x, cl)

Optimise the object bounding box section by oz rotation

Parameters
• x (tuple) – one test value for rotation along oz

• cl (ccPointCloud) – point cloud

Returns

bounding box x*y section, to minimise

Return type

float

cloudComPy.minimalBoundingBox.zinv(x, i1, i2, i3, cl, isoNodes)

optimization function: maximize the z of object bounding box by adjusting rotation. 3 neighbours points on the normalized isocahedron defines a starting point and 2 directions: starting point: rotation defined by i1, direction 1: geodesic defined by points i1, i2, direction 2: geodesic defined by points i1, i3,

Param

tuple x: 2 test values for rotations along the 2 directions

Parameters
• i1 (int) – index of the starting point in isocahedron

• i2 (int) – index of in isocahedron (i1,i2 define the geodesic of first direction)

• i3 (int) – index of in isocahedron (i1,i3 define the geodesic of second direction)

• cl (ccPointCloud) – point cloud

• isoNodes (tuple) – the 12 points of the normalised isocahedron

Returns

opposite of the z dimension of the bounding box after rotation (value to minimise)

Return type

float