ECEF坐标转WGS84坐标(C++实现)

本文介绍了如何使用C++代码实现从地球坐标系(ECEF)到世界大地坐标系统(WGS84)的转换,通过一系列数学公式计算经纬度和海拔高度。
摘要由CSDN通过智能技术生成

直接看代码吧

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坐标。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员班长

感谢您的一路相伴

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值