I am trying to get all x,y within ANY polygon shape in c++
for e.g I have a rectangle that has the following cordinates,
Point 1:
X = 5
Y = 10
Point 2:
X = 5
Y = 8
Point 3:
X = 9
Y = 8
Point 4:
X = 9
Y = 10
so the cordinates within polygon base on the 4 points given will be
X = 6 Y = 9
X = 7 Y = 9
X = 8 Y = 9
I found this from http://alienryderflex.com/polygon/
bool pointInPolygon() {
int i, j=polySides-1;
bool oddNodes=NO;
for (i=0; i<polySides; i++) {
if (polyY[i]<y && polyY[j]>=y
|| polyY[j]<y && polyY[i]>=y) {
if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x) {
oddNodes=!oddNodes; }}
j=i;
}
return oddNodes;
}
and even this http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) {
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++) {
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
c = !c;
}
return c;
}
In fact most of my search results I found will have something similar to the codes(shown above). from what I understand, the code(shown above) will only return you a true/false if the point is within the polygon and does not return any cords that is found within the polygon.