Skip to content

Instantly share code, notes, and snippets.

@vitor-diego-s
Created January 29, 2020 16:55
Show Gist options
  • Save vitor-diego-s/225d389886c708f42dfe14f09a281a35 to your computer and use it in GitHub Desktop.
Save vitor-diego-s/225d389886c708f42dfe14f09a281a35 to your computer and use it in GitHub Desktop.
Calculates the Euclidean distance between two vectors
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