Rearranging points on the list


I’m fairly new to GH, and still have problems understanding data structures (btw I would be grateful for some tutorials explaining them in a more intuitive way).

I created 4 points on 6 curves by dividing the curves evenly, so I have a list of 6 “groups” of 4 points:

Now I want to create NURBS curves by picking one point from each “group”: curve A using point #0 from each group, curve B using point #1 from each group… etc

I would be grateful for some clues how to get an item of the same position from each group, and then do it for every position

here are two curves done by hand in rhino to illustrate the example. I’ll just add, that later on, I will be adding way more curves (they are generated by offset + random), and will be dividing it by more way segments. That’s why I’m looking for a more parametric solution.

Thank you,

A little gadget called ‘Flip Matrix’ will do it. (‘Sets | Tree | Flip Matrix’)

1 Like

The usual nomenclature is that you have a tree containing six branches (or lists) and each branch (or lists) containing four items.

The paths in your tree are already quite complicated, in that they contain a lot of zeroes. This is not necessarily a bad thing, or a problem, but it might mean you can simplify your data somewhat. Each path has a length of six, and only the third path element is different. You can simplify such a path by using the Path Mapper object and the following mapping:

\{A;B;C;D;E;F\} \rightarrow \{C\}

On the left you describe what you currently have, and on the right you describe what you want to end up with. In this case only the third element C out of each path.

If you do this, your tree will change like this:

\{0;0;0;0;0;0\} \hspace{6.7mm} \{0\}
\{0;0;1;0;0;0\} \hspace{6.7mm} \{1\}
\{0;0;2;0;0;0\} \hspace{6.7mm} \{2\}
\{0;0;3;0;0;0\} \rightarrow \{3\}
\{0;0;4;0;0;0\} \hspace{6.7mm} \{4\}
\{0;0;5;0;0;0\} \hspace{6.7mm} \{5\}

Each item can be indexed using square brackets. So if \{0\} represents the first branch, then \{0\}[0] represents the first item in the first branch. Similarly, \{2\}[3] represents the fourth (and last) item in the third branch.

This particular tree is topologically similar to a rectangular table of values. It has six equal ‘columns’ (i.e. the branches) and each column contains exactly four ‘rows’ (i.e. the items). There is a component called Flip Matrix which swaps out columns and rows. This is akin to exchanging the values in the index notation; \{a\}[b] becomes \{b\}[a].

If you use that component you’ll end up with a tree containing only four branches, but each branch containing six elements. You can then use this flipped tree to create your curves.* There are other ways to re-order trees, for example using a different path mapping, but I think in this case you should just use the simplest approach possible.

* You do not have to simplify your tree for the flipping to work, at least not in this case.