Created
January 29, 2020 16:55
-
-
Save vitor-diego-s/225d389886c708f42dfe14f09a281a35 to your computer and use it in GitHub Desktop.
Calculates the Euclidean distance between two vectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def euclidean_distance(coordenates): | |
''' | |
Calculates the Euclidean distance between two vectors | |
coordenates: | |
{ | |
'target': { | |
'x':current_x, | |
'y':current_y | |
}, | |
'evaluate':{ | |
'x':next_x, | |
'y':next_y | |
} | |
} | |
''' | |
target = coordenates['target'] | |
evaluate = coordenates['evaluate'] | |
a = [evaluate['x'], evaluate['y']] | |
b = [target['x'], target['y']] | |
distance = math.sqrt(sum([(xi-yi)**2 for xi, yi in zip(a, b)])) | |
return distance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment