Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert latitude and longitude to ECEF coordinates system

I am studying pArk Apple sample code, and how it is works. anyone knows how convert the latitude and longitude to ECEF coordinates, and Covert ECEF to ENU coordinates centered at given lat, lon functions are work? I just want to understand what is going on in this function!

thanks.

void latLonToEcef(double lat, double lon, double alt, double *x, double *y, double *z)
{   
    double clat = cos(lat * DEGREES_TO_RADIANS);
    double slat = sin(lat * DEGREES_TO_RADIANS);
    double clon = cos(lon * DEGREES_TO_RADIANS);
    double slon = sin(lon * DEGREES_TO_RADIANS);

    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;
}
// Coverts ECEF to ENU coordinates centered at given lat, lon
void ecefToEnu(double lat, double lon, double x, double y, double z, double xr, double yr, double zr, double *e, double *n, double *u)
{
    double clat = cos(lat * DEGREES_TO_RADIANS);
    double slat = sin(lat * DEGREES_TO_RADIANS);
    double clon = cos(lon * DEGREES_TO_RADIANS);
    double slon = sin(lon * DEGREES_TO_RADIANS);
    double dx = x - xr;
    double dy = y - yr;
    double dz = z - zr;

    *e = -slon*dx  + clon*dy;
    *n = -slat*clon*dx - slat*slon*dy + clat*dz;
    *u = clat*clon*dx + clat*slon*dy + slat*dz;
}
like image 270
Crazy Avatar asked Oct 20 '13 13:10

Crazy


People also ask

How do you convert LLA to ECEF?

ecef = lla2ecef( lla ) converts an m-by-3 array of geodetic coordinates (latitude, longitude and altitude), lla , to an m-by-3 array of ECEF coordinates, ecef . ecef = lla2ecef( lla , model ) converts the coordinates for a specific ellipsoid planet.

How do you convert XYZ coordinates to latitude and longitude?

Calculate latitude and longitude using the formula: latitude = asin (z/R) and longitude = atan2 (y,x). In this formula, we have the values of x, y, z and R from step 2. Asin is arc sin, which is a mathematical function, and atan2 is a variation of the arc tangent function. The symbol * stands for multiplication.


1 Answers

The latLonToEcef method is an implementation of the algorithm outlined in the Geographic coordinate conversion - From geodetic to ECEF coordinates wikipedia page:

geodetic to ecef

where

Φ is latitude, λ is longitude, and

n-latitude

Likewise the ecefToEnu method is an implementation of the ECEF to ENU algorithm:

ECEF to ENU

If you need further references, they can be found at the bottom of that Wikipedia page. You might also refer to the World Geodetic System 1984 spec.

like image 185
Rob Avatar answered Sep 30 '22 14:09

Rob