Hi, I am fairly new to grasshopper and I am having issues sorting the points in sequence as shown in the image. Would appreciate if anyone can help me as I have been stuck and have been trying for a few days now..
Bit of a hacky way to do it (relying on either side of the decimal point for sorting each axis), especially if you end up needing more structured data later, because the columns are not distinguished. I suspect it will also get confused by very small separations in Y.
Here’s another way of doing it that sorts by X first, then uses a Create Set component to identify the unique X positions and the Map output (ie. which Set value does each List Item match?) to allocate each point to a tree branch for each X value. Then we sort each branch by Y. We can flatten that tree to get a contiguous list, or keep it as is if you ever need to operate on columns.
I get in that sort of troubles on a daily basis, expecially when dealing with (usually imported) drawings that were exported/produced with bad tolerance
what happens is that all the points in each row/column are supposed to share the same x/y coordinate, but in reality they might differ by cents/thousandth of units, but because of that they look like jumping here and there to different rows/columns:
what I usually do, is to take advantage of Sort Points (specifically its index output) and I sort a ghost version of those points with rounded coordinates (here you can insert the degree of precision you want by eventually introducing a multiplier where the node is, in the example I did here it’s not necessary, but it all depends on the size of the array)
you don’t touch the original points, but just Sort a ghost version of those that has perfect sharp rounded coordinates, then just retrieve their indexes and use those to really sort your original points, something like this:
or just use an expression of some sort to save components on canvas (this expression trims the number of decimals to the amount set by the slider, then rounds to that):
Wow, thanks inno. This is insightful for my learning as I will never have thought about it this way and I will definitely try it in the future and use it as some form of a reference as well. Thanks!