Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cos2sigmam
+ B
/ 4
* (
cos(sigma) * (-1 + 2 * cos2sigmam ** 2)
- B / 6 * cos2sigmam * (-3 + 4 * sin(sigma) ** 2) * (-3 + 4 * cos2sigmam ** 2)
)
)
)
dist_m = b * A * (sigma - deltasigma)
# %% From point #1 to point #2
# correct sign of lambda for azimuth calcs:
lamb = abs(lamb)
if sign(sin(lon2 - lon1)) * sign(sin(lamb)) < 0:
lamb = -lamb
numer = cos(U2) * sin(lamb)
denom = cos(U1) * sin(U2) - sin(U1) * cos(U2) * cos(lamb)
a12 = atan2(numer, denom)
a12 %= 2 * pi
az = degrees(a12)
return dist_m, az
ell = Ellipsoid()
# %% Input check:
if (abs(Lat1) > 90) | (abs(Lat2) > 90):
raise ValueError("Input latitudes must be in [-90, 90] degrees.")
# %% Supply WGS84 earth ellipsoid axis lengths in meters:
a = ell.semimajor_axis
b = ell.semiminor_axis
f = ell.flattening
# %% convert inputs in degrees to radians:
lat1 = radians(Lat1)
lon1 = radians(Lon1)
lat2 = radians(Lat2)
lon2 = radians(Lon2)
# %% correct for errors at exact poles by adjusting 0.6 millimeters:
if abs(pi / 2 - abs(lat1)) < 1e-10:
lat1 = sign(lat1) * (pi / 2 - 1e-10)
if abs(pi / 2 - abs(lat2)) < 1e-10:
lat2 = sign(lat2) * (pi / 2 - 1e-10)
U1 = atan((1 - f) * tan(lat1))
U2 = atan((1 - f) * tan(lat2))
lon1 = lon1 % (2 * pi)
lon2 = lon2 % (2 * pi)
L = abs(lon2 - lon1)
if L > pi:
L = 2 * pi - L
lamb = copy(L) # NOTE: program will fail without copy!
itercount = 0
warninggiven = False
notdone = True
if ell is not None:
a = ell.semimajor_axis
b = ell.semiminor_axis
f = ell.flattening
else: # Supply WGS84 earth ellipsoid axis lengths in meters:
a = 6378137 # semimajor axis
b = 6356752.31424518 # WGS84 earth flattening coefficient definition
f = (a - b) / a
lat1 = radians(Lat1) # intial latitude in radians
lon1 = radians(Lon1) # intial longitude in radians
# correct for errors at exact poles by adjusting 0.6 millimeters:
if abs(pi / 2 - abs(lat1)) < 1e-10:
lat1 = sign(lat1) * (pi / 2 - (1e-10))
alpha1 = radians(Azim) # inital azimuth in radians
sinAlpha1 = sin(alpha1)
cosAlpha1 = cos(alpha1)
tanU1 = (1 - f) * tan(lat1)
cosU1 = 1 / sqrt(1 + tanU1 ** 2)
sinU1 = tanU1 * cosU1
sigma1 = atan2(tanU1, cosAlpha1)
sinAlpha = cosU1 * sinAlpha1
cosSqAlpha = 1 - sinAlpha * sinAlpha
uSq = cosSqAlpha * (a ** 2 - b ** 2) / b ** 2
A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)))
B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)))
sigma = Rng / (b * A)
raise ValueError("Input latitudes must be in [-90, 90] degrees.")
# %% Supply WGS84 earth ellipsoid axis lengths in meters:
a = ell.semimajor_axis
b = ell.semiminor_axis
f = ell.flattening
# %% convert inputs in degrees to radians:
lat1 = radians(Lat1)
lon1 = radians(Lon1)
lat2 = radians(Lat2)
lon2 = radians(Lon2)
# %% correct for errors at exact poles by adjusting 0.6 millimeters:
if abs(pi / 2 - abs(lat1)) < 1e-10:
lat1 = sign(lat1) * (pi / 2 - 1e-10)
if abs(pi / 2 - abs(lat2)) < 1e-10:
lat2 = sign(lat2) * (pi / 2 - 1e-10)
U1 = atan((1 - f) * tan(lat1))
U2 = atan((1 - f) * tan(lat2))
lon1 = lon1 % (2 * pi)
lon2 = lon2 % (2 * pi)
L = abs(lon2 - lon1)
if L > pi:
L = 2 * pi - L
lamb = copy(L) # NOTE: program will fail without copy!
itercount = 0
warninggiven = False
notdone = True
while notdone: # force at least one execution
itercount += 1
if itercount > 50: