Polar Sorting
I’d like to write down an interesting problem here. I remembered this while thinking about this post. It represents one of my favorite, simple pieces of reasoning. I frequently find myself needing to sort a number of points around a center in Grasshopper. Don’t ask why. I realized I’ve been using three different methods to achieve this. The first one that comes to mind is using the Vector Angle component, naturally. All we have to do is supply a plane and two vectors, calculate the angle between them, and sort them. However, in certain contexts, the results of this approach might not be ideal.

This is where I thought of using Grasshopper’s parametric curves. A parametric curve always has a direction, a start, and an end. The parameters of points projected (mapped, or pulled) onto these curves give us a perfect ordering under any circumstances. For our specific problem, that curve can be a circle. In short, by projecting the points we want to arrange polarly onto a circle centered at that point, we can use the t output of the Curve Closest Point component. When sorted, the resulting t values will always provide an exact ordering of points (relative to the circle’s drawing plane). What’s interesting here is using a geometric object’s own parameterization to sort other geometric objects. After all, what we call sorting is essentially placing objects into a one-dimensional list. It made me wonder: if we wanted to do a spiral sorting, would we need a 2D sorting? But my mind hasn’t digested that yet.

The third and most elegant method is the To Polar component, which I don’t use very often. This component directly provides the angle we were trying to calculate above on a polar coordinate system. We solve the problem with a single component. So, how do the performances of these three methods compare? When I built the script and asked it to sort and tag 10,000 points around a center, the computer crashed. Before force-closing Rhino, I read that Rhino was consuming 26 GB of RAM. I hadn’t saved the file. I understood what students feel when similar things happen to them during Rhino exams. Fortunately, Grasshopper created a recovery file right before the final move. I deleted the point-generation and tagging parts and measured just the computational load. Consequently, using the Profiler, I obtained the following results:

To Polar component naturally appeared to give the fastest result for arranging 10,000 points. Measuring the vector angle came in second, and the curve closest point method came in last, of course. There are probably even better methods than these. It was an interesting exercise in reasoning.





