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!
You were right on needing a more structured data at a later time (now in my case).
I am studying your canvas provided however can I clarify what should be my output for the “Geometry Pipeline” in this case? I tried using both the outputs of points and coordinates to get it sorted by X followed by Y but it doesn’t seem to work.
Geometry Pipeline is a way of getting geometry from the Rhino scene without having to right click a Curve component and “select curves” etc. It lets you get realtime feedback on changes to the scene.
You type a layer name into the Layer box (you can use * and ? wildcards, so Walls* will return all objects from the layers Walls-Internal and Walls-Existing)
The icons along the bottom let you filter for points, curves, breps and meshes. Double click to turn them on and off.
In my example, the layer is set to * and the filter set to points so it should find all the points on all layers in the Rhino scene and output them. If your points come from some other GH graph, you don’t need it.
Thank you for the clarification, in my case then I’ll have to get the output from the geometry/point that I am trying to sort by X followed by Y into the components that you have come up with am I right?
Correct. My graph assumes a flat list of points, so if your point generation outputs some other structure you will need to either flatten it first, or potentially modify mine to account for it.