You are on page 1of 3

Inside Test of Polygon – Odd Even Test

It is very important to know if a point is inside or outside the polygon before


starting to fill the polygon. In this odd even test can help us, but HOW ..?
The Answer to that question is answered below in detail with examples.

Lets consider this polygon and a point (above figure) that we need to check
for Inside or Outside of polygon. For that we just draw a line from that point
in one direction(as drawn in below figure).
Now we need to count the number of intersection of that line with the line
segments of the polygon. “If the number of intersection is odd then we
say the point is inside the polygon and if number of intersection is
even then we say the point is outside the polygon”. In our example we
can see the number of intersection is 3 which is odd that means the point is
inside the polygon.
Now consider the second point and repeat the same procedure as we did
for the first one, we got 2 intersections which means the point is outside the
polygon.

Sometimes things get a bit complicated as in the case of 3rd point where
the line crosses over a vertex of the polygon. Now the question arises – For
that vertex how many intersections should we consider(1 or 2). We know
that the a vertex can be formed by intersection of endpoints of two line
segments, Now we are just interested in the other end point of those line
segments. If the end point of those line segment are in the same side of the
line drawn from point (3rd point) then we count even(2) intersection and if
end point of those line segment are in the opposite side of the line drawn
from point (3rd point) then we count odd(1) intersection. In our example for
the 3rd point the other ends of both line segments are in same sides so we
count even(2) intersection and add 1(normal intersection of line drawn from
3rd point with the line segment of polygon) to it, which gets to a total of 3
which odd that means the 3rd point is inside the polygon.

You might also like