Transformation of ECEF Coordinates to Geodetic Coordinates

Last updated:

The transformation from ECEF (Earth Centered Earth Fixed) coordinates to geodetic coordinates is a well-known problem in geodesy. The rough transformation could be done by using arctan\arctan function, assuming that the Earth is a sphere. However, for the realistic transformation, the Earth should be approximated by a spheroid, and the transformation in this case is not trivial.

ECEF Coordinate System and Geodetic Coordinate System

Let us first think about a point rsite\bm{r}_\mathrm{site} on the Earth surface. The Earth is approximated by a spheroid, which is axi-symmetric around the Earth rotation axis and slightly squashed in the north-south direction. Thus, a point on the Earth surface can be described by Eq. (1).

rsite=[RcosφrdcosλRcosφrdsinλbsinφrd]\begin{gather} \boldsymbol{r}_\mathrm{site} = \left[ \begin{array}{c} R_\oplus \cos\varphi_\mathrm{rd} \cos\lambda \\ R_\oplus \cos\varphi_\mathrm{rd} \sin\lambda \\ b_\oplus \sin\varphi_\mathrm{rd} \end{array} \right] \end{gather}

ecef-geodetic-1 Figure 1: Spheroidal Earth Geometry and Geodetic Coordinate Parameters.

On the other hand, rsite\bm{r}_\mathrm{site} can be described as Eq. (2), and it should be possible to write rsiter_\mathrm{site} as a function of φgc\varphi_\mathrm{gc}.

rsite=[rsitecosφgccosλrsitecosφgcsinλrsitesinφgc]\begin{gather} \boldsymbol{r}_\mathrm{site} = \left[ \begin{array}{c} r_\mathrm{site} \cos\varphi_\mathrm{gc} \cos\lambda \\ r_\mathrm{site} \cos\varphi_\mathrm{gc} \sin\lambda \\ r_\mathrm{site} \sin\varphi_\mathrm{gc} \end{array} \right] \end{gather}

Comparing Eq. (1) and Eq. (2), the following relationship can be found betwen φrd\varphi_\mathrm{rd} and φgc\varphi_\mathrm{gc}.

tanφgc=bRtanφrd\begin{gather} \tan \varphi_\mathrm{gc} = \frac{b_\oplus}{R_\oplus} \tan \varphi_\mathrm{rd} \end{gather}

The next step is to find the relationship between φrd\varphi_\mathrm{rd} and φgd\varphi_\mathrm{gd}. The tangential directions at the point rsite\bm{r}_\mathrm{site} can be specified by differentiating rsite\bm{r}_\mathrm{site} with respect to φrd\varphi_\mathrm{rd} and λ\lambda.

ddφrdrsite=[RsinφrdcosλRsinφrdsinλbcosφrd],ddλrsite=[Rcosφrdsinλ+Rcosφrdcosλ0].\begin{align} \frac{d}{d\varphi_\mathrm{rd}} \boldsymbol{r}_\mathrm{site} &= \left[ \begin{array}{c} -R_\oplus \sin\varphi_\mathrm{rd} \cos\lambda \\ -R_\oplus \sin\varphi_\mathrm{rd} \sin\lambda \\ b_\oplus \cos\varphi_\mathrm{rd} \end{array} \right], \\ \frac{d}{d\lambda} \boldsymbol{r}_\mathrm{site} &= \left[ \begin{array}{c} -R_\oplus\cos\varphi_\mathrm{rd} \sin\lambda \\ +R_\oplus\cos\varphi_\mathrm{rd} \cos\lambda \\ 0 \end{array} \right]. \\ \end{align}

From the above equations, the normal direction at the point rsite\bm{r}_\mathrm{site} can be obtained by

n=[bcosφrdcosλbcosφrdsinλRsinφrd]\begin{gather} \boldsymbol{n} = \left[ \begin{array}{c} b_\oplus \cos\varphi_\mathrm{rd} \cos\lambda \\ b_\oplus \cos\varphi_\mathrm{rd} \sin\lambda \\ R_\oplus \sin\varphi_\mathrm{rd} \end{array} \right] \end{gather}

