# Geodetic and Geocentric

There are three functions that can help to convert between geodetic and geocentric representations. Notice that currently all Geodetic representations are based on the WGS84 reference ellipsoid.

## ECEF to Geodetic

It is possible to convert a position vector represented in an Earth-Centered, Earth-Fixed frame (ECEF) r_e to the Geodetic latitude, longitude, and altitude by the following function:

function ecef_to_geodetic(r_e::AbstractVector)

which returns a tuple with:

• The altitude above the reference ellipsoid [m].
julia> ecef_to_geodetic([R0;0;0])
(0.0, 0.0, 0.0)

julia> ecef_to_geodetic([0;R0;0])
(0.0, 1.5707963267948966, 0.0)

julia> ecef_to_geodetic([0;0;R0])
(1.5707963267948966, 0.0, 21384.685754820704)

# Geodetic to ECEF

The Geodetic latitude lat [rad], longitude lon [rad], and altitude h [m] can be converted to a vector represented in an ECEF reference frame by the following function:

function geodetic_to_ecef(lat::Number, lon::Number, h::Number)

in which a 3x1 vector will be returned.

julia> geodetic_to_ecef(0,0,0)
3-element StaticArrays.SVector{3, Float64} with indices SOneTo(3):
6.378137e6
0.0
0.0

3-element StaticArrays.SVector{3, Float64} with indices SOneTo(3):
4.1835869067109847e6
-4.1835869067109837e6
-2.3744128953028163e6

# Geocentric to Geodetic

Given a Geocentric latitude ϕ_gc [rad] and distance from the center of Earth r [m], one can obtain the Geodetic coordinates (Geodetic latitude and altitude above the reference ellipsoid - WGS84) using the following function:

function geocentric_to_geodetic(ϕ_gc::Number, r::Number)

in which a tuple with two values will be returned:

• The Geodetic latitude [rad]; and
• The altitude about the reference ellipsoid (WGS-84) [m].
Note

The longitude is the same in both Geodetic and Geocentric representations.

julia> geocentric_to_geodetic(deg2rad(-22), R0)
(-0.3863099329112617, 3013.9291869809385)

julia> geocentric_to_geodetic(0, R0)
(0.0, 0.0)

# Geodetic to Geocentric

Given a Geodetic latitude ϕ_gd [rad] and altitude above the reference ellipsoid h [m], one can obtain the Geocentric coordinates (Geocentric latitude and position from the center of Earth) using the following function:

function geodetic_to_geocentric(ϕ_gd::Number, h::Number)

in which a tuple with two values will be returned:

• The Geocentric latitude [rad]; and
• The distance from the center of Earth [m].
Note

The longitude is the same in both Geodetic and Geocentric representations.

julia> geodetic_to_geocentric(deg2rad(-22), 0)
(-0.38164509973650357, 6.375157677217675e6)

julia> geodetic_to_geocentric(0,0)
(0.0, 6.378137e6)