Page 1 of 1

### PointInConcavePolygon at this website is not correct, it gives a incorrect true

Posted: Sat Oct 17, 2020 12:22 pm
Hi,

I'm write a unittest and using this function to detect if a point is inside a polygon.
https://love2d.org/wiki/PointInConcavePolygon

Code: Select all

``````poly = {
0,
0,
10,
0,
10,
10,
0,
10
}

pointInPolygon(poly, 10, 10) -- returns false , correct
pointInPolygon(poly, 10, 0) -- returns false , correct
pointInPolygon(poly, 0, 10) -- returns false , correct
pointInPolygon(poly, 10, 10) -- returns true but that is incorrect.
``````

Code: Select all

``````  -- detect all lines in the polygon
for y = 1, 9 do
for x = 1, 9 do
lu.assertEquals(Polygon.pointInPolygon(poly, x, y), true, "point x: " .. x .. "point y: " .. y)
end
end

-- the outer line is not included
-- here I was working to scan the outline that returns false
``````

I don't know if someone has a fix or a correct function that I can use ?
And maybe with an optional function argument to include the border in the collision detection.

Thanks

### Re: PointInConcavePolygon at this website is not correct, it gives a incorrect true

Posted: Sat Oct 17, 2020 1:29 pm
There is no such thing as the "border" of a polygon since the edges are lines which are in theory infinitely thin.
Floating point math has a hardware limit to the precision so forget about it.