用qt实现对已知A点经纬度和A点到B点的距离,以及B点相对A点的方向,求B点的经纬度
时间: 2023-11-22 15:52:24 浏览: 141
已知2点经纬度计算相对方位及距离
5星 · 资源好评率100%
可以使用经纬度坐标系中的球面三角形计算公式来求解B点的经纬度。具体步骤如下:
1. 将A点的经纬度转换为弧度表示:
```
lat1 = qDegreesToRadians(lat_A);
lon1 = qDegreesToRadians(lon_A);
```
2. 根据A点到B点的距离和方向,求出B点与A点的大圆航向角(bearing),并转换为弧度表示:
```
const double R = 6371.0; // 地球半径,单位为千米
double d = distance_AB / 1000.0; // 将距离从米转换为千米
double brng = qDegreesToRadians(direction_AB);
double lat2 = asin(sin(lat1) * cos(d/R) + cos(lat1) * sin(d/R) * cos(brng));
double lon2 = lon1 + atan2(sin(brng) * sin(d/R) * cos(lat1), cos(d/R) - sin(lat1) * sin(lat2));
```
3. 将B点的经纬度从弧度转换为度数表示:
```
lat_B = qRadiansToDegrees(lat2);
lon_B = qRadiansToDegrees(lon2);
```
完整的代码示例:
```cpp
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtMath>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
const double lat_A = 39.9042; // A点的纬度
const double lon_A = 116.4074; // A点的经度
const double distance_AB = 5000.0; // A点到B点的距离,单位为米
const double direction_AB = 45.0; // A点到B点的方向,单位为度数,正北方向为0度,顺时针递增
double lat1 = qDegreesToRadians(lat_A);
double lon1 = qDegreesToRadians(lon_A);
const double R = 6371.0; // 地球半径,单位为千米
double d = distance_AB / 1000.0; // 将距离从米转换为千米
double brng = qDegreesToRadians(direction_AB);
double lat2 = asin(sin(lat1) * cos(d/R) + cos(lat1) * sin(d/R) * cos(brng));
double lon2 = lon1 + atan2(sin(brng) * sin(d/R) * cos(lat1), cos(d/R) - sin(lat1) * sin(lat2));
double lat_B = qRadiansToDegrees(lat2);
double lon_B = qRadiansToDegrees(lon2);
qDebug() << "B点的经度:" << lon_B << ",纬度:" << lat_B;
return a.exec();
}
```
阅读全文