Grasshopper

algorithmic modeling for Rhino

For some data visualisation/ infographics I did a good while ago, there was the necessity to know the branch count of direct descendants at the different depths of the tree. So I don't mean just the final branches.

Starting at the trunk, I would need an integer of the number of direct descendants, so oh at the core: it has 3 branches, then the first branch of that, ah it has 5, the second branch to the trunk has 2, etc. yada yada.

Back then there was a script written for the specific one i needed and some funky string actions to help process. But I was always wondering, there must be a clean solution, has anyone come across such a thing?

I realize there is no component, but maybe someone wrote a script, uncovered a functionality?

Views: 524

Replies to This Discussion

Are you basically looking to find the number of branches that come out of each green circle?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Exactly that David!

This might be useful for someone.

To traverse the path in nested loops I do it like so:

Get the max number of branches at each depth by

int depthLayerOne = tree.Paths[tree.PathCount - 1].Indices[0] + 1;

int depthLayerTwo = tree.Paths[tree.PathCount - 1].Indices[1] + 1;

It gets the last element from the list of paths, which would have the max number of branches at each depth level as indices. I add one to those, to make it easy to loop.

I can do the 0 and 1 index into the 'Indices ' array because in my case I know the number of layers in my tree.

If you don't know that in advance you can use a list to loop through.

Nested looping like so:

for(int i=0; i<depthLayerOne; i++) {

    for(int j=0; j<depthLayerTwo; j++)

        {

            // code

        }

}

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