-
Notifications
You must be signed in to change notification settings - Fork 94
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
Negative Polygon Area #48
Comments
Yes, the order of the vertices is important. A polygon is defined with vertices in a clockwise order around it IIRC. But the area should never be negative, thanks for reporting this. |
Thanks for the clarification! According to this source, the area of a spherical triangle with angles A,B,C is
However, the current implementation in
which is equivalent to
Maybe that is a problem? |
Ah no, as long as R=1 there is no difference. But for the future it might be good to fix that:
Shall I send a pull request? |
A PR would be great. Thanks ! |
I think I also found the reason for negative polygon areas: In
If the angle is very small, i.e. the dot product is almost 1, the angle is reset to zero in the subsequent I assume the EPSILON criteria were implemented to prevent dot products like 1.00...1 from triggering math domain errors in
|
Well actually everything outside of [-1, 1] would trigger an error, so maybe we could simply write
|
That's true. But it would mask a possible bug in the dot product computation: Even if the dot product yielded a completely unrealistic value, the angles would still be valid. |
Good point. Also, I remember now the use of EPSILON: it's also to be able to detect colinearity, so smaller angles are snapped to 0... |
I see. What about adding a
and calling it with |
Sounds good 👍 |
The last two tests on overlap rate would then fail:
Although the computed values are very close. Original values are 0.499837070923 and 0.0679026012212. Rounding to (1,2) instead of (2,3) digits would resolve the issue, but I don't know whether this is correct. |
Looking at the test code, I don't think there is a reason 0.499837070923 should be more correct than 0.5086952608806948. And since you removed the snapping, I think the latter should be preferred. |
Ok! |
Merged, thanks for bringing this up ! |
Happy to help. Thanks for the great work you have done already! |
spherical_geometry.get_polygon_area()
computes negative values near the poles. The result also depends on the order of the given corners:Is there an expected order of the corners?
The text was updated successfully, but these errors were encountered: