-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add "Is Point In Polygon?" in mathExtend.lua #3
Comments
i found this function in the public domain -- By Pedro Gimeno, donated to the public domain
function isPointInPolygon(x, y, poly)
local x1, y1, x2, y2
local len = #poly
x2, y2 = poly[len - 1], poly[len]
local wn = 0
for idx = 1, len, 2 do
x1, y1 = x2, y2
x2, y2 = poly[idx], poly[idx + 1]
if y1 > y then
if (y2 <= y) and (x1 - x) * (y2 - y) < (x2 - x) * (y1 - y) then
wn = wn + 1
end
else
if (y2 > y) and (x1 - x) * (y2 - y) > (x2 - x) * (y1 - y) then
wn = wn - 1
end
end
end
return wn % 2 ~= 0 -- even/odd rule
end also if you change |
I've seen this algorithm before, great |
what about zframework, which is still used by techmino? |
I don't think it has a chance to be used |
I used that function for making the star collision detection in 26F-Studio/Techmino#778 |
😨 okay |
also maybe you can have 2 output variables: 1st one is non-zero rule and the 2nd one is the even/odd rule |
I think so |
looks good |
No description provided.
The text was updated successfully, but these errors were encountered: