I am trying to find the intersection point of two flight trajectories and once I have the point, I need the indices of both the trajectories at the point of intersection. I wrote the following code for this (for one pair of flights, fa, and fb)-
import time
t0 = time.time()
for i in range(len(fa)):
for j in range(len(fb)):
if fa.iloc[i]['longitude'] == fb.iloc[j]['longitude'] and fa.iloc[i]['latitude'] == fb.iloc[j]['latitude']:
print(i,j,fa.iloc[i]['longitude'], fa.iloc[i]['latitude'])
t1 = time.time()
This is computationally very expensive (almost 20 secs to compute this) and will take a lot of time when I have hundreds of flight pairs. I'm sure there would be faster ways to do this and I would really appreciate inputs on this.
The two DataFrames have the same following structure-
fa = pd.DataFrame([[14:07:05, 106.535, 2.524], [14:07:10, 106.525,2.526]], columns=['time', 'longitude', 'latitude'])
fb = pd.DataFrame([[14:00:05, 107.306, 3.722], [14:00:10, 107.296,3.718]], columns=['time', 'longitude', 'latitude'])
I have just included two rows of the data to give a better picture of the problem.