Find the greatest distance between 5 separate points

546 Views Asked by At

Let's say I am given 5 separate points, on the coordinate plane.

How would I find the greatest distance between one point to another?

What I mean is not the distance between 2 points, but I want to go through each point and find the greatest distance.

Is there 1 simple formula to do this? I hope I'm clear.

2

There are 2 best solutions below

4
On BEST ANSWER

Although there is no known efficient algorithm (see Doug M's comment), there are simpler ways to solve it than by finding the Euclidean distance. In particular, we use the following properties of the norm:

Let $d^p_{i,j}$ be the p-norm distance between points $i$ and $j$ (if you want to be technical, it is the p-norm of the vector formed by subtracting those two points). Since I can't prove this in general let's restrict p to be 1 or 2. Then, if, for a given $i,j$ and an arbitrary $p$, $d^p_{i,j}$ is maximum, then it is maximum for all $p$.

Practically, this means that we can compute the 1-norm, which is much simpler. The 1-norm would just be:

$$d^1_{i,j} = |x_i-x_j| + |y_i - y_j|$$

So computationally you need to do two subtractions and potentially a negation, and a sum, rather than (with the 2-norm), two subtractions, a squaring, a sum, and a square root.

Look for the highest 1-norm, then compute only a single 2-norm.

0
On

This is currently an open problem, Planar Euclidean Maximum TSP.

There exists an optimal linear time algorithm for $\mathbb{R}^2$ with the $L_1$-norm (see Theorem 3 from [1]).

Maximum TSP is known NP-hard for $\mathbb{R}^3$ with the Euclidean norm (see Theorem 4 from [1]).

[1]: The Geometric Maximum Traveling Salesman Problem (arxiv)


Alternatively, you could be asking for the diameter of a planar set of points.

In this case, rotating calipers provides an optimal $O(n \log n)$ algorithm.

To speed up individual comparisons, the squared Euclidean norm can be used.