直接看代码吧
static constexpr double A = 6378137.0;
static constexpr double ONE_F = 298.257223563;
static constexpr double B = A * (1.0 - 1.0 / ONE_F);
static constexpr double E2 = (1.0 / ONE_F) * (2 - (1.0 / ONE_F));
static constexpr double ED2 = E2 * A * A / (B * B);
static constexpr double PI_180 = M_PI / 180.0;
std::vector<double> ecef2blh(double x, double y, double z)
{
auto n = [this](double x) {
return A / std::sqrt(1.0 - E2 * std::sin(x * PI_180) * std::sin(x * PI_180));
};
double p = std::sqrt(x * x + y * y);
double theta = std::atan2(z * A, p * B) / PI_180;
double lat = std::atan2(
z + ED2 * B * std::sin(theta * PI_180) * std::sin(theta * PI_180) * std::sin(theta * PI_180),
p - E2 * A * std::cos(theta * PI_180) * std::cos(theta * PI_180) * std::cos(theta * PI_180)
) / PI_180;
double lon = std::atan2(y, x) / PI_180;
double ht = (p / std::cos(lat * PI_180)) - n(lat);
return { lat, lon, ht };
}
调用ecef2blh函数即可,参数为ECEF的x、y、z坐标,返回值为WGS84的x、y、z坐标。
本文介绍了如何使用C++代码实现从地球坐标系(ECEF)到世界大地坐标系统(WGS84)的转换,通过一系列数学公式计算经纬度和海拔高度。
1703

被折叠的 条评论
为什么被折叠?



