Given 2 arrays, I want to compare the coordinates of array1 with array2 and print the coordinates if the distance is <= 5. I used the code below, but it is not printing the correct coordinates.
def euclideanDistance(coordinate1, coordinate2):
dist= pow(pow(coordinate1[0] - coordinate2[0], 2) + pow(coordinate1[1] - coordinate2[1], 2), .5)
if dist <= 5:
return (coordinate1, coordinate2)
coords= [[17, 268],[17, 396],[18, 243], [18, 548]]
coords1= [[16, 484],[17, 398],[17, 640],[18, 331]]
distances = []
for i in range(len(coords)-1):
for j in range(i, len(coords1)):
distances += [euclideanDistance(coords[i],coords1[j])]
print(distances)
The output should be: [17, 396], [17, 398]