# Earth Coordinates

## Cartesian Coordinate System

The usual cartesian coordinate system associated with the Earth is specified as follows:

• The origin is the center of the Earth.
• The z-axis is the rotational axis. It pierces the Earth at the poles and its positive direction is towards the north pole. The Earth rotates in the positive direction around this z-axis: when you lay your right hand on the globe such that the thumb shows to the north pole, then the Earth rotates in the direction of the fingers ("the rule of the right hand").
• Great circles passing through the poles are called meridians. The prime meridian pass through Greenwich (London).
• The plane that is orthogonal to the z-axis is the equatorial plane and the great circle that is located in this plane is the equator.
• The x-axis points towards the intersection of the prime meridian with the equator.
• The y-axis is in the equator plane, it is orthogonal to the x-axis and oriented such that the coordinates build a right-handed system. When the fingers of the right hand go from the x- to the y-axis then the thumb shows in the direction of the z-axis.

Each point on the Earth is uniquely defined by its cartesian coordinates (x, y, z). In fact, only 2 coordinates would suffice because each point is on the surface of a sphere:

 `x2 + y2 + z2 = R2` (1)

where R is the Earth's radius, R = 6371.010 km.

Since this cartesian coordinate system is fixed with the Earth, it is call Earth-centered Earth-fixed (ECEF) system.

## Spherical Coordinate System

Points on the Earth are usually specified in the spherical coordinate system.

The spherical coordinates of an arbitrary cartesian point P(x, y, z) are:

1. The latitude φ which is the angle between OP and the equator.
2. The longitude λ which is the angle between the prime meridian and the meridian passing through OP.
3. The radius r which is the distance of P from the origin.

Since the radius is constant, the two angles (φ, λ) are already sufficient to specify a point on the Earth:

 Latitude (along equator) `-90° ≤ φ ≤ 90°` (2a) Longitude (along meridian) `-180° < λ ≤ 180°` (2b)

The longitude at the poles is arbitrary and is usually set to 0° by convention.

We can easily find the relation between the cartesian and spherical coordinates. Let P(x, y, z) be a cartesian point, and P' its projection on the x/y-plane. The length OP' is

 `r' = r cosφ.` (3)

We can now compute the cartesian coordinates from the spherical coordinates:

 `x = r' cos λ = r cosφ cosλ` (4a) `y = r' sin λ = r cosφ sinλ` (4b) `z = r sin φ` (4c)

Solving these equations for (φ, λ, r) yields the opposite relationship:

 `r = √ x2 + y2 + z2 ` (5a) `φ = arcsin(z/r)` (5b) `λ = atan2(y, x)` (5c)

Here, the simple minded λ = arctan(y/x), which is valid only for -90° < λ < 90°, was replaced by the correct atan2(y, x), which yields -180° < λ ≤ 180°.

## Geodetic Coordinate System

The spherical coordinate system is closely related to the geodetic system. In the geodetic system, the points are specified by latitude, longitude and elevation (height h). The elevation is measured orthogonal to a reference surface which is usually the earth ellipsoid. When we approximate the earth by a sphere with radius R, then

 `h = r - R.` (6)

## ENU Coordinate System

The ENU coordinate system is a local system specific to any point P on the Earth. It is formed from a plane tangent to the Earth's surface at the point P. In this plane,
the unit vector E points to the East,
the unit vector N points to the North.
The unit vector U points Up,
i.e. is orthogonal to the tangent plane.

The practical ENU coordinate system is used e.g. by Google Earth and other targeting and tracking applications.

The vector E = (Ex, Ey, Ez) is tangent to the circle of constant latitude passing through P. This circle is also called a "parallel circle" because it is parallel to the equator. The tangent is obtained by taking partial derivatives of the expressions (4) with respect to λ and normalizing the resulting vector to the length 1:

 `Ex = -sinλ.` (7a) `Ey = cosλ.` (7b) `Ez = 0. ` (7c)

The vector N = (Nx, Ny, Nz) is tangent to the meridian circle passing through P. So, by taking partial derivatives of the expressions (4) with respect to φ and normalizing the resulting vector to the length 1 we get:

 `Nx = -sinφ cosλ.` (8a) `Ny = -sinφ sinλ.` (8b) `Nz = cosφ.` (8c)

The unit vector U = (Ux, Uy, Uz) points in the direction of P. So, by setting r = 1 in the expressions (4), we get:

 `Ux = cosφ cosλ.` (9a) `Uy = cosφ sinλ.` (9b) `Uz = sinφ.` (9c)

## Transforming ENU to ECEF

Let us consider a point Q that has the coordinates (x, y, z) in the ECEF system and coordinates Q' = (e, n, u) in the ENU system located at P = (Px, Py, Pz). The spherical coordinates of P are (φ, λ, R). Then the following equation transforms (e, n, u) to (x, y, z):

 x -sinλ -sinφ cosλ cosφ cosλ e Px y = cosλ -sinφ sinλ cosφ sinλ n + Py (10) z 0 cosφ sinφ u Pz

Notice that the columns of the transformation matrix M are equal to the vectors E, N, U, respectively. Hence, the matrix M is orthonormal. It corresponds to the rotation of the XYZ-System around the origin into the ENU-System (centered at origin). The transformation is built by first rotating the vectors X, Y, Z around the origin into E, N, U, and then translating this system by the vector P into its final position.

The transformation can be written concisely using vector and matrix notation:

 `Q = M Q' + P` (11)

## Transforming ECEF to ENU

The transformation from ECEF to ENU is obtained by inverting the transformation (11):

 `Q' = M-1 (Q - P) = MT (Q - P) ` (12)

Here we used the fact that the inverse of an orthonormal matrix is equal to the transformed matrix. This equation is in explicit terms as follows:

 e -sinλ cosλ 0 x - Px n = -sinφ cosλ -sinφ sinλ cosφ y - Py (13) u cosφ cosλ cosφ sinλ sinφ z - Pz

Let me recall that this equation transforms the XYZ-coordinates (x, y, z) of an arbitrary point Q into its ENU-coordinates (e, n, u). The ENU system is located at the point P with XYZ-coordinates (Px, Py, Pz) and XYZ-spherical coordinates (φ, λ, R).

A thoughtful reader surely noticed an asymmetry in the respective transformations (11) and (12), even if they both express rotations and translations. This apparent problem is resolved as follows. The equation (12) can be written as:

 `Q' = M-1 Q - M-1 P ` (14)

The meaning is that the ENU system is first rotated around its origin at P by the inverse rotation such that its axes are parallel to the XYZ-system. Afterwards it is translated by the vector M-1 P such that its origin is moved to the origin O of the XYZ-system. Indeed, the expression M-1 P denotes the origin O = (0, 0, 0)T of the XYZ-system expressed in the ENU-system, as we can see by applying the equation (14) to the point O = (0, 0, 0)T:

 `O' = M-1 O - M-1 P = - M-1 P ` (15)

So, the equations (12) or (14), respectively, can be written as:

 `Q' = M-1 Q + O' ` (16)

which is completely symmetric to the equation (11). For computational purposes the equations (12) (respectively (13)) are preferable.