I want to process all entries of the messages_grouped dictionary with all of the remaining. However, it is taking a lot of time to process since I'm repeating some computations with the two for loop. But I can't find an easy way to avoid those repetitions, once I'm new in python. Basically I want to calculate the line for each drone and then get the intersection with each of the remaining drones. I'm using sympy library (Line1.intersection(Line2)) and inside Line_analysis function aswell. I know I'm repeating some computations, I just can't find a way to avoid that. I haven't finished the code yet to save the intersections.
def Collision_checker(messages_grouped):
"""
messages_grouped as example:{Drone0: (list of dictionaries), Drone1: (list of dictionaries), ...}
"""
for key in messages_grouped:
X_new=messages_grouped[key][1]['X (ENU)']
Y_new=messages_grouped[key][1]['Y (ENU)']
Z_new=messages_grouped[key][1]['altitude']
X_old=messages_grouped[key][0]['X (ENU)']
Y_old=messages_grouped[key][0]['Y (ENU)']
Z_old=messages_grouped[key][0]['altitude']
for key in messages_grouped:
X2_new=messages_grouped[key][1]['X (ENU)']
Y2_new=messages_grouped[key][1]['Y (ENU)']
Z2_new=messages_grouped[key][1]['altitude']
X2_old=messages_grouped[key][0]['X (ENU)']
Y2_old=messages_grouped[key][0]['Y (ENU)']
Z2_old=messages_grouped[key][0]['altitude']
Line1=Line_analysis(X_new,Y_new,Z_new, X_old, Y_old, Z_old)
Line2=Line_analysis(X2_new,Y2_new,Z2_new, X2_old, Y2_old, Z2_old)
if Line1 is not None and Line2 is not None:
Intersection=Line1.intersection(Line2)
else:
pass
I really appreciate some help. Thanks!