Hi,
I’m developing a Rhino plugin in C# and using KangarooSolver.dll directly (not Grasshopper).
I’m trying to generate hexagonal-like packing patterns (e.g. circle/sphere distributions) on meshes or surfaces.
I’ve seen Grasshopper examples using Length, Anchor, Load, or collision/relaxation workflows, but I’m not sure what the correct approach is when implementing this in code.
Should I:
- start from a predefined grid (e.g. hex grid) and deform it with Kangaroo,
or
- start from random points and rely on relaxation/collision to converge?
Are there any examples or guidance specifically for using KangarooSolver.dll programmatically for this kind of pattern generation?
Thanks!
Here’s an example of a simple script that generates a sphere packing on a mesh, using KangarooSolver.dll instead of the Goal components
pointfill_script.gh (7.8 KB)
Thanks Daniel for your reply and for sharing the example.
I was already familiar with using sphere collisions on meshes to avoid overlaps, and your script confirms the correct way to approach that in Kangaroo.
However, my question is slightly different: I’m trying to understand whether Kangaroo can be used not only to prevent collisions, but also to guide the points/spheres into specific patterns.
For example, instead of just a relaxed distribution, I’m interested in something more structured, like:
Square grid:
o o o o
o o o o
o o o o
Hexagonal grid:
o o o o
o o o
o o o o
Is it possible to steer Kangaroo towards these kinds of patterns using goals (e.g. combinations of Length, Anchors, or others), or is the typical approach to define the pattern first (e.g. a hex grid) and then use Kangaroo only for deformation/relaxation?
Thanks again!
If you are after a specific grid type then yes, the usual way to go about this would be to create that grid as a mesh first, then relax it with Kangaroo. For hexagonal grids it can sometimes be easier to do the relaxation with a regular triangular grid, then take the dual from the output.
Packing with collisions or repulsion will tend towards mostly regular triangular grids (and there are some things you can do to increase this tendency), but they generally won’t be fully regular - for that just providing the grid from the start is the way to go.
Thanks a lot for the clarification, that really helped. I think I’ve now found a way to generate the pattern I was looking for.