如何计算大地坐标(ECEF)与本地参考(ENU)之间的直接和反向转换

时间:2011-06-08 09:21:28

标签: c gps wgs84

如何将X,Y,Z从本地参考(ENU)转换为世界参考(ECEF)并将其反转?

输入:

(lat,long) = center of the local reference system.
       x,y,z = position of the point,in local system reference.

输出:(lat,long)= WGS84中点的设定值。 另外:反向坐标。

我想这一步是:

1) convert Xlocal,Ylocal,Zlocal  -> Xecef,Yecef,Zecef

2) convert Xecef,Yecef,Zecef     -> Lat,Long (WGS84)

而不是

1) convert Lat,Long(WGS84)       -> Xecef,Yecef,Zecef

2) convert Xecef,Yecef,Zecef     -> Xlocal,Ylocal,Zlocal

2 个答案:

答案 0 :(得分:2)

军械测量局已发表A Guide to Coordinate Systems in Great Britain。这是一个PDF文档,其中包含用于在纬度/长度和笛卡尔坐标之间进行转换的数学算法。显然它面向英国系统,但WGS84所需的参数在指南中给出。

答案 1 :(得分:0)

我正在开发一个地理空间AR应用程序,并且刚刚在Objective-C / iOS中解决了这个问题(来自Apple的this example code提供了很多帮助。)

从lat lon到ecef转换为ENU并返回的三个C函数如下。数学公式来自this维基百科文章。

#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
#define DEGREES_TO_RADIANS(degrees)((M_PI * degrees)/180)

#define WGS84_A (6378137.0)             // WGS 84 semi-major axis constant in meters
#define WGS84_E (8.1819190842622e-2)    // WGS 84 eccentricity

// Converts latitude, longitude to ECEF coordinate system
void latLonToEcef(double lat, double lon, double alt, double *x, double *y, double *z)
{
    double clat = cos(DEGREES_TO_RADIANS(lat));
    double slat = sin(DEGREES_TO_RADIANS(lat));
    double clon = cos(DEGREES_TO_RADIANS(lon));
    double slon = sin(DEGREES_TO_RADIANS(lon));

    double N = WGS84_A / sqrt(1.0 - WGS84_E * WGS84_E * slat * slat);

    *x = (N + alt) * clat * clon;
    *y = (N + alt) * clat * slon;
    *z = (N * (1.0 - WGS84_E * WGS84_E) + alt) * slat;
}

// Converts ECEF to ENU coordinates centered at given lat, lon
void ecefToEnu(double lat, double lon, double xRef, double yRef, double zRef, double xPOI, double yPOI, double zPOI, double *e, double *n, double *u)
{
    double clat = cos(DEGREES_TO_RADIANS(lat));
    double slat = sin(DEGREES_TO_RADIANS(lat));
    double clon = cos(DEGREES_TO_RADIANS(lon));
    double slon = sin(DEGREES_TO_RADIANS(lon));
    double dx = xPOI - xRef;
    double dy = yPOI - yRef;
    double dz = zPOI - zRef;

    *e = -slon * dx  + clon * dy;
    *n = -slat * clon * dx - slat * slon * dy + clat * dz;
    *u = clat * clon * dx + clat * slon * dy + slat * dz;
}
// Converts ENU of a POI (in realtion to a reference point) to ECEF coordinates
void enuToEcef(double lat, double lon, double xRef, double yRef, double zRef, double *xPOI, double *yPOI, double *zPOI, double e, double n, double u)
{
    double clat = cos(DEGREES_TO_RADIANS(lat));
    double slat = sin(DEGREES_TO_RADIANS(lat));
    double clon = cos(DEGREES_TO_RADIANS(lon));
    double slon = sin(DEGREES_TO_RADIANS(lon));

    *xPOI = (-slon * e) + (-slat * clon * n) + (clat * clon * u) + xRef;
    *yPOI = (clon * e)  + (-slat * slon * n) + (clat * slon * u) + yRef;
    *zPOI = (0 * e)     + (clat * n)         + (slat * u)        + zRef;

}