Using Haversine formula to solve for a single coordinate X miles away

geometrytrigonometry

I am using the Haversine formula to calculate a distance in miles between two (lat, lng) coordinate pairs. (Note: I am aware and okay with limitations in the formula related to the non-spheroidal (ellipsoidal) shape of the Earth.)

I would like to use this formula to solve for either a single latitude or single longitude that is due north, east, west, or south of a given coordinate. This is maybe best illustrated through a diagram; I have the central red point as given and am trying to solve for the 4 outer red points below:

enter image description here

From the central coordinate of (38.0, -77.0), I want to solve (individually) for the 4 missing points at each side of the circle pictured, assuming a distance of 5 miles. So in each equation, I am given a distance and 3 coordinates, and want to solve for the 4th coordinate.

How can I rework Haversine formula to solve for an individual coordinate given the other 3?

What I have tried is to use sympy, but the calculation seems to time out, unless I have a symbol wrong somewhere. I've also tried to invert the formula, but have gotten stuck halfway.

To use the top point (lat2, -77.0) as an example, I'm given the formulas

dlon = lon2 - lon1
dlat = lat2 - lat1
a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
c = 2 * atan2( sqrt(a), sqrt(1-a) )
d = R * c (where R is the radius of the Earth) 

lat1 = radians(38.0)
lon1 = radians(-77.0)
lon2 = radians(-77.0)
d = 5.0

And want to solve for lat2.

Best Answer

Let's start from the formula: $$d=2R\arcsin\sqrt{\sin^2\frac{\phi_2-\phi_1}{2}+\cos\phi_1\cos\phi_2\sin^2\frac{\lambda_2-\lambda_1}{2}}$$ So if the longitudes are the same, $\lambda_1=\lambda_2$, then the formula reduces to $$d=R|\phi_2-\phi_1|$$ so $$\phi_2=\phi_1\pm\frac dR$$ You need to check if $\phi_2$ is reasonable (see circles with radii greater than the distance to the poles).

Similarly, to check points at the same latitude, $\phi_1=\phi_2$, $$d=2R\arcsin\left|\cos\phi_1\sin\frac{\lambda_2-\lambda_1}2\right|$$ From here$$\sin\frac{\lambda_2-\lambda_1}2=\pm\frac1{\cos\phi_1}\sin\frac d{2R}$$ This is once again a simple way to get $\lambda_2$, as long as the magnitude of the right hand side is less than $1$. So careful with large distances and around the poles.

Related Question