日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

java 球面距离_[置顶] C语言实验题:已知地球上两点的经度和纬度求其球面距离...

發(fā)布時(shí)間:2025/3/20 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 球面距离_[置顶] C语言实验题:已知地球上两点的经度和纬度求其球面距离... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

要求:地球的平均半徑為6371千米,已知地球上兩個(gè)城市A、B的經(jīng)度和緯度,編程序求出這兩個(gè)城市之間的地面距離。

首先,固定兩點(diǎn),a(x1,y1,z1),b(x2,y2,z2)。

由空間解析幾何及向量知識知:

其中,theta是兩向量夾角,球面距離d:

對于A點(diǎn)來說(圖中a應(yīng)改為A,畫圖的時(shí)候?qū)戝e(cuò)了),

theta就是A點(diǎn)的緯度值,即:

也即:

而對于A點(diǎn)的x,y坐標(biāo),首先:

r1是小圓的半徑,也就是下圖中的藍(lán)色圓:

請注意平面圖與立體圖中坐標(biāo)的對應(yīng),我已一一對應(yīng)好,注意觀察。

圖中的alpha即:

所以,坐標(biāo)與經(jīng)度之間有如下關(guān)系:

實(shí)際的北極點(diǎn)是這樣的:

還有一點(diǎn),東西經(jīng)南北緯轉(zhuǎn)化問題。

關(guān)于東西經(jīng)和南北緯,在上面的闡述中,東經(jīng)的點(diǎn)的y值都是正值,西經(jīng)的點(diǎn)的y值都是負(fù)值,北緯的點(diǎn)的z值都是正值,南緯的點(diǎn)的z值都是負(fù)值。因?yàn)槿缦聢D,地球被分為了東北半球,東南半球,西北半球,西南半球:

如上分析,不難寫出如下代碼:

#include

#include

#include

#include

#include

using namespace std;

#define pi 3.1415926535

#define radio 6378137.0

//defining a new struct for the convenience of calculating

typedef struct

{

long double Longitude;

long double Lantitude;

string East_or_West;

string North_or_South;

} dot;

//function for calculating

int Distance(float lat1, float lon1, float lat2, float lon2)

{

double latitude1,longitude1,latitude2,longitude2;

double dlat,dlon;

latitude1=lat1;

longitude1=lon1;

latitude2=lat2;

longitude2=lon2;

//computing procedure

double a,c,distance;

dlon =fabs((longitude2 - longitude1))*pi/180;

dlat =fabs((latitude2 - latitude1))*pi/180;

a = (sin(dlat/2)*sin(dlat/2)) + cos(latitude1*pi/180) * cos(latitude2*pi/180) * (sin(dlon/2)*sin(dlon/2));

if(a==1.0)

c=pi;

else

c = 2 * atan(sqrt(a)/sqrt(1-a));

distance= radio*c;

return distance;

}

int main()

{

long double r = 6371.004;

dot a, b;

//freopen("D:\example.txt","r",stdin);

while(1)

{

cout<

cout<

//data input procedure

cin>>a.East_or_West>>a.Longitude>>a.North_or_South>>a.Lantitude;

cin>>b.East_or_West>>b.Longitude>>b.North_or_South>>b.Lantitude;

//transfer

{

if(a.East_or_West == "East")

{

a.Longitude = a.Longitude;

}

else if(a.East_or_West == "West")

{

a.Longitude = - a.Longitude;

}

}

{

if(a.North_or_South == "North")

{

a.Lantitude = pi / 2 - a.Lantitude;

}

else if (a.North_or_South == "South")

{

a.Lantitude = pi / 2 + a.Lantitude;

}

}

{

if(b.East_or_West == "East")

{

b.Longitude = b.Longitude;

}

else if(a.East_or_West == "West")

{

b.Longitude = - b.Longitude;

}

}

{

if(a.North_or_South == "North")

{

b.Lantitude = pi / 2 - b.Lantitude;

}

else if (a.North_or_South == "South")

{

b.Lantitude = pi / 2 + b.Lantitude;

}

}

//data output procedure

float result = Distance(a.Lantitude, a.Longitude, b.Lantitude, b.Longitude);

cout<

}

}

可能有所紕漏,因?yàn)榈谝槐閷懘a的時(shí)候沒這么仔細(xì)分析。

想要更深層次了解此問題,請參看微分幾何中關(guān)于測地線及測地線曲率的相關(guān)問題。

欲證明該思想的正確性,可以采取如下反證法:

假設(shè)通過二點(diǎn)存在一個(gè)小圓對應(yīng)的劣弧長比球面距離小,那條曲線未必是平面曲線,所以未必是圓弧。

總結(jié)

以上是生活随笔為你收集整理的java 球面距离_[置顶] C语言实验题:已知地球上两点的经度和纬度求其球面距离...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。