function IsPtInPoly(pt, pts)
local count = 0
local x, y = pt.x, pt.y
local x1, y1 = pts[1].x, pts[1].y
local x1Part = (y1 > y) or ((x1 - x > 0) and (y1 == y))
local x2, y2
for i = 1, #pts do
local point = pts[i]
local x2, y2 = point.x, point.y
local x2Part = (y2 > y) or ((x2 > x) and (y2 == y))
if x2Part == x1Part then
x1, y1 = x2, y2
else
local mul = (x1 - x)*(y2 - y) - (x2 - x)*(y1 - y)
if mul > 0 then
count = count + 1
elseif mul < 0 then
count = count - 1
end
x1, y1 = x2, y2
x1Part = x2Part
end
end
if count == 2 or count == -2 then
return true
end
return false
end
lua判断点在任意多边形内部
最新推荐文章于 2024-02-25 21:02:25 发布