在GIS(地理信息管理系统)中,判断一个坐标是否在多边形内部是个经常要遇到的问题。乍听起来还挺复杂。根据W. Randolph Franklin 提出的PNPoly算法,只需区区几行代码就解决了这个问题。假设多边形的坐标存放在一个数组里,首先我们需要取得该数组在横坐标和纵坐标的最大值和最小值,根据这四个点算出一个四边型,首先判断目标坐标点是否在这个四边型之内,如果在这个四边型之外,那可以跳过后面较为复杂的计算,直接返回false。if (p.x < minX || p.x > maxX || p.y < minY || p.y > maxY) {// 这个测试都过不了。。。直接返回false;
}
接下来是核心算法部分: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;
}额,代码就这么简单,但到底啥意思呢:首先,参数nvert 代表多边形有几个点。浮点数testx, testy代表待测试点的横坐标和纵坐标,*vertx,*verty分别指向储存多边形横纵坐标数组的首地址。
我们注意到,每次计算都涉及到相邻的两个点和待测试点,然后考虑两个问题:
1. 被测试点的纵坐标testy是否在本次循环所测试的两个相邻点纵坐标范围之内?即
verty[i] <testy < verty[j]
或者
verty[j] <testy < verty[i]
2. 待测点test是否在i,j两点之间的连线之下?看不懂后半短if statement的朋友请自行在纸上写下i,j两点间的斜率公式,要用到一点初中解析几何和不等式的知识范畴,对广大码农来说小菜一碟。
然后每次这两个条件同时满足的时候我们把返回的布尔量取反。
可这到底是啥意思啊?
这个表达式的意思是说,随便画个多边形,随便定一个点,然后通过这个点水平划一条射线,先数数看这条
射线和多边形的边相交几次,(或者说先排除那些不相交的边,第一个判断条件),然后再数这条射线穿越多边形的次数是否为奇数,如果是奇数,那么该点在多边形内,如果是偶数,则在多边形外。详细的数学证明这里就不做了,不过读者可以自行画多边形进行验证。

以上转载百度知道;以下转载阿凡卢,转载地址:http://www.cnblogs.com/luxiaoxun/p/3722358.html

判断点是否在多边形内部

如何判断一个点是否在多边形内部?

(1)面积和判别法:判断目标点与多边形的每条边组成的三角形面积和是否等于该多边形,相等则在多边形内部。

(2)夹角和判别法:判断目标点与所有边的夹角和是否为360度,为360度则在多边形内部。

(3)引射线法:从目标点出发引一条射线,看这条射线和多边形所有边的交点数目。如果有奇数个交点,则说明在内部,如果有偶数个交点,则说明在外部。

具体做法:将测试点的Y坐标与多边形的每一个点进行比较,会得到一个测试点所在的行与多边形边的交点的列表。在下图的这个例子中有8条边与测试点所在的行相交,而有6条边没有相交。如果测试点的两边点的个数都是奇数个则该测试点在多边形内,否则在多边形外。在这个例子中测试点的左边有5个交点,右边有三个交点,它们都是奇数,所以点在多边形内。

算法图解:

关于这个算法的具体的更多图形例子:http://alienryderflex.com/polygon/

参考代码:

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

