Randomly populate objects inside an area, with no intersections

Hi everyone,
I would like to randomly distribute multiple objects inside specified areas without having any intersecting objects. (randomly scale and rotate these objects is optional)
The final result should be like a stone paved road.
I am relatively new to grasshopper. reading and testing files from similar posts didn’t helped me much.
In the attached gh file you can see my progress so far.
If you could help me solve this issue or point me to the right direction, I would be grateful.

test.gh (17.1 KB)

Hello
Did you have a look to wordle in Nautilus plugin ?

1 Like

You didn’t search enough but sometimes using the search engine on discourse is not the best. I like to use google with key word like “site:https://discourse.mcneel.com/ keywors …”



test (3) LD.gh (10.4 KB)

1 Like

Thank you for your quick reply and solution to my problem.

I made a little error I forgot to put angle in degree so most of rotations are not well distributed.

If the pattern is not full you can augment trys (number of trys)


If you play with these options you could have that (360 pieces of each pieces are first added then the others …


You could jitter to randomize the list

Packing density is around 66% with 2000 pixels
Packing density is around 60% with 500 pixels

2 Likes

The packing density of @laurent_delrieu’s solution is very impressive! Must be a different algorithm than just filtering overlapping curves? Curious how it works but not curious enough to install his plugin. Is it fast?

Reminded me of an old thread here:

I started yesterday to adapt it to your code but it’s slow and @laurent_delrieu’s results are better. Still, it’s interesting enough that I resumed tinkering this morning. It got complicated.


cull_crvs_2023Dec5a.gh (42.0 KB)

The green group is an Anemone loop to filter out overlapping shapes. I used a low ‘Count’ value (5) to speed up the debug process and focused first on only the small square on the right, using the small yellow group to work with only one branch at a time. The gray group handles the special case where one shape completely engulfs another without intersecting.

I tried a variety of methods for maximum speed, including RUnion (Region Union). It returns one result when two shapes intersect or one “engulfs” the other, or one result when they don’t. Effective but slow.

Later I added a second loop (large light yellow group) to traverse all branches, passing one at a time to the first loop in the green group. And a Value List (white group) to switch between “All branches” and “One branch”. Using a ‘Count’ value of 30, the profiler shows ~16 seconds for the small square and 1.7 minutes for the large rectangle.

Using a ‘Count’ value of 130, the profiler shows close to six minutes for the large rectangle!

NOTE: There is a ‘min_sep’ slider that adjusts the space between filtered shapes.

1 Like

Hello Joseph,
the principle is simple. Everything is transformed to mesh then to bolean Pixels. A big matrix for the sheet. And more little matrices for the shapes.
So for less than 1 million pixels and 1 million of tests it takes ~10 seconds.
here the outputs with pixels not touched.


Source there

If you want to write another recursive tool and if you have Clipper installed you could use Minkowski difference

1 Like

WOW :exclamation: I don’t understand at all but am extremely impressed. A worthy reason to use a plugin, if I need to do something like that. Thanks for explaining.

1 Like

Hello, I’ve enjoyed reading this thread and plugging in my own files into the script. I was hoping I could get some guidance on a way to populate the region with a designated percentage of each shape, eg. 30% largest, 10% medium etc… would it be best to tweak the script in this thread or to make a new one to achieve visually similar results?

Hello, it is surely better to make a new thread with reference to this one.