Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
odd x's above y solution in Clear category for Inside Block by Tinus_Trotyl
def is_inside(polygon, point):
x, y = point
inside = False
for begin, end in zip(polygon, polygon[1:] + polygon[:1]):
x0, y0, x1, y1 = (*begin, *end)
if y0 == y == y1 and min(x0, x1) <= x <= max(x0, x1): return True
if x0 == x == x1 and min(y0, y1) <= y <= max(y0, y1): return True
if x0 <= x < x1 or x1 <= x < x0:
a = (y1 - y0) / (x1 - x0)
b = y1 - a * x1
if y <= a * x + b: inside = not inside
return inside
Oct. 12, 2020
Comments: