# Wish for an "Official" Minimal bounding box with multithreading

**URL:** <https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086>\
**Category:** Grasshopper\
**Created:** [December 2, 2019, 10:07pm UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086 "2019-12-02T22:07:22Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![osuire](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/osuire/32/656689_2.png) [@osuire](https://discourse.mcneel.com/u/osuire)\
**Post date:** [December 2, 2019, 10:07pm UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/1 "2019-12-02T22:07:22Z")

</div>

I find that the search for a minimal bounding has many applications like finding a relevant local reference frame for oddly shaped objects.  
There are a few scripts out there, and even a “MinBBox” component which I don’t know who did it because there’s no metadata with this info.

Yet, I find that it should be promoted to an actual “official”, optimized component, with multithreading capabilities because this typically slows my definitions quite a lot.

---

<div class="post-metadata">

**Author:** ![RIL](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ril/32/771758_2.png) [@RIL](https://discourse.mcneel.com/u/RIL)\
**Post date:** [December 2, 2019, 10:20pm UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/2 "2019-12-02T22:20:45Z")

</div>

Is this version fast enough for your usecase? It runs in parallel and is quite “battle tested”. Helvetosaur also have a very good MinBB component (sometimes slightly tighter end result, but only very little) but I use this one for its speed.

[minimalboundingbox-csharp\_R6.gh](https://discourse.mcneel.com/uploads/short-url/doyWtY7eeSgPkiHfLCztoqjTz2c.gh) (96.7 KB)

// Rolf

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [December 2, 2019, 10:38pm UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/3 "2019-12-02T22:38:22Z")

</div>

We\* don’t actually have a 100% reliable algorithm for this. It’s doable for simple shapes with planar convex hulls, but as soon as the hull contains curved regions it becomes a guessing game.

Still, a solution which gets close is probably better than nothing at all.

\* Actually I’ll have to ask if anyone else at McNeel has any ideas.

---

<div class="post-metadata">

**Author:** ![osuire](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/osuire/32/656689_2.png) [@osuire](https://discourse.mcneel.com/u/osuire)\
**Post date:** [December 3, 2019, 8:31am UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/4 "2019-12-03T08:31:04Z")

</div>

Hi Rolf,

Thanks for this.  
I notice that you mesh your Brep before the Min. Bbox component.  
Rhino bounding boxes are sometimes wrong with Polysurfaces, with large chunks protruding out, and the result is more accurate if the Polysurface is meshed.  
Is that why you did that ?

I tested your script against the one I grabbed somewhere, and indeed, yours is faster and more accurate. Thanks a lot !

 ![Better%20and%20faster](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/d/f/df3531a9fa393368c97a3cdc1f49f5fa19d79f41.jpeg)

I see there are other ones out there ; maybe we could organize some kind of competition 😉

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [December 3, 2019, 8:48am UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/5 "2019-12-03T08:48:01Z")

</div>

> [@RIL](#):
>
> Helvetosaur also have a very good MinBB component

I didn’t make a component - just a script which runs in Rhino without GH. And yes, it’s not the fastest because it’s not multithreaded.

---

<div class="post-metadata">

**Author:** ![akilli](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/akilli/32/514967_2.png) [@akilli](https://discourse.mcneel.com/u/akilli)\
**Post date:** [December 3, 2019, 9:33am UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/6 "2019-12-03T09:33:40Z")

</div>

Is this in any way related to the idea of principal axis?

[https://en.wikipedia.org/wiki/Principal\_axis](https://en.wikipedia.org/wiki/Principal_axis)

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [December 3, 2019, 10:41am UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/7 "2019-12-03T10:41:28Z")

</div>

In general the minimal bounding box wouldn’t align with the principal axes, because it is only based on shape, not mass distribution.  
For example, attaching a thin spike to a solid like this would significantly alter the minimal bounding box, but the principal axes wouldn’t change much

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/6/c/6cbae0349c0921d8a90ad339ef2f1a012a272a2a.png)

---

<div class="post-metadata">

**Author:** ![akilli](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/akilli/32/514967_2.png) [@akilli](https://discourse.mcneel.com/u/akilli)\
**Post date:** [December 3, 2019, 10:44am UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/8 "2019-12-03T10:44:55Z")

</div>

Well, there goes that idea.

---

<div class="post-metadata">

**Author:** ![RIL](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ril/32/771758_2.png) [@RIL](https://discourse.mcneel.com/u/RIL)\
**Post date:** [December 3, 2019, 11:34am UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/9 "2019-12-03T11:34:14Z")

</div>

> [@osuire](#):
>
> Rhino bounding boxes are sometimes wrong with Polysurfaces, with large chunks protruding out, and the result is more accurate if the Polysurface is meshed.  
> Is that why you did that ?

I think the conversion was simply because of the better speed after converting to mesh. I get **83ms** for the mesh, while it takes **2.5sec** for the brep (on my 6 core / 12 thread machine).

> [@osuire](#):
>
> maybe we could organize some kind of competition

We were playing around with this quite a bit some time ago so there should be several threads left behind where we were trying different things.

The component I posted above was the end result of attempting to make a parallel C# version of a Python component originally created by Ilja Asanovic (credit where credit is due)\*. At the end of this looong thread you’ll find the posted MinDB component. I also added quite elaborate comments to the code explaining how it does its thing:

> [@Minimum oriented bounding box. Implementation in Grasshopper + Python script node](https://discourse.mcneel.com/t/minimum-oriented-bounding-box-implementation-in-grasshopper-python-script-node/64344/45):
>
> Let us know if you gain better speed with a C# solution. It should be possible to get much better speed with only that little parallel-for enhancement, even with the rest of the code remaining pretty much the same. If I had known Python better (I can only listen to it fluently…) I would have tried to convert your script into some really nasty C# version, but I’m not that Python guy. // Rolf

// Rolf

- Original code by Ilja Asanovic, translated to C# and converted to parallel execution. The info box below can be found if double clicking the component:

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/f/1/f119d9d2c19331d5006a4420504687fd3325dd3c.png)

---

<div class="post-metadata">

**Author:** ![jeffoulet](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jeffoulet/32/499869_2.png) [@jeffoulet](https://discourse.mcneel.com/u/jeffoulet)\
**Post date:** [December 3, 2019, 12:04pm UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/10 "2019-12-03T12:04:14Z")

</div>

Hi all,

I agree, a proper command/GH component would be a great thing!

@DavidRutten: what about this paper: [https://pdfs.semanticscholar.org/a76f/7da5f8bae7b1fb4e85a65bd3812920c6d142.pdf](https://pdfs.semanticscholar.org/a76f/7da5f8bae7b1fb4e85a65bd3812920c6d142.pdf)

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [December 3, 2019, 1:55pm UTC](https://discourse.mcneel.com/t/wish-for-an-official-minimal-bounding-box-with-multithreading/93086/11 "2019-12-03T13:55:45Z")

</div>

It seems to rely on a preexisting 3D convex hull algorithm, and even then only handles points, not smoothly curved brep faces and edges. Did you see the runtimes? between 1 and 10 seconds per shape, and they’re not even that complicated. Also the links in the paper pointing to source and demo are dead by now.

It may well get us 99% of the way there, hard to tell before implementing it.
