Sign up ×

We're dealing with country borders, that is the set of multiple disjoint domains that is made of polygons.

To extract the different point on the map by a given country we've been said to implement the ray casting algorithm which is absolutely fine, but the country is hardly to be the simply-connected domain. For example, the Italy consists of many disjoint domains (islands).

In this case the crossing number algorithm or the even-odd rule algorithm is still a valid approach to validate if the point in question is within the country borders or not?


After days of research finally found one discussion: MySQL implementation of ray-casting Algorithm? which gives the exhausting number of links, answers and code snippets to implement the algorithm in code (Pseudo-code:


share|improve this question

1 Answer 1

Yes, the even-odd rule works for any closed set of polygons.

The only thing to be careful about is the ray hitting a vertex, since code which is not equipped to handle degeneracies may return incorrect results in that case. The lowest effort solution is usually to (1) first check if you are on the boundary of the polygon and (2) try rays with random directions until no vertex is hit.

share|improve this answer

Your Answer


