Randomized distance between boxes

Hi dear Grasshopper enthusiasts, I am a beginner and I am trying to create a simple definition to scatter parametric boxes along a curve. The problem that I have is that I would like to space them different random distances without them colliding into each other, but I cant seem to find a way to do it. I managed to space them a set distance without them overlapping, but cant generate the same with a series of random spaing between the boxes (I run in a recursive error since my spacing logic is tied to the box sizes).

Sharing below an image of the test and my own definition.

Would greatly appreciate the help :slightly_smiling_face: Thanks
Base definition.gh (11.1 KB)


You didn’t internalize your curve. Given a curve of the right size and shape, your code seems to work well enough?

Seems to me that I’ve done this sort of thing many times on this forum but can’t seem to find them now… Found this from 8.5 years ago using nested Anemone loops. Cool but different:


RecursiveBrick_2016_Jan2b.gh (25.2 KB)

And this one, which is something very different but also uses Anemone:

Too lazy to do it again today, sorry.

1 Like

This is still your code with minor changes and my internalized curve.


boxes_along_crv_2024_Jun23b.gh (12.8 KB)

1 Like

Hi Joseph, thank you very much for your help and the improved code!

I was looking at the anemone plugin and I see that it works by looping data, something that I am not really familiar with. What I was wondering is if there is a way (if it is even possible) to be able to space the boxes with different random values of a specified domain (lets say 10 meters to 20 meters) without affecting the size of the boxes.

I am attaching a little screenshot of what I am mean exactly. It would basically be to separate/space the boxes a random distance (withing a set of values) and keep their sizes. With the current code I can separate a specified distance, or generate a random distance for the spacing of the boxes, but that random distance keeps being always the exact same.

Thank you so much in advance.

Boxes on a straight line could be done rather easily without Anemone. But that’s not your initial spec.

1 Like

Yes, I only used the straight line to explain the issue. Ideally the code should be able to work on twisted curves like in the original example.

Avoiding collisions (overlaps) of boxes on curves tends to require Anemone, but there is no single correct method. Here (white group) is something WITHOUT Anemone that has a ‘MinGap/MaxGap’ domain, but that’s between points, not actual distance between boxes.


boxes_along_crv_2024_Jun23c.gh (16.7 KB)

1 Like

By the way, instead of “center boxes”, both ends of the boxes could be centered on the curve…

Hi Joseph, thank you very much :pray:.
I think that this is great for what I am trying to accomplish!

I am going to set this last reply as the solution since it is pretty much what I unsuccesfully was trying to do.

Have a great day.

This is the Anemone loop I didn’t want to write. Both ends of each box are centered on the curve but I didn’t bother with collision detection.


boxes_along_crv_2024_Jun23e.gh (36.1 KB)

Some parameter values result in anomalies. I didn’t spend much time debugging. :zzz:

1 Like

Fixed. This is a far more solid piece of work. The Anemone loop creates points for a polyline (yellow group) with alternate segments being box and random lengths. Circles between boxes (teal green group) are only for reference and may be hidden. :+1:


boxes_along_crv_2024_Jun24a.gh (41.6 KB)

1 Like

This is absolutely a phenomenl work Joseph! Looks fantastic.
I am not really familiar with anemone and loops but I will study the basic principles of the component to understand better your code.

Thank you soo much sir!! :pray: :pray:

Given the nature of GH, loops are rarely needed. But in this case, using distance between points instead of curve length, each new point depends on earlier points so the loop is required.

The FastLoopStart ‘C’ (Counter) output wired to List Item ‘i’ determines which of the distances (box or random length) from Weave is used. If that distance is Smaller than the remaining curve (from LenP ‘L+’), the loop is terminated.

Remember that the circles between boxes (the teal green group) can be deleted. Cheers.