I'm working on a function in python that uses GPS coordinates to calculate distance using Vincenty's formulae. The first step is to iterate a set of equations until convergence using a while loop. "lam" is the variable I'm outputting and feeding back into the while loop. The while loop runs the first time, then the output every iteration after that is the exact same output as the first time. The loop is using the initial value of lam every time. It's supposed to take the lam output and use it as the new input, correct?
import math
location=[-83.55176667, -83.548975, 40.30421944, 49.30228889]
def distance(points):
""" points is a list containing 2 latitude/longitude points
in this order: [lon1, lon2, lat1, lat2]. This function determines
distance between those 2 points."""
L1, L2, theta1, theta2=points[0],points[1],points[2],points[3]
f=1/298.257223563
L=L2-L1
lam=L
outs=[]
U1=math.atan((1-f)*math.tan(theta1))
U2=math.atan((1-f)*math.tan(theta2))
while lam > .001:
sin_sigma=((math.cos(U2)*math.sin(lam))**2+
(math.cos(U1)*math.sin(U2)-
math.sin(U1)*math.cos(U2)*math.cos(lam))**2)**0.5
cos_sigma=math.sin(U1)*math.sin(U2)+math.cos(U1)*
math.cos(U2)*math.cos(lam)
sigma=math.atan2(sin_sigma,cos_sigma)
sin_alpha=(math.cos(U1)*math.cos(U2)*math.sin(lam))/sin_sigma
cos2_alpha=1-(sin_alpha)**2
cos2sigm=cos_sigma-((2*math.sin(U1)*math.sin(U2))/cos2_alpha)
C=(f/16)*cos2_alpha*(4+f*(4-3*cos2_alpha))
lam=L+(1-C)*f*sin_alpha*(sigma+C*sin_sigma*
(cos2sigm+C*cos_sigma*(-1+2*(cos2sigm)**2)))
outs.append(lam)
print(lam)
print('')
return outs
outs=distance(location)