# Calculating a line of bearing between two LLAs

**URL:** <https://discourse.julialang.org/t/calculating-a-line-of-bearing-between-two-llas/75244>\
**Category:** Geo\
**Created:** [January 26, 2022, 6:01pm UTC](https://discourse.julialang.org/t/calculating-a-line-of-bearing-between-two-llas/75244 "2022-01-26T18:01:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![devin](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@devin](https://discourse.julialang.org/u/devin)\
**Post date:** [January 26, 2022, 6:01pm UTC](https://discourse.julialang.org/t/calculating-a-line-of-bearing-between-two-llas/75244/1 "2022-01-26T18:01:03Z")

</div>

Hi,

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!  
Devin

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 27, 2022, 5:26am UTC](https://discourse.julialang.org/t/calculating-a-line-of-bearing-between-two-llas/75244/2 "2022-01-27T05:26:20Z")

</div>

[This article](http://tchester.org/sgm/analysis/peaks/how_to_get_view_params.html#intro) 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.

> **Code**
>
> ```julia
> # A) Spherical Earth solution by Tom Chester: 
> # http://tchester.org/sgm/analysis/peaks/how_to_get_view_params.html#intro
> 
> # INPUT
> 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]
> 
> # FORMULAS:
> Δ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
> 
> ```

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [January 27, 2022, 6:33pm UTC](https://discourse.julialang.org/t/calculating-a-line-of-bearing-between-two-llas/75244/3 "2022-01-27T18:33:55Z")

</div>

The javascript code behind this web page should be straightforward to port [Azimuth/Distance calculator by Don Cross](http://cosinekitty.com/compass.html), plus you can check results to what the page produces.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 27, 2022, 6:55pm UTC](https://discourse.julialang.org/t/calculating-a-line-of-bearing-between-two-llas/75244/4 "2022-01-27T18:55:43Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [January 27, 2022, 7:56pm UTC](https://discourse.julialang.org/t/calculating-a-line-of-bearing-between-two-llas/75244/5 "2022-01-27T19:56:33Z")

</div>

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.
