I have an array of points which makes up a polygon, i want to find out weather a point lies within the polyon area.
Is there a build in function for polygons.
(pss I don't need to draw on screen.)
I am using Visual C++ 6
Printable View
I have an array of points which makes up a polygon, i want to find out weather a point lies within the polyon area.
Is there a build in function for polygons.
(pss I don't need to draw on screen.)
I am using Visual C++ 6
I highly doubt that. Try searching the internet, Im sure its out there somewhere
It's not a standard function, I think... But the problem is not too hard. Search for "polygon interior". I found this (by Randolph Franklin).
alexCode:int pnpoly(int npol, float *xp, float *yp, float x, float y)
{
int i, j, c = 0;
for(i = 0, j = npol-1; i < npol; j = i++)
{
if((((yp[i] <= y) && (y < yp[j])) || ((yp[j] <= y) && (y < yp[i]))) &&
(x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
c = !c;
}
return c;
}
There are a couple of win32 API GDI functions that you could use CreatePolygonRgn() to create a region from your points and PtInRegion() to find out if a specific point is in a region.