# Converting between lat/long/azimuth and distance/heading

I have three points, `p1`, `p2`, and `p3`, and I'm trying to find the distance between `p2` and `p3`. I have the latitude and longitude coordinates for `p1` and `p2` and have the `p3 - p1` distance in meters and bearing of `p1`. How would I find the `p2 - p3` distance?

My thoughts were to get the azimuth from the `geographiclib.geodesic.Geodesic.Inverse()` function which could then be converted to a bearing. Thus, I could define `p2` and `p3` on the polar coordinate system (with `p1` being at the origin) and thus find the distance. However, I'm unsure about how to go about this. I see quite a few posts on "UTM" which seems to also be a Cartesian grid based system, but I'm very new to this and am unsure how to proceed.

• It seems as if you're over thinking this. If you have a library that solves for both problems of geodesy, use it, Use bearing and distance from P1 to locate P3, then compute the P2-P3 distance Commented Mar 8, 2022 at 0:44
• @Vince - I thought I might be able to use `geographiclib.geodesic.Geodesic.Direct()` that would solve the problem, but it requires azimuth. I think I should be able to convert heading to azimuth to solve this given they seem to measure similar things, but I'm unsure about how exactly to do this
– sla
Commented Mar 8, 2022 at 0:47
• No, the two Problems of Geodesy are, find P2 from {P1,bearing,distance} (aka Forward or Direct) and given P1 and P2, find bearing and distance (aka Reverse or Inverse). The second problem returns both distance and bearing.. Commented Mar 8, 2022 at 1:18

Get the location of p3 by using GeographicLib's `Direct()` function from p1 using the bearing and distance you already know.

Then get the distance (and bearing) between p2-p3 using `Inverse()` function for p2, p3.

I have not coded this in Python, I have my own wrapper for GeographicLib written in Swift, but I think you can see how this works from my test code.

``````import GTSCommon
import GTSInverse
import GTSDirect

/*
p3  ?

p1 *               * p2

* = known lat/lon
? = unknown location
s13 = 1000 km
az13 = 30.0

Find p3, s23, and az23
*/

let p1 = GeodesicPoint(lat: 50.0, lon: 10.0)
let p2 = GeodesicPoint(lat: 50.0, lon: 12.0)
print("p1  : \(p1.asString(.HDD_MM_SS_ssss))")
print("p2  : \(p2.asString(.HDD_MM_SS_ssss))")
let az13 = Bearing(degrees: 30.0)
let s13 = 1000.0e+3  // 1000 km

let dir13 = gtsDirect(startPoint: p1, distance: s13, fwdInitialBearing: az13, ellipsoid: WGS84)
let p3 = dir13.endPoint
print("p3  : \(p3.asString(.HDD_MM_SS_ssss))")

let inv23 = gtsInverse(point1: p2, point2: p3, ellipsoid: WGS84)
let s23 = inv23.distance
let az23 = inv23.fwdInitialBearing
print("s23 : \(s23/1000) km")
print("az23: \(az23.asString(.D_dd_o))")
``````

Output:

``````p1  : N50°00'00.0000" E010°00'00.0000"
p2  : N50°00'00.0000" E012°00'00.0000"
p3  : N57°31'15.1413" E018°20'23.0604"
s23 : 934.7409342169686 km
az23: 024.02°
``````