Based on the normal direction, the relationship between reduced latitude φrd\varphi_\mathrm{rd} and geodetic latitude φgd\varphi_\mathrm{gd} can be obtained.

tanφgd=Rbtanφrd\begin{gather} \tan \varphi_\mathrm{gd} = \frac{R_\oplus}{b_\oplus} \tan \varphi_\mathrm{rd} \end{gather}

From Eq. (3) and Eq. (7), the geocentric latitude φgc\varphi_\mathrm{gc} can be described by using the geodetic latitude φgd\varphi_\mathrm{gd}.

tanφgc=b2R2tanφgd\begin{gather} \tan \varphi_\mathrm{gc} = \frac{b_\oplus^2}{R_\oplus^2} \tan \varphi_\mathrm{gd} \end{gather}

In this way, the transformation from geocentric parameters to geodetic parameters can be performed on the surface of the Earth. However, as we are interested in the transformation of the on-orbit satellite position (x,y,z)(x, y, z) to the geodetic parameters, some additional steps are required. Now, the goal is to describe (x,y,z)(x, y, z) with the geodetic parameters and then reversly solve the relation.

[xyz]=[(C+hellp)cosφgdcosλ(C+hellp)cosφgdsinλ(S+hellp)sinφgd]\begin{align} \left[ \begin{array}{c} x \\ y \\ z \end{array} \right] = \left[ \begin{array}{c} (C_\oplus + h_\mathrm{ellp}) \cos\varphi_\mathrm{gd} \cos\lambda \\ (C_\oplus + h_\mathrm{ellp}) \cos\varphi_\mathrm{gd} \sin\lambda \\ (S_\oplus + h_\mathrm{ellp}) \sin\varphi_\mathrm{gd} \end{array} \right] \end{align}

As (x,y,z)(x, y, z) coordinates can be described by Eq. (9), we should specify the parameters CC_\oplus and SS_\oplus.

rδ=rsitecosφgc=Rcosφrd=Ccosφgdrk=rsitesinφgc=R1e2sinφrd=Ssinφgd\begin{align} r_\delta &= r_\mathrm{site} \cos \varphi_\mathrm{gc} = R_\oplus \cos \varphi_\mathrm{rd} = C_\oplus \cos \varphi_\mathrm{gd} \\ r_\mathrm{k} &= r_\mathrm{site} \sin \varphi_\mathrm{gc} % = R_\oplus \frac{b_\oplus}{R_\oplus}\sin \varphi_\mathrm{rd} = R_\oplus \sqrt{1-e_\oplus^2}\sin \varphi_\mathrm{rd} = S_\oplus \sin \varphi_\mathrm{gd} \end{align}

In these equations, cosφrd\cos \varphi_\mathrm{rd} is still unknown. From the following relations, cosφrd\cos \varphi_\mathrm{rd} can be expressed by φgd\varphi_\mathrm{gd}.

tan2φgd=R2b2(1cos2φrd1)1cos2φrd=b2R2tan2φgd+1cosφrd=1b2R2tan2φgd+1,whereπ2φrdπ2\begin{align} &\tan^2\varphi_\mathrm{gd} = \frac{R_\oplus^2}{b_\oplus^2} \left(\frac{1}{\cos^2\varphi_\mathrm{rd}} - 1 \right) \\ &\frac{1}{\cos^2\varphi_\mathrm{rd}} = \frac{b_\oplus^2}{R_\oplus^2} \tan^2\varphi_\mathrm{gd} + 1 \\ &\cos\varphi_\mathrm{rd} = \frac{1}{\sqrt{\frac{b_\oplus^2}{R_\oplus^2} \tan^2\varphi_\mathrm{gd} + 1}}, \quad \mathrm{where} \quad -\frac{\pi}{2} \le \varphi_\mathrm{rd} \le \frac{\pi}{2} \end{align}

Then, CC_\oplus and SS_\oplus can be expressed by the following formula.

