如何判斷乙個指定的經緯度點是否落在乙個多邊形內

2021-06-06 05:53:55 字數 2492 閱讀 2792

1、理論支援:如果從需要判斷的點出發的一條射線與該多邊形的焦點個數為奇數,則該點在此多邊形內,否則該點在此多邊形外。(射線不能與多邊形頂點相交)

2、程式設計思路:

該程式的思路是從a點出發向左做一條水平射線(平行於x軸,向x軸的反方向),判斷與各邊是否有焦點。

dlon1, dlon2, dlat1, dlat2分別表示邊的起點和終點的經度和緯度(x軸和y軸)。

先判斷a點是否在邊的兩端點d1和d2的水平平行線之間,不在則不可能有交點,繼續判斷下一條邊。

在之間則說明可能與a點向左的射線有交點,接下來利用幾何方法得到a點的水平直線與該邊交點的x座標。

然後判斷交點的x座標在a點的左側還是右側,左側則總交點數加一,右側則不在a點左射線上,繼續判斷下一條邊。

3、原文**如下(dephi):

type

tmypoint

=packed

record

x : double;

y : double;

end;

function

isptinpoly(alon, alat: double; apoints:

array

oftmypoint): boolean;

varisum, icount, iindex: integer;

dlon1, dlon2, dlat1, dlat2, dlon: double;

begin

result :

=false;

if(length(apoints)

<3)

then

begin

result :

=false;

exit;

end;

isum :=0

;icount :

=length(apoints);

foriindex :=0

toicount -1

dobegin

if(iindex

=icount -1

) then

begin

dlon1 :

=apoints[iindex].x;

dlat1 :

=apoints[iindex].y;

dlon2 :

=apoints[

0].x;

dlat2 :

=apoints[

0].y;

endelse

begin

dlon1 :

=apoints[iindex].x;

dlat1 :

=apoints[iindex].y;

dlon2 :

=apoints[iindex +1

].x;

dlat2 :

=apoints[iindex +1

].y;

end;

//以下語句判斷a點是否在邊的兩端點的水平平行線之間,在則可能有交點,開始判斷交點是否在左射線上

if((alat

>=

dlat1)

and(alat

<

dlat2))

or((alat

>=

dlat2)

and(alat

<

dlat1))

then

begin

if(abs(dlat1

-dlat2)

>0)

then

begin

//得到 a點向左射線與邊的交點的x座標

:dlon :

=dlon1

-((dlon1

-dlon2)

*(dlat1

-alat))

/(dlat1

-dlat2);

// 如果交點在a點左側(說明是做射線與 邊的交點),則射線與邊的全部交點數加一:if

(dlon

<

alon)

then

inc(isum);

end;

end;

end;

if(isum

mod2

<>0)

then

result :

=true;

end;

(c#)

public bool isptinpoly(double alon, double alat, listapoints)

else

//以下語句判斷a點是否在邊的兩端點的水平平行線之間,在則可能有交點,開始判斷交點是否在左射線上

if (((alat >= dlat1) && (alat < dlat2)) || ((alat >= dlat2) && (alat < dlat1)))}}

if (isum % 2 != 0)

return true;

return false;

}

判斷乙個點是否在一組經緯度包圍圈內

將判斷點經緯度塞入point2d.double中,將包圍圈放入點集之中。public static boolean isinpolygon arraylistbound,double pointlng,double pointlat return check point,pointlist 將點集中...

根據經緯度 角度 距離獲取另乙個點的經緯度

這就需要根據獲取到的經緯度獲取計算半徑內4個點的座標 計算方法 phppublic static function getrandlnglat lng,lat,angle,distance 其實高德地圖提供了方法,使用很簡單 amap.event.addlistener placesearch,ma...

PHP判斷乙個點的經緯度是否在多邊形或圓內

判斷乙個座標是否在圓內 思路 判斷此點的經緯度到圓心的距離 然後和半徑做比較 如果此點剛好在圓上 則返回true param point lng lat array指定點的座標 param circle array center lng lat radius 中心點和半徑 function is p...