Calculating closest point to multiple other points

1.7k Views Asked by At

So I have a set of predefined $(x,y)$-coordinates for example: $(40,25)$, $(12,42)$, $(64,96)$, etc.

I have done calculations that give me the distance from one point to the other. This means that I know the distance between $1$ to $2$ and $1$ to $3$, but also $2$ to $1$, $2$ to $3$ and $3$ to $1$, $3$ to $2$. Now imagine that I don't have three points but a bit more say $10$.

How would I determine the point, that is part of the other points, and has the least amount of distance needed for all other points to travel there?

In other words, how do I determine the point that requires the least distance to be 'traveled' between other points.

1

There are 1 best solutions below

4
On

You may reduce the number of computation by avoiding duplicates.

Note that $$d(P,Q)=d(Q,P)$$

Arrange your points in some sort of order, say $$ P_1, P_2, P_3, ..., P_n$$ Find $$d(P_1, P_2),d(P1,P_2),....,d(P_1, P_n)$$ and let $M_1$ be the minimum of the above numbers. Now compute $$d(P_2, P_3),d(P2,P_4),....,d(P_2, P_n)$$ and let $M_2$ be the minimum of the above numbers.

Continue until you find $d(P_{n-1}, P_n)$.

Now find the minimum of your $M_1,M_2,...,M_{n-1}$ and you are done.