C=Rcosφgd1b2R2tan2φgd+1=Rb2R2sin2φgd+cos2φgd=R(1e2)sin2φgd+cos2φgd=R1e2sin2φgd\begin{align} C_\oplus &= \frac{R_\oplus}{\cos\varphi_\mathrm{gd}} \frac{1}{\sqrt{\frac{b_\oplus^2}{R_\oplus^2} \tan^2\varphi_\mathrm{gd} + 1}} = \frac{R_\oplus}{\sqrt{\frac{b_\oplus^2}{R_\oplus^2} \sin^2\varphi_\mathrm{gd} + \cos^2\varphi_\mathrm{gd}}} \notag \\ &= \frac{R_\oplus}{\sqrt{(1-e_\oplus^2) \sin^2\varphi_\mathrm{gd} + \cos^2\varphi_\mathrm{gd}}} = \frac{R_\oplus}{\sqrt{1 - e_\oplus^2 \sin^2\varphi_\mathrm{gd}}} \end{align} S=R(1e2)1e2sin2φgd\begin{equation} S_\oplus = \frac{R_\oplus(1-e_\oplus^2)}{\sqrt{1 - e_\oplus^2 \sin^2 \varphi_{\mathrm{gd}}}} \end{equation}

Numerical Transformation

As the relationship between geodetic coordinates and ECEF coordinates is clarified, we proceed to the actual transformation. The reference spheroid is WGS84, the shape of which is specified by the semi-major axis RR_\oplus and the flattening ff_\oplus.

R=6378.137 km,f=1298.257223563\begin{gather} R_\oplus = 6378.137~\mathrm{km}, \quad f_\oplus = \frac{1}{298.257223563} \end{gather}

The other parameters are calculated as follows.

e=2ff2=0.0818191908426215,b=R1e2=R(1f)=6356.75231424518 km.\begin{align} e_\oplus &= \sqrt{2f_\oplus - f_\oplus^2} = 0.0818191908426215, \\ b_\oplus &= R_\oplus \sqrt{1-e_\oplus^2} = R_\oplus(1-f_\oplus) = 6356.75231424518~\mathrm{km}. \\ \end{align}

The longitude is simply calculated by

λ=arctan2(y,x)\begin{gather} \lambda = \arctan2 (y,x) \end{gather}

Regarding the geodetic latitude and altitude, it seems difficult to find the explicit analytic solution. Thus, we try to find the solution by using a numerical method. If we know the geodetic latitude φgd\varphi_\mathrm{gd}, the altitude hellph_\mathrm{ellp} can be calculated by

hellp=x2+y2cosφgdC=x2+y2cosφgdR1e2sin2φgdhellp=zsinφgdS=zsinφgdR(1e2)1e2sin2φgd\begin{align} h_\mathrm{ellp} &= \frac{\sqrt{x^2+y^2}}{\cos\varphi_\mathrm{gd}} - C_\oplus = \frac{\sqrt{x^2+y^2}}{\cos\varphi_\mathrm{gd}} - \frac{R_\oplus}{\sqrt{1 - e_\oplus^2 \sin^2\varphi_\mathrm{gd}}} \\ h_\mathrm{ellp} &= \frac{z}{\sin\varphi_\mathrm{gd}} - S_\oplus = \frac{z}{\sin\varphi_\mathrm{gd}} - \frac{R_\oplus(1-e_\oplus^2)}{\sqrt{1 - e_\oplus^2 \sin^2 \varphi_{\mathrm{gd}}}} \end{align}

To make the above equations equal, we should find the geodetic latitude φgd\varphi_\mathrm{gd} which satisfies the following equation.

zx2+y2tanφgd+e2Rsinφgd1e2sin2φgd=0\begin{gather} z - \sqrt{x^2+y^2} \tan \varphi_\mathrm{gd} + \frac{e_\oplus^2 R_\oplus \sin\varphi_\mathrm{gd}}{\sqrt{1 - e_\oplus^2 \sin^2 \varphi_{\mathrm{gd}}}} = 0 \end{gather} φ0=arctan(zx2+y2)\begin{gather} \varphi_0 = \arctan \left( \frac{z}{\sqrt{x^2 + y^2}} \right) \end{gather}

