Bit of a challenging Python problem for me. I have from one to six points in constant motion but only in a Cartesian(2D) plane. I need to create a function that would calculate all the possible distances between these points and return a collection of some sort with theses distances and corresponding points. So for a maximum of six points there would be 15 unique distances that need calculating (see diagram)
I assume I can use this for calculating the actual distance
import math
def calcDist(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist
distance = calcDist(x1, y1, x2, y2)
What I need help with is how to best create the input and output. ie I know I need to pass from 1 to 6 possible points (x,y coordinates and associated point reference) . So does this suggest 1-6 dictionary objects would first need to be created?
And as well the returned collection needs both the calculated distances and associated point pairs for each distance. Since I'm more concerned with minimum distances sorting on the distance value would be optional.
Lastly since this is constantly running, optimization is important. Any feedback appreciated.