|
In computational geometry, the point in polygon (PIP) problem asks whether a given point in the plane lies inside, outside, or on the boundary of a polygon. (http://en.wikipedia.org/wiki/Point_in_polygon)
解决这一问题的经典算法是 Ray casting algorithm, 如下是一个实现这一算法的C程序 (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;
}
Argument | Meaning |
---|---|
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. |
相应的Fortran 程序可以如下网页上找到:http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
下图是我用上述Fortran程序做的一个找出所有在EAST最外闭合磁面(LCFS)外的点的结果 :
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-10-20 01:41
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社