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;
}
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.
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.
The latLonToEcef
method is an implementation of the algorithm outlined in the Geographic coordinate conversion - From geodetic to ECEF coordinates wikipedia page:
where
Φ is latitude, λ is longitude, and
Likewise the ecefToEnu
method is an implementation of the ECEF to ENU algorithm:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With