Turn out right solution in Clear category for Inside Block by carel.anthonissen
from math import acos,sqrt,pi
def is_inside(polygon, point):
# Add the angles between the point and consecutive vertices on the polygon.
# The sum of the angels will add up to 2pi (360 deg) if it is on the inside,
# zero if it is on the outside, and somewhere in between on the boundary.
# Credit to Mary Rose Cook for making me aware of this method :)
Calculates the angle (+-pi) between two vectors (zero if one is a zero vector)
dot = v1*v2+v1*v2
cross = v1*v2-v1*v2
mag = sqrt(v1**2+v1**2)*sqrt(v2**2+v2**2)
return 0 if mag == 0 else acos(dot/mag) if cross >=0 else -acos(dot/mag)
# Determine the consective vectors from the point to the vertices of the polygon.
vectors = [(p-point,p-point) for p in polygon]
# Sum the angles between consecutive vectors.
total_angle = sum((angle(*pair) for pair in zip(vectors[1:],vectors[:-1])))
# Return True if larger than zero (accounting for floating point imprecision)
May 3, 2020