Help understanding tree logic

Hi All,
I find i’m a bit stuck with some basic math - making the right tree branches line up.

I have two trees;

T1-A {0;0}
T1-B {1;0}

AND

T2-A {0;0}
T2-A {0;1}
T2-A {0;2}
T2-B {1:0}
T2-B {1;1}
T2-B {1;2}

I want to perform an operation with tree T1-A applied to all of T2-A - {0;0,1,2} and again T1-B applied to all of T2-B {1;0,1,2}.

I.e;

image

When i try to apply this, obviously my logic is wrong, as i end up with 1 branch in {0;x} and 5 in {1:Y}


Note: This is slightly revised off the attached file - but same problem.

Any assistance in understanding how to perform this would be most appreciated :slight_smile:

Flow Calc.3dm (28.0 KB) Flow calc.gh (11.4 KB)

Is this the logic you are looking for?

image

Or there is the flipside of this:

image

DataTrees are difficult to always understand the logic.

And for others that might stumble onto this thread, here a a couple helpful videos.

David’s classic tutorial is here on trees: https://vimeopro.com/rhino/grasshopper-masterclass-with-david-rutten

And many practical tips from @andheum helps a lot: https://youtu.be/Z6Pb-ScLpFI

Hi Scott,
Thanks for the reply, unfortunately no - using your example above what I wanted was effectively first branch of Tree 1 applied to all sub branches of the first major branch in tree 2.

Something like this:

image

1 + 4
1 + 8
1 +16

Then

2 + 32
2 + 64
2 + 128

I was actually just watching David’s videos on data trees- I thought the relative items might work for me but not quite right.

I did actually solve it by duplicating my smaller set of input data, matching the tree structures then doing the operation. But hoping there is a slightly more elegant way.

Ill keep working through David’s videos and if i find a better way ill post.

Try this. Trimming the bottom one makes two lists. So then by matching you get 1 to the first member list{0} and 2 to list{1}

Conceptually, the list are the leaves of data. If that is true then there is no difference trimming both sides of the tree:

Thanks Scott,
Works in the number example, but not working for the application I was chasing - reason being that my second tree is pairs of points (apologies, i didn’t make this clear in my earlier post).

I am using a shatter component, to cut curves with sets of two intersections - and i need to retrieve the middle piece of the curve.

My end goal is to output a closed shape for each of the intersections with the input curve - as shown in I1 through I5 below:

Where I1 is produced by intersecting C1 with L1 to Produce P1-A and P1-B - then shattering both curves based on those points and joining.

When i trim tree, i end up shattering the curve with all of the points which results in lots of little pieces like this:

(See segment in green)

Rather than what i need which is:

(See segment in green)

Ideally, i need to split the first curve, 5 times, with each resulting pair of intersections, then my second curve with each of its intersecting pair etc.

I can do this by duplicating my input curves 5 times - and feeding to the shatter component like so:

Hopefully the context makes a little bit more sense?

I think I cheated :grin:

With a little help from @Michael_Pryor and Pufferfish. The Trim Crv and Close Crv looked too easy not to use.

CurveTrim.gh (10.7 KB)

1 Like

Beautiful!
I think I need to get the pufferfish addon :smiley:

Thanks alot for that! There is always a better solution!

For future reference, would there be a way to force the tree computation, dynamically, so that you could always apply the first branch of Tree 1, to all sub branches of Tree 2? I could do it with a loop in VBA easy enough - just wondered if there is some native component that would be easy for people to use?

I think the key is to have the final sub- branches, actually be a list. So trimming the tree works.

The way I would typically handle this with native components is similar to your “duplicate” solution, only I’d use “Longest List” — it saves you the step of needing the List Length (and duplicate will occasionally get you into trouble). It can also handle multiple sets of data that need to be “duplicated” in parallel.

If we’re opening up to plug-in based solutions, I’d look at @dave_stasiuk’s tree sloth — the “Propagate Ancestors” component handles automatically duplicating the data in one higher-level tree to match the structure of a lower level tree.

3 Likes

Excellent,
Thank you Andrew, thats exactly what i was after - I finished it yesterday, still using duplicate but ill likely either adopt the puffer fish components (if I get what i need, as i do need the individual curve lengths, as well as the area) - or failing that try the longest list and match the trees (will figure that out regardless, for future reference).

This is for a flood modelling plugin related to failure of dams I am writing - Im interested to see if I can calculate ‘time steps’ with modified data flowing back through the script after each step. Not sure if thats possible yet but could be fun to try.

Thanks again for the explanation :slight_smile: