Tree connecting points pairwise

Input: A number of points arranged in a line.

Desired output: A tree that joins nodes neighboring in x-direction, pairwise.

Simplification: The y-position of the output nodes does not matter. They are allowed to be all in the same line.

Scripting that should be straight forward. But I wonder: Can this be done with pure Grasshopper?

Are the branchings always into two or less?

No. Basic binary decomposition is much easier than that:


Tree connecting points pairwise VR 01.gh (21.1 KB)

3 Likes

For anybody wondering why the above is useful:


Tree connecting points pairwise VR 02.gh (43.1 KB)

You can use the binary paths to create a jagged tree of nodes. This is normally frowned upon as “poor form”, but the advantage is that you can use path depth to ascertain valence and parent/child relationships easily.

For example, the ancestor nodes of the leaf {0;0;1;0;0} are {0;0;1;0}, {0;0;1}, {0;0}, and {0} and using Tree Item with these paths quickly delivers the nodes for the polyline of that branch.

I don’t see a problem with using jagged trees if the portion of the script using the jagged tree is purely generative, i.e. not taking in data of unknown structure from somewhere else. You just have to be cognisant of what you’re doing. But for those who like to complain, at least the point and polyline geometry has been flattened to global indices.

Please mark a solution.

2 Likes