gps坐标转大地直角坐标代码c++
时间: 2023-10-23 22:09:25 浏览: 81
大地测量_坐标转换_c++代码
以下是C++代码,用于将经纬度坐标转换为大地直角坐标:
```c++
#include <iostream>
#include <cmath>
const double a = 6378137.0; // WGS84椭球长轴半径
const double f = 1.0 / 298.257223563; // WGS84椭球扁率
double rad(double d) {
return d * M_PI / 180.0;
}
void llh2xyz(double lat, double lon, double height, double &x, double &y, double &z) {
double e2 = 2 * f - f * f;
double n = a / sqrt(1 - e2 * sin(rad(lat)) * sin(rad(lat)));
x = (n + height) * cos(rad(lat)) * cos(rad(lon));
y = (n + height) * cos(rad(lat)) * sin(rad(lon));
z = (n * (1 - e2) + height) * sin(rad(lat));
}
int main() {
double lat = 31.2304;
double lon = 121.4737;
double height = 10.0;
double x, y, z;
llh2xyz(lat, lon, height, x, y, z);
std::cout << "经度:" << lon << "\t纬度:" << lat << "\t高度:" << height << std::endl;
std::cout << "X:" << x << "\tY:" << y << "\tZ:" << z << std::endl;
return 0;
}
```
在此示例中,输入的经纬度坐标是31.2304和121.4737,高度为10米。函数`llh2xyz`将其转换为大地直角坐标系下的X、Y、Z值,并输出结果。
阅读全文