In-The-Box:
A Monte Carlo-ish algorithm for calculating the minimum volume bounding box of an arbitrary number of points in 3-space.
Stylianos Dritsas 2004

This small applet was developed for calculating the minimum bounding box of three dimensional objects for rapid prototyping purposes; namely subtractive prototyping techniques, such as CNC milling. So, essentially the goal was to minimize the time, waste and cost of milling a three dimensional objects out of solid blocks of material.

The default bounding boxes provided by CAD software are usually aligned to the global coordinate system's planes (a.k.a. axis aligned bounding boxes, or aabb for short). Aabbs are generic and do not take in consideration the actual geometry but simply calculate the minimum and maximum coordinates of the contained points.

While it is not very difficult to create a better solution by manually creating a box aligned about the axis defined by the most distant points (diameter of the point collection), it turns out that analytically calculating the minimum volume bounding box of an arbitrary number of 3d points is not a trivial task.

For this reason, I picked up a randomized heuristic approach based on the paradigm of the evolutionary computation. The applet essentially creates bounding boxes randomly, evaluates their volume and blends their orientation to reach a satisfactory solution. Each box is defined by two perpendicular vectors. A third one is produced as the cross product of the previous pair. All three vectors are used as normals of the box's planes. The planes are tightened on the point collection and the volume of the box is calculated. The vector pairs of the most fit boxes are blended and randomly mutated and the process is repeated until its termination.

You can use the applet by importing point coordinates from a comma/space delimited text file (exported from your favorite CAD application). The applet recognizes sequences of real numbers (dot notation for fractional part) separated by spaces of commas. All other alphabetic characters may produce errors. Paste the point coordinates in the text area and hit process. Alternatively, you can evolve one of the demo configurations. Once you get it going you can always restart and stop it by the same button. If you actually want to use the best box, you can hit the export button, select all the contents of the text area and paste them in a plain text editor. Save the file with (*.stl) extension and import the file in a CAD app.

A Minimal Example
This example illustrates the problems of using axis aligned bounding boxes. Three points are placed on the xy plane and a fourth is stretched across diagonally. Both the bounding sphere (in blue) and aabb ( in green) produce absurd volumes compared to the mvbb (in red).

Boxing a Cube
The second example shows the convergence of the randomized algorithm to a visually identifiable solution by attempting to find the mvbb of a cube's peaks. You would expect that the algorithms rests faster than usual but in this case the symmetry of the cube keeps the population alive for a while. This example also shows the numeric error of the volume calculation process (the volume drops a little bit off the aabb's volume).

Infinite Sphere?
The last example was added for showing that the bounding sphere is not always the worse bounding object you get but also for driving nuts the algorithm by giving it a problem with an infinite number of solutions. While this was the initial hope I observed that the boxes tended to calm down after a while, giving a volume, substantially lower than the aabb's. After checking the code for numeric errors (and going nuts) I figured out that this happened because while the input points were on a sphere, they didn't actually describe a perfect sphere; so the algorithm just found these gaps and produced tighter boxes!