地心地固坐标系(ECEF)和WGS-84坐标系(WGS84)互转

//经纬度WGS-84坐标系(WGS84)转 地心地固坐标系(ECEF)
myPoint WGS84toECEF(double latitude, double longitude, double height)
{
	double X;
	double Y;
	double Z;
	double a = 6378137;
	double b = 6356752.314245;
	double E = (a * a - b * b) / (a * a);
	double COSLAT = cos(latitude * PI / 180);
	double SINLAT = sin(latitude * PI / 180);
	double COSLONG = cos(longitude * PI / 180);
	double SINLONG = sin(longitude * PI / 180);
	double N = a / (sqrt(1 - E * SINLAT * SINLAT));
	double NH = N + height;
	X = NH * COSLAT * COSLONG;
	Y = NH * COSLAT * SINLONG;
	Z = (b * b * N / (a * a) + height) * SINLAT;
	return myPoint(X, Y, Z);
}

//地心地固坐标系(ECEF)转 经纬度WGS-84坐标系(WGS84)
void ECEFtoWGS84(myPoint pt, double& lon, double& lat, double& altitude)
{
	double x = pt.X(), y = pt.Y(), z = pt.Z();
	double a, b, c, d;
	double p, q;
	double N;
	a = 6378137.0;
	b = 6356752.31424518;
	c = sqrt(((a * a) - (b * b)) / (a * a));
	d =	sqrt(((a * a) - (b * b)) / (b * b));
	p = sqrt((x * x) + (y * y));
	q = atan2((z * a), (p * b));
	lon = atan2(y, x);
	lat = atan2((z + (d * d) * b * pow(sin(q), 3)), (p - (c * c) * a * pow(cos(q), 3)));
	N = a / sqrt(1 - ((c * c) * pow(sin(lat), 2)));
	altitude = (p / cos(lat)) - N;
	lon = lon * 180.0 / PI;
	lat = lat * 180.0 / PI;
}

以下是经纬高坐标系(LLH)到地心地坐标系ECEF)的换代码示例(C++): ```cpp #include <cmath> // WGS84椭球参数 const double a = 6378137.0; // 长半轴 const double b = 6356752.3142; // 短半轴 const double f = (a - b) / a; // 扁率 // LLHECEF void llh2ecef(const double& lat, const double& lon, const double& alt, double& x, double& y, double& z) { double N = a / std::sqrt(1 - f * f * std::sin(lat) * std::sin(lat)); x = (N + alt) * std::cos(lat) * std::cos(lon); y = (N + alt) * std::cos(lat) * std::sin(lon); z = (N * (1 - f * f) + alt) * std::sin(lat); } ``` 以下是地心地坐标系ECEF)到局部东北天坐标系(ENU)的换代码示例(C++): ```cpp // ECEFENU void ecef2enu(const double& x, const double& y, const double& z, const double& lat0, const double& lon0, const double& alt0, double& e, double& n, double& u) { double dx = x - (std::sin(lat0) * std::cos(lon0) * y - std::sin(lat0) * std::sin(lon0) * x + std::cos(lat0) * z); double dy = y - (-std::sin(lon0) * dx + std::cos(lon0) * y); double dz = z - (std::cos(lat0) * std::cos(lon0) * x + std::cos(lat0) * std::sin(lon0) * y + std::sin(lat0) * z); e = -std::sin(lon0) * dx + std::cos(lon0) * dy; n = -std::sin(lat0) * std::cos(lon0) * dx - std::sin(lat0) * std::sin(lon0) * dy + std::cos(lat0) * dz; u = std::cos(lat0) * std::cos(lon0) * dx + std::cos(lat0) * std::sin(lon0) * dy + std::sin(lat0) * dz; } ``` 需要注意的是,以上代码示例中输入参数的单位应该是弧度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值