Minimum oriented bounding box. Implementation in Grasshopper + Python script node

Well, in between end-of-semester bouts of laser cutting, milling and 3D printing, I was able to work on my bounding box script for sometimes a few minutes, sometimes a half hour or so… I finally put a bit of UI on it and I’m going to throw it out here now…

It’s a combined 2D and 3D bounding box tool, it first checks to see if the input objects are planar/coplanar, if yes, it calculates a minimum bounding rectangle, if not, it calculates a 3D box. In both cases it makes an initial rough pass to find the orientation of the smallest starting area (2D) or volume (3D), then refines in successive passes with smaller increments. Each pass is an order of magnitude (10x) smaller than the previous. When the next pass cannot find a better answer than the previous within tolerance, it stops and spits out the result.

It will accept any combination of points, pointclouds, curves, surfaces, polysurfaces and meshes. No blocks, sorry.

I didn’t want to throw in a huge number of options, but there are 3…

  • Standard or fine sampling - applies only to the 3D routine. Standard is 10 samples (9 degree intervals) in all three axes which makes 1000 samples; each refinement is also 1000 samples. Fine sampling is 18 samples (5 degree intervals), so 5832 samples each pass, which will be quite a bit slower. With Standard it zeroes in on a solution reasonably fast, and I’m not sure how many cases will actually benefit from the Fine setting, but I put it in there just in case.

  • StopVal - also for 3D only - you can decide if you want the script to stop after the difference from the preceding pass is within a percentage tolerance (default) or an absolute value. Both are hard coded, the relative is set at 0.01% (one hundredth of one percent) difference from the previous; the absolute uses the file tolerance (which is likely pretty small considering it’s applied to a volume measurement). In general the absolute setting will provoke more passes.

  • ReportIntermediateResults will simply print the intermediate area or volume calculations to the command line, set it to no to turn it off. In any case the final result will be printed.

I’ve tested it in V5 and V6 on a few things here and it seems to work OK without erroring out - haven’t tried on Mac, but I think it should work. Let me know if you find any major (or minor!) problems…

MinimumBoundingBox.py (16.3 KB)

–Mitch

20 Likes