Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
intersection method solution in Clear category for Inside Block by kdim
from typing import Tuple
def is_inside(polygon: Tuple[Tuple[int, int], ...], point: Tuple[int, int]) -> bool: # intersection method
p, l, flag = polygon, len(polygon), False # only for convex
x, y = point
for i in range(l):
x0, y0 = p[i]
x1, y1 = p[(i+1)%l]
if (x0==x==x1 and (y0<=y<=y1 or y1<=y<=y0)): return True # point lies on the segment
if (y0==y==y1 and (x0<=x<=x1 or x1<=x<=x0)): return True #
if (((y1<=y(x0-x1)*(y-y1)/(y0-y1)+x1)): flag = not flag # intersection
return flag
Jan. 20, 2021