List/tree operations

Hi all!

I have a tree with branches with data of z-coordinates. The first list (marked with 1) is what it looks like now and the second list (marked with 2) is what I want it to look like. The final list will consist of approx 500 branches with varying length of each branch.

The data is sorted by z-coordinates from smallest to largest within each branch and one branch each for values with the same x- and y-coordinates.

What I want to do is it to check if the next value in the list is bigger than 2 of the previous and if it is then just keep the first value. So in the example, 9.2 is 0.9 units bigger than 8.3 so then it should just keep 8.3. It can be maximum three values that is within the range of 2 units and then I want it to keep the middle value.

So in reality what it will check is if the window consists of two parts, I want to keep the lower point. The window can consist of maximum three parts and then I want to keep the middle one.

I expect that I need to use a Python script but I have not made it work as it seems too complicated.

Does anyone know how to solve this?

Thanks in advance!

looks like for each index i you want to check -triplet first- if [i+2] - [i] < 2
if true, then output [i+1] (middle element of the triplet) and next iteration will test [i+3]
otherwise you want to check the very same previous i for [i+1] - [i] < 2
if true then output [i] and next iteration will test [i+2]
if false, output [i] and next iteration will test [i+1]

1 Like

Thank you. What would it look like in a script? I don’t know how to define i.

This is what I’ve come up with. The data marked with red is the input, black is the output of the code I’ve written and blue is what I want it to look like.

It seems that the increament of i is not written correct. Do you know how I can fix this?

If you can read C# (no auto conversion to P possible) and you need a full tutorial on similar matters (using LINQ and the likes) drop a word.

be aware, I’m literally in the bottom 10% of Python users… but here’s my take

Python_thing.gh (8.6 KB)

It works, thank you so much!!