Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
counting intersections solution in Clear category for Inside Block by David_Jones
def is_inside(polygon, point):
x0, y0 = point
intersections = 0
for p1, p2 in zip(polygon, polygon[1:]+polygon[:1]):
x1, y1 = p1
x2, y2 = p2
if (
(x1, y1) == (x0, y0)
or y0 == y1 == y2 and min(x1, x2) < x0 < max(x1, x2)
or x0 == x1 == x2 and min(y1, y2) < y0 < max(y1, y2)
):
return True
if min(y1, y2) < y0 <= max(y1, y2) and x0 <= max(x1, x2):
intersections += (y0 - y1) * (x2 - x1) / (y2 - y1 + .1) + x1 >= x0
return intersections % 2 > 0
May 20, 2019