PNPOLY - Point Inclusion in Polygon W. Randolph Franklin

测试目标点是否在多边形内
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; }
ArgumentMeaning
nvert Number of vertices in the polygon. Whether to repeat the first vertex at the end is discussed below.
vertx, verty Arrays containing the x- and y-coordinates of the polygon's vertices.
testx, testy X- and y-coordinate of the test point.

http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

posted @ 2014-03-05 11:58  superping  阅读(766)  评论(0编辑  收藏  举报