I am working on a python
project where from a function I am getting coordinate values x, y
in a dict
like below:
centroid_dict = {0: (333, 125), 1: (288, 52), 2: (351, 41)}
where 0, 1, 2
are the objectId
and (333, 125), (288, 52), (351, 41)
are their (x, y)
coordinate values respectively. I need to calculate the distance between each coordinate which means:
0 - 1 -> ((333, 125) - (288, 52))
0 - 2 -> ((333, 125) - (351, 41))
1 - 0 -> ((288, 52) - (333, 125))
1 - 2 -> ((288, 52) - (351, 41))
2 - 0 -> ((351, 41) - (333, 125))
2 - 1 -> ((351, 41) - (288, 52))
To calculate the distance, I can use:
def calculateDistance(x1, y1, x2, y2):
dist = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
return dist
but I am not able to think of any logic which can calculate distance between each points as the length of dict might increase in future. As of now, it is 3
but it can be 10
. Can anyone please help me give some ideas on it. Thanks