来自一个polygon的内部实现:

      public bool IsInside(PointLatLng p)
{
int count = Points.Count;

     </span><span style="color:rgb(0,0,255);line-height:1.5 !important;">if</span>(count &lt; <span style="color:rgb(128,0,128);line-height:1.5 !important;">3</span><span style="line-height:1.5 !important;">){</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span> <span style="color:rgb(0,0,255);line-height:1.5 !important;">false</span><span style="line-height:1.5 !important;">;}</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">bool</span> result = <span style="color:rgb(0,0,255);line-height:1.5 !important;">false</span><span style="line-height:1.5 !important;">;</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">for</span>(<span style="color:rgb(0,0,255);line-height:1.5 !important;">int</span> i = <span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span>, j = count - <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span>; i &lt; count; i++<span style="line-height:1.5 !important;">){</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">var</span> p1 =<span style="line-height:1.5 !important;"> Points[i];</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">var</span> p2 =<span style="line-height:1.5 !important;"> Points[j];</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">if</span>(p1.Lat &lt; p.Lat &amp;&amp; p2.Lat &gt;= p.Lat || p2.Lat &lt; p.Lat &amp;&amp; p1.Lat &gt;=<span style="line-height:1.5 !important;"> p.Lat){</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">if</span>(p1.Lng + (p.Lat - p1.Lat) / (p2.Lat - p1.Lat) * (p2.Lng - p1.Lng) &lt;<span style="line-height:1.5 !important;"> p.Lng){result </span>= !<span style="line-height:1.5 !important;">result;}}j </span>=<span style="line-height:1.5 !important;"> i;}</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span><span style="line-height:1.5 !important;"> result;}</span></pre><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy" style="line-height:1.5 !important;"><a title="复制代码" style="color:#008000;border:none !important;" target="_blank"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border:none !important;"></a></span></div></div><p>特殊情况:要检测的点在多变形的一条边上,射线法判断的结果是不确定的,需要特殊处理(<span>If the test point is on the border of the polygon, this algorithm will deliver unpredictable results</span>)。</p><p>计算一个多边形的面积(area of a polygon):</p><div class="cnblogs_code" style="background-color:rgb(245,245,245);border:1px solid rgb(204,204,204);overflow:auto;font-family:'Courier New' !important;font-size:12px !important;"><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy" style="line-height:1.5 !important;"><a title="复制代码" style="color:#008000;border:none !important;" target="_blank"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border:none !important;"></a></span></div><pre style="font-family:'Courier New' !important;">        <span style="color:rgb(0,0,255);line-height:1.5 !important;">private</span> <span style="color:rgb(0,0,255);line-height:1.5 !important;">static</span> <span style="color:rgb(0,0,255);line-height:1.5 !important;">double</span> SignedPolygonArea(List&lt;PointLatLng&gt;<span style="line-height:1.5 !important;"> points){</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Add the first point to the end.</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">int</span> pointsCount =<span style="line-height:1.5 !important;"> points.Count;PointLatLng[] pts </span>= <span style="color:rgb(0,0,255);line-height:1.5 !important;">new</span> PointLatLng[pointsCount + <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span><span style="line-height:1.5 !important;">];points.CopyTo(pts, </span><span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span><span style="line-height:1.5 !important;">);pts[pointsCount] </span>= points[<span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span><span style="line-height:1.5 !important;">];</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">for</span> (<span style="color:rgb(0,0,255);line-height:1.5 !important;">int</span> i = <span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span>; i &lt; pointsCount + <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span>; ++<span style="line-height:1.5 !important;">i){pts[i].Lat </span>= pts[i].Lat * (System.Math.PI * <span style="color:rgb(128,0,128);line-height:1.5 !important;">6378137</span> / <span style="color:rgb(128,0,128);line-height:1.5 !important;">180</span><span style="line-height:1.5 !important;">);pts[i].Lng </span>= pts[i].Lng * (System.Math.PI * <span style="color:rgb(128,0,128);line-height:1.5 !important;">6378137</span> / <span style="color:rgb(128,0,128);line-height:1.5 !important;">180</span><span style="line-height:1.5 !important;">);}</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Get the areas.</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">double</span> area = <span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span><span style="line-height:1.5 !important;">;</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">for</span> (<span style="color:rgb(0,0,255);line-height:1.5 !important;">int</span> i = <span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span>; i &lt; pointsCount; i++<span style="line-height:1.5 !important;">){area </span>+= (pts[i + <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span>].Lat - pts[i].Lat) * (pts[i + <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span>].Lng + pts[i].Lng) / <span style="color:rgb(128,0,128);line-height:1.5 !important;">2</span><span style="line-height:1.5 !important;">;}</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Return the result.</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span><span style="line-height:1.5 !important;"> area;}</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span> <span style="color:rgb(128,128,128);line-height:1.5 !important;">&lt;summary&gt;</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Get the area of a polygon</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span> <span style="color:rgb(128,128,128);line-height:1.5 !important;">&lt;/summary&gt;</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span> <span style="color:rgb(128,128,128);line-height:1.5 !important;">&lt;param name="points"&gt;&lt;/param&gt;</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span> <span style="color:rgb(128,128,128);line-height:1.5 !important;">&lt;returns&gt;&lt;/returns&gt;</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">public</span> <span style="color:rgb(0,0,255);line-height:1.5 !important;">static</span> <span style="color:rgb(0,0,255);line-height:1.5 !important;">double</span> GetPolygonArea(List&lt;PointLatLng&gt;<span style="line-height:1.5 !important;"> points){</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Return the absolute value of the signed area.</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> The signed area is negative if the polygon is oriented clockwise.</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span><span style="line-height:1.5 !important;"> Math.Abs(SignedPolygonArea(points));}</span></pre><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy" style="line-height:1.5 !important;"><a title="复制代码" style="color:#008000;border:none !important;" target="_blank"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border:none !important;"></a></span></div></div><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>参考资料:</p><p>http://alienryderflex.com/polygon/</p><p>http://en.wikipedia.org/wiki/Point_in_polygon</p><p>http://www.codeproject.com/Tips/84226/Is-a-Point-inside-a-Polygon</p><p>&nbsp;</p></div><div id="MySignature" style="background-color:rgb(248,248,238);border:1px solid rgb(232,231,208);color:#808080;"><div style="line-height:25px;">作者:<a href="http://www.cnblogs.com/luxiaoxun/" rel="nofollow" style="color:#008000;text-decoration:none;" target="_blank">阿凡卢</a></div><div style="line-height:25px;">出处:<a href="http://www.cnblogs.com/luxiaoxun/" rel="nofollow" style="color:#008000;text-decoration:none;" target="_blank">http://www.cnblogs.com/luxiaoxun/</a></div><div style="line-height:25px;">本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。</div></div></div><br><pre class="best-text mb-10" style="background-color:rgb(255,255,255);font-family:'Microsoft YaHei', arial, 'courier new', courier, '宋体', monospace;font-size:16px;line-height:29px;min-height:55px;" name="code"><span style="color:#333333;">

假设多边形的坐标存放在一个数组里,首先我们需要取得该数组在横坐标和纵坐标的最大值和最小值,根据这四个点算出一个四边型,首先判断目标坐标点是否在这个四边型之内,如果在这个四边型之外,那可以跳过后面较为复杂的计算,直接返回false。

if (p.x < minX || p.x > maxX || p.y < minY || p.y > maxY) {
// 这个测试都过不了。。。直接返回false;
}
接下来是核心算法部分:

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

额,代码就这么简单,但到底啥意思呢:

首先,参数nvert 代表多边形有几个点。浮点数testx, testy代表待测试点的横坐标和纵坐标,*vertx,*verty分别指向储存多边形横纵坐标数组的首地址。
我们注意到,每次计算都涉及到相邻的两个点和待测试点,然后考虑两个问题:

  1. 被测试点的纵坐标testy是否在本次循环所测试的两个相邻点纵坐标范围之内?即
    verty[i] <testy < verty[j]
    或者
    verty[j] <testy < verty[i]

  2. 待测点test是否在i,j两点之间的连线之下?看不懂后半短if statement的朋友请自行在纸上写下i,j两点间的斜率公式,要用到一点初中解析几何和不等式的知识范畴,对广大码农来说小菜一碟。
    然后每次这两个条件同时满足的时候我们把返回的布尔量取反。
    可这到底是啥意思啊?
    这个表达式的意思是说,随便画个多边形,随便定一个点,然后通过这个点水平划一条射线,先数数看这条

    射线和多边形的边相交几次,(或者说先排除那些不相交的边,第一个判断条件),然后再数这条射线穿越多边形的次数是否为奇数,如果是奇数,那么该点在多边形内,如果是偶数,则在多边形外。详细的数学证明这里就不做了,不过读者可以自行画多边形进行验证。
    
    
    以上转载百度知道;以下转载阿凡卢,转载地址:http://www.cnblogs.com/luxiaoxun/p/3722358.html

    判断点是否在多边形内部

    如何判断一个点是否在多边形内部?

    (1)面积和判别法:判断目标点与多边形的每条边组成的三角形面积和是否等于该多边形,相等则在多边形内部。

    (2)夹角和判别法:判断目标点与所有边的夹角和是否为360度,为360度则在多边形内部。

    (3)引射线法:从目标点出发引一条射线,看这条射线和多边形所有边的交点数目。如果有奇数个交点,则说明在内部,如果有偶数个交点,则说明在外部。

    具体做法:将测试点的Y坐标与多边形的每一个点进行比较,会得到一个测试点所在的行与多边形边的交点的列表。在下图的这个例子中有8条边与测试点所在的行相交,而有6条边没有相交。如果测试点的两边点的个数都是奇数个则该测试点在多边形内,否则在多边形外。在这个例子中测试点的左边有5个交点,右边有三个交点,它们都是奇数,所以点在多边形内。

    算法图解:

    关于这个算法的具体的更多图形例子:http://alienryderflex.com/polygon/

    参考代码:

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

    来自一个polygon的内部实现:

          public bool IsInside(PointLatLng p)
    {
    int count = Points.Count;

      </span><span style="color:rgb(0,0,255);line-height:1.5 !important;">if</span>(count &lt; <span style="color:rgb(128,0,128);line-height:1.5 !important;">3</span><span style="line-height:1.5 !important;">){</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span> <span style="color:rgb(0,0,255);line-height:1.5 !important;">false</span><span style="line-height:1.5 !important;">;}</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">bool</span> result = <span style="color:rgb(0,0,255);line-height:1.5 !important;">false</span><span style="line-height:1.5 !important;">;</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">for</span>(<span style="color:rgb(0,0,255);line-height:1.5 !important;">int</span> i = <span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span>, j = count - <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span>; i &lt; count; i++<span style="line-height:1.5 !important;">){</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">var</span> p1 =<span style="line-height:1.5 !important;"> Points[i];</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">var</span> p2 =<span style="line-height:1.5 !important;"> Points[j];</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">if</span>(p1.Lat &lt; p.Lat &amp;&amp; p2.Lat &gt;= p.Lat || p2.Lat &lt; p.Lat &amp;&amp; p1.Lat &gt;=<span style="line-height:1.5 !important;"> p.Lat){</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">if</span>(p1.Lng + (p.Lat - p1.Lat) / (p2.Lat - p1.Lat) * (p2.Lng - p1.Lng) &lt;<span style="line-height:1.5 !important;"> p.Lng){result </span>= !<span style="line-height:1.5 !important;">result;}}j </span>=<span style="line-height:1.5 !important;"> i;}</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span><span style="line-height:1.5 !important;"> result;
    

    }

    特殊情况:要检测的点在多变形的一条边上,射线法判断的结果是不确定的,需要特殊处理(If the test point is on the border of the polygon, this algorithm will deliver unpredictable results)。

    计算一个多边形的面积(area of a polygon):

            private static double SignedPolygonArea(List<PointLatLng> points)
    {
    // Add the first point to the end.
    int pointsCount = points.Count;
    PointLatLng[] pts = new PointLatLng[pointsCount + 1];
    points.CopyTo(pts, 0);
    pts[pointsCount] = points[0];
    
         </span><span style="color:rgb(0,0,255);line-height:1.5 !important;">for</span> (<span style="color:rgb(0,0,255);line-height:1.5 !important;">int</span> i = <span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span>; i &lt; pointsCount + <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span>; ++<span style="line-height:1.5 !important;">i){pts[i].Lat </span>= pts[i].Lat * (System.Math.PI * <span style="color:rgb(128,0,128);line-height:1.5 !important;">6378137</span> / <span style="color:rgb(128,0,128);line-height:1.5 !important;">180</span><span style="line-height:1.5 !important;">);pts[i].Lng </span>= pts[i].Lng * (System.Math.PI * <span style="color:rgb(128,0,128);line-height:1.5 !important;">6378137</span> / <span style="color:rgb(128,0,128);line-height:1.5 !important;">180</span><span style="line-height:1.5 !important;">);}</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Get the areas.</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">double</span> area = <span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span><span style="line-height:1.5 !important;">;</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">for</span> (<span style="color:rgb(0,0,255);line-height:1.5 !important;">int</span> i = <span style="color:rgb(128,0,128);line-height:1.5 !important;">0</span>; i &lt; pointsCount; i++<span style="line-height:1.5 !important;">){area </span>+= (pts[i + <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span>].Lat - pts[i].Lat) * (pts[i + <span style="color:rgb(128,0,128);line-height:1.5 !important;">1</span>].Lng + pts[i].Lng) / <span style="color:rgb(128,0,128);line-height:1.5 !important;">2</span><span style="line-height:1.5 !important;">;}</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Return the result.</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span><span style="line-height:1.5 !important;"> area;}</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span> <span style="color:rgb(128,128,128);line-height:1.5 !important;">&lt;summary&gt;</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Get the area of a polygon</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span> <span style="color:rgb(128,128,128);line-height:1.5 !important;">&lt;/summary&gt;</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span> <span style="color:rgb(128,128,128);line-height:1.5 !important;">&lt;param name="points"&gt;&lt;/param&gt;</span><span style="color:rgb(128,128,128);line-height:1.5 !important;">///</span> <span style="color:rgb(128,128,128);line-height:1.5 !important;">&lt;returns&gt;&lt;/returns&gt;</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">public</span> <span style="color:rgb(0,0,255);line-height:1.5 !important;">static</span> <span style="color:rgb(0,0,255);line-height:1.5 !important;">double</span> GetPolygonArea(List&lt;PointLatLng&gt;<span style="line-height:1.5 !important;"> points){</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> Return the absolute value of the signed area.</span><span style="color:rgb(0,128,0);line-height:1.5 !important;">//</span><span style="color:rgb(0,128,0);line-height:1.5 !important;"> The signed area is negative if the polygon is oriented clockwise.</span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span><span style="line-height:1.5 !important;"> Math.Abs(SignedPolygonArea(points));}</span></pre><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy" style="line-height:1.5 !important;"><a title="复制代码" style="color:#008000;border:none !important;" target="_blank"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border:none !important;"></a></span></div></div><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>参考资料:</p><p>http://alienryderflex.com/polygon/</p><p>http://en.wikipedia.org/wiki/Point_in_polygon</p><p>http://www.codeproject.com/Tips/84226/Is-a-Point-inside-a-Polygon</p><p>&nbsp;</p></div><div id="MySignature" style="background-color:rgb(248,248,238);border:1px solid rgb(232,231,208);color:#808080;"><div style="line-height:25px;">作者:<a href="http://www.cnblogs.com/luxiaoxun/" rel="nofollow" style="color:#008000;text-decoration:none;" target="_blank">阿凡卢</a></div><div style="line-height:25px;">出处:<a href="http://www.cnblogs.com/luxiaoxun/" rel="nofollow" style="color:#008000;text-decoration:none;" target="_blank">http://www.cnblogs.com/luxiaoxun/</a></div><div style="line-height:25px;">本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。</div></div></div><br><pre class="best-text mb-10" style="background-color:rgb(255,255,255);font-family:'Microsoft YaHei', arial, 'courier new', courier, '宋体', monospace;font-size:16px;line-height:29px;min-height:55px;" name="code"><span style="color:#333333;">
    

如何判断一个点是否在多边形内?相关推荐

  1. HDU1756(判断一个点是否在多边形内)

    以下内容是在自己学习中总结出来了的,如果有什么错误,请指出,谢谢! 判断一个点是否在多边形内: (1)判断方法一(具有一定的局限性):将测试点的Y坐标与多边形的每一个点进行比较,将得到一 个与多边形的 ...

  2. 如何判断一个点是否在多边形内?(转)

    转自:https://blog.csdn.net/u011722133/article/details/52813374 在GIS(地理信息管理系统)中,判断一个坐标是否在多边形内部是个经常要遇到的问 ...

  3. [math]判断一个点是否在多边形内的方法

    文章目录 向量叉乘判别法 面积和判别法 夹角和判别法 引射线法 PNPoly算法 多边形的内角是由两条相邻边形成边界之内的角:如果一个多边形的所有内角均小于180°,则该多边形为凸(convex)多边 ...

  4. Java 判断一个点是否在一个多边形内

    工具类 提供:监测点的X轴.Y轴.多边形的多个坐标.如果存在多边形里面返回true,反之返回false import java.awt.geom.Point2D; import java.awt.ge ...

  5. 如何判断一个点是否在一个多边形内?

    提示:对多边形进行分割,成为一个个三角形,判断点是否在三角形内. 一个非常有用的解析几何结论:如果P2(x1,y1),P2(x2,y2), P3(x3,y3)是平面上的3个点,那么三角形P1P2P3的 ...

  6. python判断平面内一个点是否在多边形内

    采用射线法就可以判断一个点是否在多边形内, 只需从点出发向右侧水平做出一条射线,如果跟多边形交点个数为奇数,则点在多边形内,否则在多边形外.看一张图就可以看懂啦 图片来自:https://www.ji ...

  7. 【寒江雪】判断一个点是否在网格内

    判断一个点是否在多边形网格内   根据前几天看到的博客--<判断一个点是否在多边形内>--突发奇想,设计一个算法判断一个点是否在多面体网格内.   这里假设该网格物体都是由许多个三角面构成 ...

  8. JAVA判断一个地理坐标是否在一个多边形区域内和是否在一个圆形区域内(经纬度)

    怎么样判断一个坐标点在一个多边形区域内?包括规则多边形,不规则多边形,还有圆... 1 判断一个坐标是否在圆形区域内? 多边形和圆分开写,首先简单的就是判断是否在圆里面,如何判断一个坐标是否在圆形区域 ...

  9. 判断一个点是否在多边形内部

    一.比如说,我就随便涂了一个多边形和一个点,现在我要给出一种通用的方法来判断这个点是不是在多边形内部(别告诉我用肉眼观察--). 首先想到的一个解法是从这个点做一条射线,计算它跟多边形边界的交点个数, ...

  10. java pnpoly算法_PNPoly算法代码例子,判断一个点是否在多边形里面

    写C语言的实验用到的一个算法,判断一个点是否在多边形的内部.C的代码如下: int pnpoly(int nvert, float *vertx, float *verty, float testx, ...

最新文章

  1. iOS 13 适配TextField 崩溃问题
  2. 一句话回复:关于'SqlMembershipProvider' requires a database schema compatible with schema version '1'...
  3. Hyper-V 2016:支持guest操作系统
  4. amr转换成mp3 java_java将amr文件转换为MP3格式(windowslinux均可使用,亲测)
  5. 免费直播| TDD如何颠覆了我对开发的认知?
  6. python中的corr函数_Python中的相关分析correlation analysis的实现
  7. logrus 输出多个文件_Logrus源码阅读(1)基本用法
  8. [2019杭电多校第七场][hdu6655]Just Repeat
  9. codevs 4189 字典
  10. 离开Autodesk,开启新篇章
  11. GNS3 将虚拟机加入组网
  12. 我为什么开始写博客,并要坚持下去?
  13. pwm调速流程图小车_循迹+pwm调速的小车源程序
  14. 教育与人生:教师节有感
  15. android 让app全屏显示,Android app设置全屏模式
  16. ps CS6 不能直接拖入图片的问题!!win8 系统下
  17. 2021最新《python爬虫从0-1》5.正则表达式讲解
  18. docker挂载mysql会失败_Docker Mysql 挂载 /var/lib/mysql 后无法启动
  19. uniapp web端 支付宝 微信使用当面付
  20. 亚马逊测评的获得方法及测评环境系统介绍,一次诊断全部解决。

热门文章

  1. Day54 Java框架 SSH案例_CRM(二)
  2. 理解Python中的RingBuffer环形缓冲区
  3. 02-Epicor二次开发常用代码
  4. java rrd 读取_RRD插入值的计算方式
  5. CSS:个人常用搜索框样式
  6. 【VS】VS2013如何项目重命名
  7. android多悬浮窗口播放器,Android实现悬浮播放器
  8. qq游戏大厅中解析不安装apk的研究
  9. 骨传导蓝牙耳机什么牌子最好?骨传导蓝牙耳机排名
  10. 23 种设计模式的分类 - Design Patterns