判断点在多边形内部
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) //testx,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;
}
转自https://www.cnblogs.com/luxiaoxun/p/3722358.html