Grasshopper

algorithmic modeling for Rhino

Approach to distribute objects randomly while avoiding intersection

Dear community,

I am new to grasshopper and as I learned in the introduction video one should work into grasshopper by trying to solve a specific project. My problem is, I don't know how to approach the solution and I'm hoping for hints which way to go...


The goal

...is to have grasshopper randomly distribute a certain amount of sticks in a certain angle (or range of angles) in a certain area without them colliding with each other.
In this example I did it manually, but I'd like to do it in parametrically in the future (altering amount, angle, area, diameter, length...).


My (pseudo) logic:

set counter //amount of sticks
loop counter {
    make instance of stick on random point in area   // cf. populate
    rotate stick within parameters   // tilt and rotate
    try to intersect all sticks
    if (intersection = TRUE) {
        delete current instance of stick
        exitcounter++   // don't want to get stuck in the loop
    }else{
        counter++
    }
    if exitcounter > max {
        exit
        }
}


My thoughts:

  • The crucial part is avoiding the intersections
  • As I understand, it is not possible to make loops with standard grasshopper components. I tried Hoopsnake, but it would overwrite the instance of the stick each iteration, making the intersection impossible.
  • Galapagos: I could set up all instances of sticks at once an define their rotation/tilt as genes, where the fitness value would be a false result for trying to intersect all instances. But galapagos doesn't allow for boolean values, and it doesn't seam very straigt forward anyways.
  • I'll have to script it which have to learn first...

Cheers,
d@2T

Views: 4674

Replies to This Discussion

You could also just create a bunch of sticks that are randomly placed/angled, and just cull all the ones that happen to have intersections. 

Here is an example of that

Attachments:

This is actually one approach I thougth of, but I wasn't able to put it into practice properly. The downside here in my opinion is the difficulty to control the resulting amount of sticks - which is crucial to me.
But this sounds like a case for galapagos, where the the gene would be the seed to randomize points and the fitness would be the resulting amount of pipes that don't intersect?

My thanks, anyway!

Anemone - This was fun.  You could use 'Fast Loop' but it's fun to watch.

I see that Brian Harms has done a version without looping.  Interesting approach but different model so different results.

Attachments:

This is a better version of the Anemone loop approach to this challenge.  More robust, more fun to play with and watch.  The green "X' points are the ones that remain unoccupied, the blue pipe is the one being tested.  The basic idea is simple.  What is quite challenging in Grasshopper, compared to conventional programming languages, is the lack of "if ___ then" to avoid possible error conditions.  Instead, both possibilities must be generated and then the correct one selected with 'Stream Filters'.

This is what it looks like when that loop finishes - none of the pipes collide.

Attachments:

This is freakin amazing, just what I was looking for! Though it will take some time to comprehend this gem, I will try to implement the option to place external 'colliders' to leave out certain spaces (imagine placing a sphere somwhere in this tangle and omit sticks that intersect with it).

Thank you so much!

Adding fixed obstacles is extremely easy.

Attachments:

Great work!

Starting from your example I would like to try a similar exercise: positioning circles going farther from a specific point and not shuffling the list every iteration.

Any suggestion on how to achieve this? 

Thanks in advance!

Thank you Joseph Oster, this does right what I was looking for and the time will come that I also understand how it does it.
To reproduce the initial design I changed some slight details for my purposes, like mirroring the tubes, rotating them against z-axis with step-wise angles, using rhino geometry for the area and using meshes as external colliders.

Its now easy to use different shapes

Attachments:

Looks like you understand it well enough to use it - cool!  Would love to see your work but you forgot to internalize your reference curves and meshes.  Right-click those params and "Internalize data" to avoid having to send a Rhino file.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service