Here is the most known method to test if point is inside polygon.
p polygon
n number of vertices in polygon
q point
RightHorizontalRayIntersection(q,u,v) tests if horizontal ray starting from point q (in right direction) intersects a segment (u,v).
Code:
bool IsPointInsidePolygon( P *p,int n,P q ) {
int i,j,c=0;
for (i=0,j=n-1; i<n; j=i++) // Considering all segments (p[i],p[j])
if (RightHorizontalRayIntersection( q,p[i],p[j] )) c++;
return c%2;
}
There is a special cases, ray r intersects a segment in one of it.
Sample:
http://blog.youkuaiyun.com/xqls_xqls/archive/2009/07/30/4393369.aspx
点在多边形内判断算法
本文介绍了一种常见的判断点是否位于多边形内部的方法。通过水平射线法来确定点与多边形的关系,该算法适用于任意数量顶点的多边形。文章还讨论了射线与多边形边相交的特殊情况。
386

被折叠的 条评论
为什么被折叠?



