Geo Fencing - point inside/outside polygon

Niko Gamulin picture Niko Gamulin · May 29, 2009 · Viewed 69.2k times · Source

I would like to determine a polygon and implement an algorithm which would check if a point is inside or outside the polygon.

Does anyone know if there is any example available of any similar algorithm?

Answer

Ian Boyd picture Ian Boyd · May 29, 2009

If i remember correctly, the algorithm is to draw a horizontal line through your test point. Count how many lines of of the polygon you intersect to reach your point.

If the answer is odd, you're inside. If the answer is even, you're outside.

Edit: Yeah, what he said (Wikipedia):

alt text