大地坐标系转换经纬度 c++
时间: 2023-11-24 14:53:18 浏览: 167
以下是C++中实现大地坐标系转换经纬度的示例代码:
```cpp
#include <iostream>
#include <cmath>
using namespace std;
const double a = 6378137.0; // 长半轴
const double b = 6356752.3142; // 短半轴
const double f = (a - b) / a; // 扁率
const double e = sqrt(2 * f - f * f); // 第一偏心率
const double e2 = e * e; // 第二偏心率
double rad(double d) {
return d * M_PI / 180.0;
}
void BLHtoXYZ(double B, double L, double H, double &X, double &Y, double &Z) {
double N = a / sqrt(1 - e2 * sin(rad(B)) * sin(rad(B)));
X = (N + H) * cos(rad(B)) * cos(rad(L));
Y = (N + H) * cos(rad(B)) * sin(rad(L));
Z = (N * (1 - e2) + H) * sin(rad(B));
}
void XYZtoBLH(double X, double Y, double Z, double &B, double &L, double &H) {
double p = sqrt(X * X + Y * Y);
double theta = atan2(Z * a, p * b);
B = atan2(Z + e2 * b * pow(sin(theta), 3), p - e2 * a * pow(cos(theta), 3));
L = atan2(Y, X);
double N = a / sqrt(1 - e2 * sin(B) * sin(B));
H = p / cos(B) - N;
}
int main() {
double B = 31.2304, L = 121.4737, H = 10.0;
double X, Y, Z;
BLHtoXYZ(B, L, H, X, Y, Z);
cout << "X: " << X << ", Y: " << Y << ", Z: " << Z << endl;
XYZtoBLH(X, Y, Z, B, L, H);
cout << "B: " << B << ", L: " << L << ", H: " << H << endl;
return 0;
}
```
阅读全文
相关推荐















