Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polygonWind uses the wrong convention #48

Open
kimchirichie opened this issue Sep 23, 2024 · 1 comment
Open

polygonWind uses the wrong convention #48

kimchirichie opened this issue Sep 23, 2024 · 1 comment

Comments

@kimchirichie
Copy link

I was looking to use polygonWind to reorient my polygons to be right hand oriented. However there appears to be a mistake in the implementation which incorrectly interprets positive area as clockwise orientation.

const isClockwise = polygonArea(polygon, true) > 0;

The implementation here should be corrected to:

  var isClockwise = polygonArea(polygon, true) < 0;

Conventionally, counterclockwise nets a positive area & polygonArea is correctly implemented.

@HarryStevens
Copy link
Owner

HarryStevens commented Oct 9, 2024

Hi @kimchirichie. Take a look at the demo here: https://observablehq.com/@harrystevens/geometric-polygonwind.

First, draw a polygon in the gray field. On the polygon below, the vertices are numbered in order. If you toggle back and forth between "Clockwise" and "Counter-clockwise", you will see that the vertices, as displayed on the screen, are numbered in the correct order corresponding to your selection.

It is true that in plane geometry, the convention is that counter-clockwise winding nets a positive area. The reason it is reversed here is that computer screens reverse the y-axis — 0 is on top rather than on bottom. I recognize that defying the convention can be confusing, but I think it would be even more confusing if a user asked the function to return a polygon whose vertices were in clockwise order, but then they appeared counter-clockwise on the screen.

That's why I leaned towards implementing polygonWind in this way, but I am open to counter-arguments. For instance, maybe it would be better to do const isClockwise = polygonArea(polygon, true) < 0;, and then I would update the documentation to explain that the polygon's vertices will appear in the opposite order on your screen. If I were to do this, it would be a breaking change, so I would only want to implement it along with a major update to V3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants