One way of testing whether or not your point is inside a simple polygon is to use what is called a ray casting algorithm http://en.wikipedia.org/wiki/Point_in_polygon.
What you do is create a line that goes through the point you are checking, and count how many times it intersects with all of the line segments that make up your Polygon.
If the number of intersections is divisible by 2 then the point is outside the Polygon, otherwise it is inside. (Zero is even in this case)
I implemented this function in python using an arbitrarily large line segment for my 'ray'. And used two functions to test line segment intersection.
def counterclockwise(self, A, B, C):
return (C- A) * (B - A) > (B - A) * (C - A)
def segment_intersect(self,A, B, C, D):
return counterclockwise(A,C,D) != counterclockwise(B,C,D) and counterclockwise(A,B,C) != counterclockwise(A,B,D)
def ray_cast(self, point, polyPoints, farAwayPoint):
intersections = 0
for i in range(len(polyPoints)-1):
if segment_intersect(point, farAwayPoint, polyPoints[i], polyPoints[i+1]) :
intersections += 1
if intersections % 2 == 0:
Notice I used point and farAwayPoint as my arbitrarily large segment. Obviously you could just choose any arbitrarily large point like (point.x + 10000, point.y + 10000) without making an extra function argument.
I hope this helps.