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:
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.
What I have tried is to use sympy, but the calculation seems to time out, unless I have a symbol wrong somewhere. To use the top point (lat2, -77.0)
as an example:
import sympy as s
lat1 = s.rad(38.0)
lat2 = s.Symbol('lat2')
lon1 = s.rad(-77.0)
lon2 = s.rad(-77.0)
d = 5.0 # Given distance
R = 3950. # Radius of earth in miles
dlon = lon2 - lon1
dlat = lat2 - lat1
a = (s.sin(dlat/2))**2 + s.cos(lat1) * s.cos(lat2) * (s.sin(dlon/2))**2
c = 2 * s.atan2( s.sqrt(a), s.sqrt(1-a) )
s.solve(3950 * c - d, lat2) # HANGS
Here I'm trying to solve for lat2
, but the .solve()
call hangs up indefinitely.