日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

通过经度纬度得到距离

發布時間:2024/4/11 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 通过经度纬度得到距离 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

C#的寫法

public struct EarthPoint
? {
?? public const double Ea = 6378137; // 赤道半徑 WGS84標準參考橢球中的地球長半徑(單位:m)?
?? public const double Eb = 6356725; // 極半徑??
?? public readonly double Longitude,Latidute;
?? public readonly double Jd;
?? public readonly double Wd;
?? public readonly double Ec;
?? public readonly double Ed;
?? public EarthPoint(double _Longitude,double _Latidute)
?? {
??? Longitude = _Longitude;
??? Latidute = _Latidute;
??? Jd = Longitude * Math.PI / 180; //轉換成角度
??? Wd = Latidute * Math.PI /180; //轉換成角度
??? Ec = Eb + (Ea - Eb) * (90 - Latidute) / 90;
??? Ed = Ec * Math.Cos(Wd);
?? }
?? public double Distance(EarthPoint _Point)
?? {
??? double dx = (_Point.Jd - Jd) * Ed;
??? double dy = (_Point.Wd - Wd) * Ec;
??? return Math.Sqrt(dx * dx + dy *dy);
?? }
? }

public static Double GetDistance(double _Longitude1,
?? double _Latidute1,
?? double _Longitude2,
?? double _Latidute2)
? {
?? EarthPoint p1 = new EarthPoint(_Longitude1,_Latidute1);
?? EarthPoint p2 = new EarthPoint(_Longitude2,_Latidute2);
?? return p1.Distance(p2);
? }

C#的寫法,可惜不會用,所以將上面的代碼改造一下,形成C++的寫法

C++的寫法:

#include <math.h>
const double Ea = 6378137; // 赤道半徑 WGS84標準參考橢球中的地球長半徑(單位:m)?
const double Eb = 6356725; // 極半徑
#define PI 3.1416926;
class EarthPoint
{
public:?
??? double Longitude,Latidute;
??? double Jd;
??? double Wd;
??? double Ec;
??? double Ed;

??? EarthPoint(double _Longitude,double _Latidute)
??? {
??????? Longitude = _Longitude;
??????? Latidute = _Latidute;
??????? Jd = Longitude * 3.1415926 / 180; //轉換成角度
??????? Wd = Latidute * 3.1415926 / 180; //轉換成角度
??????? Ec = Eb + (Ea - Eb) * (90 - Latidute) / 90;
??????? Ed = Ec * cos(Wd);
??? }

??? double Distance(EarthPoint * _Point)
??? {
??????? double dx = (_Point->Jd - Jd) * Ed;
??????? double dy = (_Point->Wd - Wd) * Ec;
??????? return sqrt(dx * dx + dy *dy);
??? }
};

double GetDistance(double _Longitude1,
?????????????????? double _Latidute1,
?????????????????? double _Longitude2,
?????????????????? double _Latidute2)
{
??? EarthPoint *p1 = new EarthPoint(_Longitude1,_Latidute1);
??? EarthPoint *p2 = new EarthPoint(_Longitude2,_Latidute2);
??? double d=p1->Distance(p2);
??? return d;
}

總結

以上是生活随笔為你收集整理的通过经度纬度得到距离的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。