Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
8-liner: Even-odd rule with origin point simplifications solution in Speedy category for Inside Block by Phil15
def is_inside(ngon, pt): # https://en.wikipedia.org/wiki/Even–odd_rule (simplified)
ngon = [(x-pt[0], y-pt[1]) for x, y in ngon] # pt = (0, 0)
count = 0 # will be True for an odd count
for (xA, yA), (xB, yB) in zip(ngon, ngon[1:] + ngon[:1]):
if xA*xB <= 0 and yA*yB <= 0 and yA*xB==yB*xA:
return True # (0,0) is on the line segment AB
count += min(yA,yB) <= 0 < max(yA,yB) and (yA*xB-yB*xA)/(yA-yB) < 0
return count%2
Oct. 11, 2018
Comments: