经纬度坐标系转东北天_大地坐标系(WGS-84)、地心地固坐标系(ECEF)与东北天坐标系(ENU)的相互转换C语言代码分享...
//ECEF ---> WGS84
//pcg為WGS-84坐標系結構體指針,pcc為ECEF坐標系結構體指針
void ECEFToWGS(PWGS pcg, PECEF pcc)
{
double B0, R, N;
double B_, L_;
double X = pcc->x;
double Y = pcc->y;
double Z = pcc->z;
R = sqrt(X * X + Y * Y);
B0 = atan2(Z, R);
while (1)
{
N = dSemiMajorAxis / sqrt(1.0 - e2 * sin(B0) * sin(B0));
B_ = atan2(Z + N * e2 * sin(B0), R);
if (fabs(B_ - B0) < 1.0e-10)
break;
B0 = B_;
}
L_ = atan2(Y, X);
pcg->height = R / cos(B_) - N;
//弧度轉換成經緯度
pcg->latitude = B_ * 180 / M_PI;
pcg->longitude = L_ * 180 / M_PI;
}
//ECEF ---> ENU
//pcc為ECEF坐標系結構體指針,center為東北天坐標原點的指針,pct為東北天坐標系結構體指針
//坐標原點center要用GPS采到的第一個點的數據
void ECEFToENU(PECEF pcc, PWGS center, PENU pct)
{
double dX, dY, dZ;
PECEF Geodetic;
Geodetic = (PECEF)malloc(sizeof(ECEF));
WGSToECEF(center, Geodetic);
dX = pcc->x - Geodetic->x;
dY = pcc->y - Geodetic->y;
dZ = pcc->z - Geodetic->z;
double B, L, H;
B = center->latitude;
L = center->longitude;
H = center->height;
pct->easting = -sin(L) * dX + cos(L) * dY; //X軸
pct->northing = -sin(B) * cos(L) * dX - sin(B) * sin(L) *
dY + cos(B) * dZ; //Y軸
pct->upping = cos(B) * cos(L) * dX + cos(B) * sin(L) * dY +
sin(B) * dZ;?//Z軸
free(Geodetic);
}
//ENU ---> ECEF
//pcc為ECEF坐標系結構體指針,center為東北天坐標原點的指針,pct為東北天坐標系結構體指針
//坐標原點center要用GPS采到的第一個點的數據
void ENUToECEF(PECEF pcc, PWGS center, PENU pct)
{
PECEF Geodetic;
Geodetic = (PECEF)malloc(sizeof(ECEF));
WGSToECEF(center, Geodetic);
double B, L, H;
B = center->latitude;
L = center->longitude;
H = center->height;
pcc->x = -sin(B) * cos(L) * pct->northing - sin(L) *
pct->easting + cos(B) * cos(L) * pct->upping +
Geodetic->x;
pcc->y = -sin(B) * sin(L) * pct->northing + cos(L) *
pct->easting + cos(B) * sin(L) * pct->upping +
Geodetic->y;
pcc->z = cos(B) * pct->northing + sin(B) *
pct->upping + Geodetic->z;
free(Geodetic);
}
總結
以上是生活随笔為你收集整理的经纬度坐标系转东北天_大地坐标系(WGS-84)、地心地固坐标系(ECEF)与东北天坐标系(ENU)的相互转换C语言代码分享...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python parser count_
- 下一篇: python文本编辑器报错_notepa