def pointInsidePolygon(x, y, poly):
n = len(poly)<EOL>inside = False<EOL>p1x, p1y = poly[<NUM_LIT:0>]<EOL>for i in range(n + <NUM_LIT:1>):<EOL><INDENT>p2x, p2y = poly[i % n]<EOL>if y > min(p1y, p2y):<EOL><INDENT>if y <= max(p1y, p2y):<EOL><INDENT>if x <= max(p1x, p2x):<EOL><INDENT>if p1y != p2y:<EOL><INDENT>xinters = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x<EOL><DEDENT>if p1x == p2x or x <= xinters:<EOL><INDENT>inside = not inside<EOL><DEDENT><DEDENT><DEDENT><DEDENT>p1x, p1y = p2x, p2y<EOL><DEDENT>return inside<EOL>
Determine if a point is inside a given polygon or not
Polygon is a list of (x,y) pairs.

[code taken from: http://www.ariel.com.au/a/python-point-int-poly.html]

let's make an easy square:

>>> poly = [ (0,0),\
             (1,0),\
             (1,1),\
             (0,1) ]
>>> pointInsidePolygon(0.5,0.5, poly)
True
>>> pointInsidePolygon(1.5,1.5, poly)
False