For the initial value, we can use the geocentric latitude. As an example, the following python script shows the transformation from ECEF coordinates to geodetic coordinates.

# WGS84 parameters
flattening = 1/298.257223563
semimajor = 6378.137
eccentricity = np.sqrt(2*flattening - flattening**2)

def geodetic_latitude(x, y, z):
    """ calculate the geodetic latitude

    # Args:
        x(ndarray): x coordinate in ECEF, km
        y(ndarray): y coordinate in ECEF, km
        z(ndarray): z coordinate in ECEF, km

    # Returns:
        latitude(ndarray): geodetic latitude, rad
    """
    params = (x, y, z)
    latitude = np.arctan(z/ np.sqrt(x**2 + y**2))
    return optimize.fsolve(latitude_equation, latitude, args=params)

def latitude_equation(x: np.ndarray, *args) -> np.ndarray:
    """ equation to be solved

    # Args:
        *args(tuple): (x, y, z)

    # Returns:
        latitude(ndarray): latitude
    """
    return args[2] - np.sqrt(args[0]**2 + args[1]**2) * np.tan(x) + eccentricity**2 * semimajor * np.sin(x) / np.sqrt(1 - eccentricity**2 * np.sin(x)**2)

Now, we understand the basics of the conversion from ECEF coordinates to geodetic parameters. However, this numerical method requires a considerable amount of computation as the amount of data increases. Therefore, we would like to use a more efficient method to calculate the geodetic parameters.

Vermeille’s Method

One of the more efficient methods is the method proposed by Vermeille [2]. In this method, the solution can be obtained analytically, by using quite technical parameter transformations.

First, we define the following variable k>0k > 0.

k=QSPR=hellp+Ce2CChellp=(k+e21)C=kCS\begin{align} &k = \frac{QS}{PR} = \frac{h_\mathrm{ellp} + C_\oplus - e_\oplus^2 C_\oplus}{C_\oplus} \\ &h_\mathrm{ellp} = (k + e_\oplus^2 - 1) C_\oplus = k C_\oplus - S_\oplus \end{align}

Next, we describe CC_\oplus by using kk.

sinφgd=zS+hellp=zkC\begin{align} \sin\varphi_\mathrm{gd} = \frac{z}{S_\oplus + h_\mathrm{ellp}} = \frac{z}{k C_\oplus} \end{align} C2=R2(1e2sin2φgd)=R2+C2e2sin2φgd=R2+e2z2k2\begin{align} C_\oplus^2 &= \frac{R_\oplus^2}{(1 - e_\oplus^2 \sin^2\varphi_\mathrm{gd})} = R_\oplus^2 + C_\oplus^2 e_\oplus^2 \sin^2\varphi_\mathrm{gd} \notag \\ &= R_\oplus^2 + \frac{e_\oplus^2 z^2}{k^2} \end{align}

Using the above equation, we re-write x2+y2x^2 + y^2.

x2+y2=(hellp+C)2cos2φgd=(k+e)2C2(1sin2φgd)=(k+e)2C2(1z2k2C2)=(k+e)2(R2+e2z2k2z2k2)\begin{align} x^2 + y^2 &=(h_\mathrm{ellp} + C_\oplus)^2 \cos^2\varphi_\mathrm{gd} = (k + e_\oplus)^2 C_\oplus^2 (1 - \sin^2\varphi_\mathrm{gd}) \notag \\ &=(k + e_\oplus)^2 C_\oplus^2 \left( 1 - \frac{z^2}{k^2 C_\oplus^2} \right) \notag \\ &=(k + e_\oplus)^2 \left( R_\oplus^2 + \frac{e_\oplus^2 z^2}{k^2} - \frac{z^2}{k^2}\right) \end{align} x2+y2(k+e2)2+(1e2)z2k2=R2\begin{align} \frac{x^2+y^2}{(k+e_\oplus^2)^2} + \frac{(1 - e_\oplus^2) z^2}{k^2} = R_\oplus^2 \end{align}

Now, we define the following variables pp and qq.

p=x2+y2R2,q=1e2R2z2\begin{align} p = \frac{x^2 + y^2}{R_\oplus^2}, \quad q = \frac{1-e_\oplus^2}{R_\oplus^2} z^2 \end{align}

Using these variables, we can formulate the 4th order polynomial equation (quartic equation) for kk. In general, quartic equations can be solved analytically, such as by using Ferrari’s method. Vermeille’s method does not apply Ferrari’s method directly, but uses some similar transformations to find the factorized form.

k4+2e2k3(p+qe4)k22e2qke4q=0\begin{align} k^4 + 2e_\oplus^2 k^3 - (p+q-e_\oplus^4) k^2 - 2e_\oplus^2 q k - e_\oplus^4 q = 0 \end{align}

Now, we introduce a new variable uu. For any uu, the following equation holds.

(k2+e2ku)2[(p+q2u)k2+2e2(qu)k+u2+e4q]=0\begin{align} (k^2 + e_\oplus^2 k - u)^2 - \left[ (p+q-2u) k^2 + 2e_\oplus^2(q-u)k + u^2 + e_\oplus^4 q \right] = 0 \end{align}

In Eq. (33), the inside of []\left[ \cdots \right] is a quadratic polynomial with respect to kk. If we require that discriminant of this part equals zero, the condition of Eq. (34) is obtained. If this condition is satisfied, the quadratic polynomial can be factorized into the form of ()2(\cdots)^2, and then the entire equation can be factorized as well.

e4(qu)2(p+q2u)(u2+e4q)=0\begin{align} e_\oplus^4 (q-u)^2 - (p+q-2u)(u^2 + e_\oplus^4 q) = 0 \end{align} 2u3(p+qe4)u2+e4pq=0\begin{align} 2u^3 - (p + q - e_\oplus^4) u^2 + e_\oplus^4 pq = 0 \end{align}

Additionally, we introduce the following variables rr and ss.

r=p+qe46,s=e4pq4r3\begin{align} r = \frac{p+q-e_\oplus^4}{6}, \quad s = e_\oplus^4 \frac{pq}{4r^3} \end{align}

These variables are always positive, because

p+q=x2+y2R2+(1e2)z2R2=x2R2+y2R2+z2b2>1\begin{align} p + q = \frac{x^2 + y^2}{R_\oplus^2} + \frac{(1-e_\oplus^2) z^2}{R_\oplus^2} = \frac{x^2}{R_\oplus^2} + \frac{y^2}{R_\oplus^2} + \frac{z^2}{b_\oplus^2} > 1 \end{align}

Then, the cubic equation with respect to u/ru/r can be obtained.

u3r33u2r22s=0\begin{align} \frac{u^3}{r^3} - 3\frac{u^2}{r^2} - 2s = 0 \end{align}

We substitute Eq. (38), to obtain the equation with respect to tt. In the range of t>0t > 0, 1+t+1/t1 + t + 1/t takes the minimum value of 3 at t=1t = 1. When t=1t = 1, the left-hand side of Eq. (37) becomes 2s<0-2s < 0. Therefore, there should be one solution in the range of 0<t<10 < t < 1, and another solution in the range of t>1t > 1.

ur=1+t+1t\begin{align} \frac{u}{r} = 1 + t + \frac{1}{t} \end{align} t62(1+s)t3+1=0\begin{gather} t^6 - 2(1+s)t^3 + 1 = 0 \end{gather}

Focusing on real values, the following two solutions can be found. As expected, one solution is in the range of 0<t<10 < t < 1, and the other is in the range of t>1t > 1.

t3=1+s±s(2+s)t=1+s±s(2+s)3\begin{align} t^3 &= 1 + s \pm \sqrt{s(2+s)} \\ t &= \sqrt[3]{1 + s \pm \sqrt{s(2+s)}} \end{align}

Regardless of which solution is chosen, the value of u/ru/r will be the same. So we can choose whichever solution we like. For now, let us choose the solution with plus sign. The second term in Eq. (33) is expressed in the square form.

(k2+e2ku)2(e2quvk+v)2=0,wherev=u2+e4q\begin{align} (k^2 + e_\oplus^2 k - u)^2 - \left( e_\oplus^2 \frac{q-u}{v}k + v \right)^2 = 0, \quad \mathrm{where}\quad v = \sqrt{u^2 + e_\oplus^4 q} \end{align} (k2+vu+qve2k+vu)(k2+vu+qve2kvu)=0\begin{align} \left( k^2 + \frac{v-u+q}{v}e_\oplus^2k + v - u\right)\left( k^2 + \frac{v-u+q}{v}e_\oplus^2k - v - u\right) = 0 \end{align}

The first bracket in Eq. (44) has no solution for k>0k>0, because vuv-u, vv, and qq are all positive. So we are interested in the second bracket. Since u+vu+v is positive, there is only one solution for k>0k>0.

k=u+v+w2w,wherew=e2u+vq2v\begin{gather} k = \sqrt{u+v+w^2} - w, \quad \mathrm{where} \quad w = e_\oplus^2\frac{u+v-q}{2v} \end{gather}

As kk has been determined, we can calculate the geodetic latitude φgd\varphi_\mathrm{gd} and the altitude hellph_\mathrm{ellp}.

D=kx2+y2k+e2,C=D2+z2k\begin{equation} D = \frac{k\sqrt{x^2+y^2}}{k+e_\oplus^2}, \quad C_\oplus = \frac{\sqrt{D^2+z^2}}{k} \end{equation} hellp=k+e21k,φgd=2arctanzD+D2+z2\begin{equation} h_\mathrm{ellp} = \frac{k+e_\oplus^2-1}{k}, \quad \varphi_\mathrm{gd} = 2 \arctan \frac{z}{D+\sqrt{D^2+z^2}} \end{equation}

The original paper [2] lists the minimum equations required for the conversion. By writing a simple script based on these equations, we can convert from ECEF coordinates to geodetic parameters.

# WGS84 parameters
flattening = 1/298.257223563
semimajor = 6378.137
eccentricity = np.sqrt(2*flattening - flattening**2)

def geodetic_vermeille(x, y, z):
    """ calculate the geodetic latitude and altitude based on
    H. Vermeille, "Direct transformation from geocentric to geodetic coordinates", 2002, Journal of Geodesy, 76:451-454

    # Args:
        x(ndarray): x coordinate in ECEF, km
        y(ndarray): y coordinate in ECEF, km
        z(ndarray): z coordinate in ECEF, km

    # Returns:
        lat(ndarray): geodetic latitude, rad
        lon(ndarray): geodetic longitude, rad
        h(ndarray): geodetic altitude, km
    """
    p = (x**2 + y**2)/semimajor**2
    q = (1 - eccentricity**2) * z**2 / semimajor**2
    r = (p + q - eccentricity**4)/6
    s = eccentricity**4 * p * q / (4 * r**3)
    t = (1 + s + np.sqrt(s * (2 + s)))**(1/3)
    u = r * (1 + t + 1/t)
    v = np.sqrt(u**2 + eccentricity**4 * q)
    w = eccentricity**2 * (u + v - q)/(2 * v)
    k = np.sqrt(u + v + w**2) - w
    D = k * np.sqrt(x**2 + y**2)/(k + eccentricity**2)
    lat = 2 * np.arctan(z/(D+np.sqrt(D**2 + z**2)))
    lon = np.arctan2(y, x)
    h = (k + eccentricity**2 - 1)/k * np.sqrt(D**2 + z**2)
    return lat, lon, h

Reference

  1. David A. Vallado, Fundamentals of Astrodynamics and Applications Fourth Edition, 2013, Microsoft Press
  2. H. Vermeille, “Direct transformation from geocentric to geodetic coordinates”, 2002, Journal of Geodesy, 76:451-454, doi: 10.1007/s00190-002-0273-6.

Recent Articles

Xorshift Random Number Generator

Xorshift is one of the simplest and high-speed random number generator (RNG) algorithms. In this article, we explore the concept of Xorshift, and implement Rust code for searching valid Xorshift parameters for 32-bit binary.