已知经纬度求地球上两地点之间球面距离
2016-04-12 09:49
375 查看
C++代码如下:
//根据地球两点经纬度求两点间弧长
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const double pi = acos(-1.0);
const double EARTH_RADIUS = 6371.004;
double rad(double d)
{
return d * pi / 180.0;
}
double GetDistance(double Lat_1, double Lng_1, double Lat_2, double Lng_2)
{
double radLat_1 = rad(Lat_1);
double radLat_2 = rad(Lat_2);
double a = radLat_1 - radLat_2;
double b = rad(Lng_1) - rad(Lng_2);
double s = 2 * asin(sqrt(pow(sin(a / 2), 2) + cos(radLat_1) * cos(radLat_2) * pow(sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = round(s * 10000) / 10000;
return s;
}
int main()
{
//freopen("a.in", "r", stdin);
//freopen("a.out","w",stdout);
return 0;
}
//根据地球两点经纬度求两点间弧长
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const double pi = acos(-1.0);
const double EARTH_RADIUS = 6371.004;
double rad(double d)
{
return d * pi / 180.0;
}
double GetDistance(double Lat_1, double Lng_1, double Lat_2, double Lng_2)
{
double radLat_1 = rad(Lat_1);
double radLat_2 = rad(Lat_2);
double a = radLat_1 - radLat_2;
double b = rad(Lng_1) - rad(Lng_2);
double s = 2 * asin(sqrt(pow(sin(a / 2), 2) + cos(radLat_1) * cos(radLat_2) * pow(sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = round(s * 10000) / 10000;
return s;
}
int main()
{
//freopen("a.in", "r", stdin);
//freopen("a.out","w",stdout);
return 0;
}
相关文章推荐
- Android彩色二维码带logo
- Linux mv命令
- Struts2 ajax+json账户唯一性验证
- SHELL笔记之网络(六)
- 码农小汪-spring框架学习之8- Using JSR 330 Standard Annotations @Inject and @Named
- html运用(二) html5前端开发基础–html5 meta全解
- php面向对象-关键字的合理运用,public,private,
- maven读取顺序
- Delphi 保存写字板程序, 并进行打印
- HttpContext讲解
- 重构第30天 尽快返回 (Return ASAP)
- Sorting Railway Cars
- js实现页面定时跳转
- android异常捕捉处理-CrashHandler
- HashMap源码注解 之 get()方法(五)
- JAVA设计原则与设计模式
- SHELL笔记之归档(五)
- Linux下安装Git
- Launcher2的桌面预设【1】
- 如何搭建一个git服务器?