-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Geometry2D.is_polygon_clockwise
always returns false for some triangles.
#92537
Comments
This also occurs in 3.x. I debugged it, and it looks like the triangle is very near zero area (i.e. colinear points), so the results are unreliable and liable to float error. The differences between c++ and gdscript are likely between 32 bit / 64 bit math (64 bit in gdscript versus 32 bit in the c++). Indeed if you print out the areas returned by your formula you get:
(before flipping, your methods seem to return opposite sign) The results not being opposite is understandable if the triangle is degenerate - neither clockwise or anti-clockwise. As to whether this is actionable, it would be nice if routine like this would return clockwise, anti-clockwise or failure. For failure it looks like it might be able to just test for 0 sum. However the binding system for functions makes it difficult to return multiple values. This is often a pain. So you'd currently need to run another test to calculate area before calling
I don't actually know offhand whether any of the triangle area functions are bound... |
Thank you for the investigation. Also, I prefer this option:
Because |
Tested versions
System information
Godot v4.2.1.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 (NVIDIA; 31.0.15.4633) - Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz (8 Threads)
Issue description
Description
I am using
Geometry2d.is_polygon_clockwise
to detect a clockwise polygon.Because my polygons are simple (i.e. they are not self-intersecting), they should be clockwise or counterclockwise.
However, even in a triangle case,
Geometry2d.is_polygon_clockwise
returnsfalse
in any polygon order.In other words, the function says my triangle is always counterclockwise, even if I reverse its order.
I met this issue only for specific polygons.
But, I was unable to figure out the exact reason.
So please check my minimum reproducible script.
Expected behavior
The return value should change if the array is reversed.
Additional note
This is a different issue from #49716.
The function returns false in any order of vertices, not the opposite of the expected.
Steps to reproduce
Here is my minimum reproducible code.
My results are:
Minimal reproduction project (MRP)
MRP.zip
The text was updated successfully, but these errors were encountered: