在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. vmx转换ofv模板,导入esxi
  2. MySQL外键与外键关系说明(简单易懂)
  3. 叔叔我要可乐,要冰冻的
  4. Todolist总结
  5. 网易视频云分享:如何搭建视频转码集群
  6. 世界上最诡异的画,到底为何让无数人闻风丧胆?
  7. 微信小程序request:fail invalid url
  8. PHP学习之六:预定义常量
  9. 服务器如何关闭登录日志文件,linux云服务器登录日志文件
  10. 毕设系列之 -- 基于大数据的全国热门旅游景点数据分析与可视化
  11. 2021秋招IC验证面经-ARM中国/中科芯/飞腾/地平线/中兴
  12. matlab 图片数字化,基于MATLAB的尾流图像数字化处理
  13. 计算机二级刷题库刷的到原题吗,刷题能过计算机二级吗?
  14. android 支付宝 地图,支付宝小程序地图组件 地图·Map
  15. reflections歌词翻译_问:关于玛丽亚凯莉的一首Reflections 的中文翻译(不要翻译机!)...
  16. 空气质量等级c语言编程,关于SDS011模块(空气中pm2.5及pm10)单片机c程序实现(链接附源码)...
  17. Docker 18.09.0更换阿里镜像加速器
  18. 校园表白墙网站PHP源码
  19. java spark 二进制_spark数据源操作
  20. JavaSE基本数据类型

热门文章

  1. 安装CAD2006出现html,win7系统安装cad2006出现已终止CAD2006-Simplifieng安装的解决方法...
  2. 体验服官网和平精英维护服务器,和平精英体验服怎么注册?和平精英体验服注册流程...
  3. css小猫笑起来的动画
  4. 指数分布具有“无记忆性”
  5. 内存空间的分配与回收
  6. 方正飞鸿智能信息平台(FIX ES2007)帮助手册+知识库
  7. 分享ZKEYS公有云分销系统部署详细教程
  8. java版12306抢票_GitHub - a1647517212/J12306: 12306抢票程序JAVA版
  9. R语言古风诗人转职c++
  10. 第三方支付-分账接口对接