Select Curves Belonging to the Least Frequent Direction?

I have a list of line curves.The lines can point in opposite directions, but I want to treat opposite vectors as the same direction, so +X and -X are both “X direction,” and +Y and -Y are both “Y direction.”

I need to group the curves by their overall/unoriented direction, count how many curves are in each direction group, and then return only the curves from the least common direction group.

For example, if I have 50 lines in the X direction and 2 lines in the Y direction, I want the result to be those 2 Y-direction lines.

I was able to achieve it this way, but it feels like I’m using too many components. I suspect there may be a more efficient approach, or perhaps a mathematical concept that I’m missing.

Less Frequent Direction.gh (13.5 KB)

Just lines in the x or y direction of a plane, or more complicated?

Yup just planar 2D lines in x or y.

I feel like you did just fine. I suppose you could abbreviate by finding the dot-product against unit-x. 0 values are then unit y, which cast to boolean are false for y direction, true for x:

I think this method is less concise, but here is another way to do it.

Least Direction Lines.gh (11.1 KB)

You can also stick to angles if you want and use To Polar to abbreviate:

Also fun is math:

Less Frequent Direction VR 2.gh (45.9 KB)

I would’ve done it pretty much how you did it without the first 8 components:

First few components are necessary if opposing directions should be considered the same.


@ShynnSup You wanted the script longer, correct?

Less Frequent Direction VR 4.gh (25.1 KB)

I tease, but the advantage is that you carry the count number in the branch adresses moving forward this way.