Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Ray casting solution in Clear category for Inside Block by DiZ
def is_inside(polygon, point):
inside, n, (x, y) = 0, len(polygon), point
for p1, p2 in zip(polygon, polygon[1:] + polygon):
(p1x,p1y), (p2x, p2y) = p1, p2
# check if point is a vertex
if p1 == point: return True
# check if point is on a boundary
if y == p1y == p2y and min(p1x, p2x) < x < max(p1x, p2x) \
or x == p1x == p2x and min(p1y, p2y) < y < max(p1y, p2y):
return True
# check if point is strictly inside polygon
if min(p1y, p2y) < y <= max(p1y, p2y) and x <= max(p1x, p2x):
inside += (y-p1y)*(p2x-p1x) / (p2y-p1y + 1e-9) + p1x >= x
return inside % 2
Jan. 30, 2015
Comments: