Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creator: Squalleze
- --Made in: 05/02/2016
- --Last update: 25/05/2016
- --[[ Notes:
- Does:
- Descubra se os pontos x,y estão dentro do polígono de ... lados em ... posições
- Args:
- x --> Ponto horizontal
- y --> Ponto vertical
- ... --> Tabela {x,y} dos lados do polígono
- ]]--
- math.inPolygon=function(x,y,...)
- local s={...}
- local i=false
- local p=#s
- if p<3 then error("A polygon needs more than "..p.." points.") end
- for v=1,p do
- if (s[v][2]<y and s[p][2]>=y) or (s[p][2]<y and s[v][2]>=y) then
- if s[v][1]+(y-s[v][2])/(s[p][2]-s[v][2])*(s[p][1]-s[v][1])<x then
- i=not i
- end
- end
- p=v
- end
- return i
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement