Grasshopper

algorithmic modeling for Rhino

How to transpose a "matrix" or split a list into equal length parts?

Hello everyone,

Grasshopper beginner here.  I'm looking for a way to transpose a "matrix", where "matrix" means a list of equal length lists.  For example, if I have {{1,2,3},{4,5,6}}, I'd like to get {{1,2},{3,4},{5,6}}.

I have three lists of points, and I'd like to transform them into a list of point triplets that I can interpolate a curve over.

A related question: is there a way to split a list into sublists of a fixed length?  For example, transform a list of 12 elements into a list of three quarduplets, e.g. {1,2,3,4,5,6,7,8,9,10,11,12} -> {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}} ?

Perhaps I'm not yet thinking in the "grasshopper way" and problems of this nature are best solved in a different way?

Views: 2253

Replies to This Discussion

If you are using v0.7 then there is a component that will transpose the data tree structure. Flip (Flip Matrix) see here http://www.grasshopper3d.com/forum/topics/switch-uv-coordinates?com....

If you are using 0.6 then you will need to do this manually with the Path Mapper something like this {A;B;C}(ì) --> {A;B;i}(C) where you are swapping the last branch C for the index i.

You can use the path mapper in many ways to re configure the data structure of lists have a play with dividing the index i by either using '\', '/' or '%' with you intended value to get different results. Have a look at this thread. http://www.grasshopper3d.com/forum/topics/path-mapping
Thanks for the reply! I'm using 0.6. Is there a good tutorial on the Path Mapper component somewhere?
Or generally, is there a tutorial explaining the formal notation used to describe tree structures?
If you right click on the pathmapper component and select help you'll find everything you need.

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service