plasmascience的个人博客分享 http://blog.sciencenet.cn/u/plasmascience

博文

Point-in-polygon problem

已有 4723 次阅读 2014-4-1 15:51 |系统分类:科研笔记

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;
}

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, testyX- and y-coordinate of the test point.


相应的Fortran 程序可以如下网页上找到:http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html


下图是我用上述Fortran程序做的一个找出所有在EAST最外闭合磁面(LCFS)外的点的结果 :




https://blog.sciencenet.cn/blog-620148-781126.html

上一篇:朗道阻尼
下一篇:计算托卡马克中Alfven本征模的程序GTAW
收藏 IP: 61.190.88.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-29 16:57

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部