Hello
There is an algorithm I want to do, but I can’t find it no matter how much I search.

I want to randomly place various size and number of module boxes inside a huge bounding box.

condition

1. The module box must not protrude outside the bounding box.
2. Module boxes must not overlap each other.
3. I want the module box to be evenly distributed within the bounding box.

I can’t think of a way to achieve this with native GH. You will most likely need coding. Let me summon @laurent_delrieu maybe if he sees this he might be able to help. I know he has made something similar in the past, at least in 2D.

I am thinking that a shortcut might be to just pack your modules inside the Bbox so that they completely fill it (you can do this by hand), and then use Reduce to just erase some randomly.

In this case it becomes a matter of packing boxes inside another box, which should be quite trivial in code. Still I can’t code you an example because I wouldn’t know how

1 Like

Hello
@Nike03 2 first rules are easy and clear. The 3rd is not clear. Define Evenly for Boxes of various size. Do you intend to have a center of Gravity at the center of bounding box, will you look to inertia … Does the bow are centered or they can touch the bounding box.

Inertia could be useful to find the more evenly places. But you need first find which inertia is best.
If goal inertia is low => box are centered
if too high => box are on borders

Surely Kangaroo could be used with springs.

Module box could be inflated then packed then de-inflated. PackRat could be used to do that.

2 Likes

Thanks for tagging. I need to study some more.

Yes. The curves and surfaces of the module box are touchable to the bounding box.

'Do you intend to have a center of Gravity at the center of bounding box, will you look to inertia … ’
I don’t understand this sentence because my Grasshopper’s level is low.

Before thinking with grasshopper think about the algorithm constrains goals …
My Best guess is that you offset the boxes pack them and de offset them. It must be a good way.

I’m sorry, but can you make an example file?

PackRat, which @laurent_delrieu suggested is a plug-in, which has a paid version. Have you checked it? It does exactly what you need.

populate boxes.gh (30.6 KB)

I quickly arranged a mock up for you if you are still very new in GH. It is far from perfect, you need to fiddle around with the random Seed and Count to get good results.

As the placing is entirely random, many boxes get deleted because they intersect. The advantage of using a coded solution is that you can make use of iteration and optimize the placing of your cubes inside the volume. That is called packing.

This is what packing algorithms looks like.

If you can pack them all very close to each other, then it is only a matter of scaling them from center to separate them.

I PACKED THEM HERE BY HAND AS AN EXAMPLE.

scale from center.gh (158.3 KB)

Hope this helps,
Good luck!

2 Likes