i have to find all interior points in a polygon. I used the following function, to check every point (x,y), but for some points returns true even if the point is exterior or is on the edge of the polygon.
bool IsInside(int no_vert,float *vertx, float *verty, float testx, float testy)
{
int i;
int j;
bool c=false;
for (i = 0, j = no_vert-1; i < no_vert; j = i++)
{
if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
{
c = true;
}
}
return c;
}
What you want to do isn’t to test that
but that the relationship stay the same (i.e. always
<or always>).The common way to do that would be something like (not tested, doesn’t have to special case for equality)
BTW, this work only for convex polygons.