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

Which one? There are several Minimal BoundingBox components in this thread, both Python script and C#. They are compared for their different benefits.

You might want to read the whole thread to find out.

// Rolf

1 Like

Hi @RIL

Thanks for your reply. Sorry for the confusion. I thought my post was made as a reply to the post above by Mathias Sรธnderskov Schaltz, but looks like it isnโ€™t.

I did read through the whole thread, and ended up choosing Mathiasโ€™s solution to see if it worked. However, I found that his component has the same problem that was observed about the others: it consumes a lot of computing power, sometimes taking 15 minutes to resolve (I am working with hundreds of framing members at a go), and even crashing Rhino multiple times. (His component also doesnโ€™t preserve data structure of inputs in the output, as far as I can tell.)

This heavy computation is why I am pursuing a simplified script, instead of one of the solutions shared above. Because I donโ€™t need the geometric flexibility of a full-blown minimum oriented bounding box scriptโ€“in other words, because I know all the inputs will be generally long and skinny wooden members with a variety of notches and angled short endsโ€“I can avoid all the computation by going straight to a GetBoundingBox (plane) using a plane derived from one of the long sides of a member.

The ultimate goal is an axial centerline for each member, in this case derived from a line drawn between the centroids of the two short ends of the bounding box.

See my attached script for the current state of my attempt. I am implementing this in a GhPython component in Grasshopper in Rhino 7. Seems to be working, but I was looking for feedback on my approach. My next step is to integrate a nested dictionary so that I can associate the output centerlines with their input layer, and remake the script to receive breps from multiple layers. Then I can process all the different framing members, which are all on separate layers, with one script, and output the centerlines into a data tree in GH (or a grafted list) where each branch is associated with the layer those centerlines were derived from. Maybe this is done with a headingโ€“each branch index 0 is the layer name. Not sure yet.

Python script
24 0130 OrientedBoundingBoxForFramingMembers.py (5.3 KB)
GH file
24 0131 OrientedBoundingBoxForFramingMembersTestingPythonScripts.gh (13.2 KB)

Best

Brian

Hello everyone and thank you for all these interesting insights.
Below is my 2cents on this discussion.

:light_bulb: ๐—ง๐—ต๐—ฒ ๐—ฆ๐—ผ๐—น๐˜‚๐˜๐—ถ๐—ผ๐—ป ๐—œ ๐——๐—ฒ๐˜ƒ๐—ฒ๐—น๐—ผ๐—ฝ๐—ฒ๐—ฑ
My implementation in the ATk MinBBox component uses a multi-strategy approach:

  • Principal Component Analysis for initial orientation estimates
  • Special case detection for geometric primitives (triangles, rectangles, trapezoids)
  • Advanced angle-space optimisation algorithms
  • Intelligent caching of previous calculations

The results have been validated: when compared to other available components, ATk MinBBox consistently offers an excellent balance between computation speed and minimum volume optimisation.

๐—œ๐˜€ ๐—ถ๐˜ ๐˜๐—ต๐—ฒ ๐—ฏ๐—ฒ๐˜€๐˜ ๐—ฝ๐—ผ๐˜€๐˜€๐—ถ๐—ฏ๐—น๐—ฒ ๐˜€๐—ผ๐—น๐˜‚๐˜๐—ถ๐—ผ๐—ป ๐—ฒ๐˜ƒ๐—ฒ๐—ฟ? ๐— ๐—ฎ๐˜†๐—ฏ๐—ฒ ๐—ป๐—ผ๐˜ :sweat_smile: Computational geometry is a field where perfection is elusive. But for my practical architectural needs, it represents the right compromise between theoretical optimisation and real-world usability.

This new component will be included in the upcoming ATk v1.3.3 release, and I will share more info about it.

[UPDATE] read more tech in-depth details here: Minimum Bounding Box (MinBBox) and Minimum Bounding Sphere (MinBSph) included in ATk v1.3.3 | lucianoambrosini.it



3 Likes

Given that you are going to share a working solution to the problem, I think it would have made more sense to start your own topic and post links to your topic in repliesโ€ฆ

Hello Martin, Thank you for your suggestionโ€”I will certainly follow it, maybe on the personal channel.

However, I would like to emphasize that the primary function of the forum and discussion is to inform the community interested in a given topic about developments over time. This discussion is a clear example of that, especially when solutions that can be tested for free are shared.

Opening multiple topics on the same subject is generally not well received by moderators and can reduce the forumโ€™s usability. For this reason, I chose to add my contribution to the existing discussion rather than start a new thread.

Nonetheless, I appreciate your suggestion.

Stay in the loop!
L.A.

P.S.:
It has been quite some time since I last contributed to the forum, and now I remember why :sweat_smile:โ€ฆ Did you really go through all my posts to support your latest answer? My gosh :blush:

That said, if I did provide the same answer, questions in the thread address two issues: one pertains to the implementation Grasshopper, while the other the most effective method or tool for determining the minimum bounding box for solids. If two questions result in the same answer, the issue not with the response but the existence of similar threads that have not been merged, reinforcing my earlier point about forum usability and consolidating answers within a single thread.

I responded here using a single post because it would be disappointing if this meaningful discussion devolved into akin to Facebook (I tend to avoid such situations).

Wishing you all the best :wink:
โ†“โ†‘

The same content in two posts can lead to two parallel discussions which I think should be avoided.

Anyway, have a nice day.

Hi @RIL , nice piece of code when no external addons can be used, still works after all these years and fast :wink: Thanks for sharing

have been trying to add a boolean toggle to control how it handles multiple input geometries.

The goal is to have two modes:

  • Toggle is false: The script calculates a minimal box for each piece of geometry individually (a list in gives a list out).
  • Toggle is true: The script calculates a single minimal box that encloses all the input geometries combined.

With the assistance of AI, I try to get the minimal box for each object and then try to find a new minimal box that encloses the corner points of all those individual boxes. However, I keep getting stuck in a loop of compiler errors, .

Has anyone successfully implemented a robust script like this or have any advice on a better approach?

I attach you latest version in rhino 8 C# node

minimalboundingbox-py2csharp_R6_rhino8.gh (604.8 KB)

edit: come to think about it > maybe just putting all geometry in a group might work .. or in the case of breps and just mesh, convert them to simple mesh and the join them to be one object.. not behind computer to check

Iโ€™m a little short on time right now, but for the box enclosing a group I think meshing into a group would be the fastest.

When I have the time Iโ€™ll try to add parallel processing of individual Breps from an input list. Shouldnโ€™t be a big deal.

as for me I prefer using human intelligence. :wink:

//Rolf