Calculating a line of bearing between two LLAs


I’ve got two lat/lon/alt locations and I’d like to compute the line of bearing between them (az/el). Is there a way to do this using geodesy.jl? I’ve looked around and found GreatCircle.jl, geodesics.jl and LibGeographic.jl but none of those are registered packages.

For my use case all the LLAs are going to be fairly close, 20 km distance max. Does the projection really matter when everything is so close? Can I just use Euclidean geometry?

Thanks for any help with this!

1 Like

This article seems to address those questions.

After checking the numbers in that article there seems to be a dimensional mistake in the azimuth formula where sin(d) and cos(d) should be sin(c) and cos(c). The following code produces the correct results in their example.

# A) Spherical Earth solution by Tom Chester: 

lat2, lon2, elev2 = 34.28889, 117.6458, 10064*0.3048    # Mt. Baldy
lat1, lon1, elev1 = 34.22389, 118.0603,  5710*0.3048    #  Mt. Wilson
R = 6.3710e6                                            # Earth radius [m]

Δlon, Δlat, Δelev = lon2 - lon1, lat2 - lat1, elev2 - elev1
a = sind(Δlat/2)^2 + cosd(lat1) * cosd(lat2) * sind(Δlon/2)^2
c = 2 * asin(min(1,sqrt(a)))    # in radian

# Distance
d = R * c

# Azimuth and Elevation Angle
ϕ = acosd((sind(lat2) - sind(lat1)*cos(c))/(sin(c)*cosd(lat1)))
ϕ = sind(Δlon) <= 0 ?  ϕ : 360 - ϕ      # 79.1 deg
λ = (180/π) * (Δelev/d - d/(2*R))       # 1.79 deg

The javascript code behind this web page should be straightforward to port Azimuth/Distance calculator by Don Cross, plus you can check results to what the page produces.

1 Like

@Jeff_Emanuel, herein a comparison for the example I posted above, where the two points are about 40 km apart:

            Don Cross (ellips)  Tom Chester (sphere)
Azimuth:        79.1753°            79.1405°
Distance:       38.890 km           38.774 km
Alt/Elev:        1.7812°             1.7867°

FWIW, the Don Cross site requires negative longitudes for locations in California. The OP’s points are only about half as far apart, so he’d see even less difference, and he doesn’t indicate the level of accuracy required.