Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Inside Block by Sim0000
def is_inside(polygon, point):
x, y, x1, y1 = point + polygon[-1]
count = 0
for x2, y2 in polygon:
if y1 == y2:
if y == y1 and min(x1, x2) <= x <= max(x1, x2): return True # on line
else:
cx = x1 + (x2 - x1) * (y - y1) / (y2 - y1) # x of cross point
if x == cx: return True # on line
if x < cx and min(y1, y2) <= y < max(y1, y2): count += 1
x1, y1 = x2, y2
return count % 2 # odd then inside
Dec. 13, 2015
Comments: