Given a list of 2-uples on python [(x_0,y_0),(x_1,y_1)...(x_n,y_n)], i need to evaluate the travel time of a particle placed at the point (x_0,y_0) with the initial velocity v_0 through the broken line formed by the point of the previous list.
By application of the second Newton's law, i came up with this algorithm, but i'm not confident about it :
def travel_time(v_0,l):
n=len(l)
t=0
v=v_0
a=0
T=0
g=9.8
for k in range(n-1):
a=np.arctan(abs((l[k][1]-l[k+1][1])/(l[k][0]-l[k+1][0])))
t=(l[k+1][0]-l[k][0])/(v*np.cos(a))
v=np.sqrt((np.cos(a)*v)**2+(-g*t+v*np.sin(a))**2)
T += t
return T
Can you help me to spot some potential mistakes, or submit improvements for the algorithm?
There are several things you should correct.
1) Your formula for the final velocity $v$ is wrong: you should use instead $$ v=\sqrt{v_0+2gL\sin\alpha}, \quad\text{where}\quad L={x_{k+1}-x_k\over\cos\alpha}\quad \text{is the length of $k$-th segment}. $$
(Side note: you'd better use $L=\sqrt{(x_{k+1}-x_k)^2+(y_{k+1}-y_k)^2}$ )
2) You compute travel time on $k$-th segment as $L/v_0$, but that is not accurate as velocity is not constant; you should use instead $$ t={2L\over v_0+v}, $$ where $v$ is the final velocity computed above.
Of course you should at the end of each cycle set $v_0=v$.