Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Inside Block solution in Uncategorized category for Inside Block by capback250
# migrated from python 2.7
from functools import reduce
def is_inside(polygon, point):
distance = (max(reduce(list.__add__, [list(i) for i in polygon])) + 1, point[0])
pairs = [[polygon[i-1], polygon[i]] for i in range(len(polygon))]
for i in range(len(pairs)):
if pairs[i-1][1] == pairs[i][0]:
check = pairs[i][0]
if point[1] == check[1] == distance[1] and check[0] in range(point[0],distance[0]):
return True
for i in range(len(polygon)):
for z in range(2):
if polygon[i-1][z] == point[z] == polygon[i][z]:
cors = sorted([polygon[i-1][int(not z)], polygon[i][int(not z)]])
if point[int(not z)] in range(cors[0], cors[1]):
return True
return sum([1 for i in range(len(polygon)) if intersect(polygon[i-1], polygon[i], point, distance)]) % 2
rotate = lambda a, b, c: (b[0]-a[0])*(c[1]-b[1])-(b[1]-a[1])*(c[0]-b[0])
intersect = lambda a, b, c, d: rotate(a, b, c)*rotate(a, b, d) <= 0 and rotate(c, d, a)*rotate(c, d, b) < 0
Jan. 12, 2016