Grasshopper

algorithmic modeling for Rhino

Hi, I am just wondering if anyone could explain, or point me to an explanation of how trees and branches compare to arrays?

I am just trying to understand how each component will iterate through lists, branches, and trees.

This is currently how I think of it:

A 'point' component with 5 points will generally be compared to a 1-dimensional array with 5 indices.

If we flip this "path" then it becomes a 2-dimensional array looking like this [5][1].

Although it seems like Grasshopper does not iterate through these 'arrays' as one would assume. 

Also, the question arises when we have a "tree" whose "paths" looks like:

{0;0;0} (5)

{0;0;1} (5)

{0;1;0} (5)

{0;1;1} (5)

{1;0;0} (5)

{1;0;1} (5)

{1;1;0} (5)

{1;1;1} (5)

For example.

Anyone have any insight here? Or where insight may be found.

Thanks!

Views: 1327

Replies to This Discussion

Components specify ahead of time whether their input parameters need to behave like item, list or tree parameters. How Grasshopper then iterates over the trees to provide the component with all the required permutations of inputs depends on what type each parameter is and what the data looks like.

Do not think of trees as two or multi-dimensional arrays. Think of them as Dictionaries. The words in the dictionary are the paths {0;0}, {0;2;4;0}, {2} etc. You can not have the same path more than once. The branches/lists are analogous to the descriptions/definitions in the dictionary. Each word can have any number of definitions, and similarly each path can have any number of data items associated with it.

The order of the paths is always the same and defined by the sorting logic of the path data (lower numbers come before higher numbers and shorter paths come before longer paths). The order of items inside the list is arbitrary and decided by whoever creates the data.

Datatrees can be used to mimic one, two and multi-dimensional arrays. They can also be used to mimic jagged arrays. But it is important to remember that they are none of those. The [Flip Matrix] component for example only accepts DataTrees that mimic two-dimensional arrays. If you feed it something else it will turn red and complain.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

David, thank you for the explanation, but it still leaves me in the dark about something in particular.

The reason I ask is because I am trying to calculate weighting coefficients for a dataset.

The tree looks like this: 8 branches where each branch has 6 values. <--- Branches represent a specific time and each value within the branches are values for 6 different sensors.

If I [Flip Matrix] then I get 6 branches with 8 values in each branch, so each branch represents all time values for a particular sensor.

If I take a single branch, take the sum of (x(i) - x(i+1)) from that branch and do (branch length/sum of calculation) that will give me the weighting coefficient for each value in that branch to compute the weighted average.

This works absolutely fine, but when I try to use the same definition for the entire tree, it just doesn't work. I have tried many configurations and I cannot get it to compute correctly.

So, the reason I ask this question is because if I set these values as an array in Python for example, computing this way with for loops works fine.

I am just trying to figure out why I cannot do this with Grasshopper components.

Thanks again.

David, also one more question regarding this.

If I have 2 trees. One looks like this:

{0} (1)

{1} (1)

.........> {5} (1)

and the other looks like this:

{0;0} (8)

{0;1} (8)

{0;2} (8)

{1;0} (8)

............>{2;2} (8)

And I want to add the values of these trees, how does [Addition] know how to iterate through?

Chris

Attachments:

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