The general problem we'd like to solve is, given a point and a polygon (represented by its sequence of vertices), is in , on the boundary, or outside?
Fortunately the problem has a simple and elegant answer. Just draw a ray (portion of a line extending infinitely in one direction) down (or in any other direction) from , count crossings on ray.
Every time the polygon crosses this ray, it separates a part of the ray that's inside the polygon from a part that's outside. For this, all we really need to know is whether there's an even or odd number of them. In even crossings, the point is outside the polygon.