No, the example you quote is ok. Don't forget that for each line segment you calculate the x-coordinate on the line corresponding to the y-coordinate of the point of interest.
The case it can't cope with is if there are line segments on either side of the point of interest that are 'horizontal' (i.e. they start and end with the same y-coordinate of the point of interest). In this case, the algorithm "doesn't know' if the point is inside or outside the polygon.
If there are such line segments only one side of the point of interest, that is ok because you can start counting segments from either side to get the result.
For example, in the attached sketch all of the 'o' points can be correctly identified (try it!) but the (red) 'x' point can
not.
There are two solutions to this:
- You can go to a much more complex algorithm in which the polygon is broken down into a number of trapezoids and triangles; the point can then be tested against all of these elements to see if it is inside one of them.
- You can move the point a tiny bit up and/or down to clear the ambiguity (that is what I normally do, since for most practical situations it works fine).
--
Martin
--
Martin
Certified CVI Developer