Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the closest point from a set of points on plane

Given n points on a 2-D plane, what is the point such that the distance from all the points is minimized? This point need not be from the set of points given. Is it centroid or something else?

How to find all such points(if more than one) with an algorithm?

like image 587
nowonder Avatar asked Dec 07 '09 08:12

nowonder


People also ask

How do you find the closest two points on a plane?

Note: The distance between two points on a plane is the Euclidean distance. So the closest two points are [3, 3], [-2, 4]. Approach: The solution is based on Greedy approach. The idea is to calculate the Euclidean distance from the target for every given point and store them in an array.

How do you find the smallest distance between two points?

To solve this problem, we have to divide points into two halves, after that smallest distance between two points is calculated in a recursive way. Using distances from the middle line, the points are separated into some strips. We will find the smallest distance from the strip array.

What is the closest pair of points problem?

Closest Pair of Points Problem. In this problem, a set of n points are given on the 2D plane. In this problem, we have to find the pair of points, whose distance is minimum. To solve this problem, we have to divide points into two halves, after that smallest distance between two points is calculated in a recursive way.

How do you find pairs of points whose x coordinate is closer?

Now we need to consider the pairs such that one point in pair is from the left half and the other is from the right half. Consider the vertical line passing through P [n/2] and find all points whose x coordinate is closer than d to the middle vertical line.


3 Answers

This is known as the "Center of Distance" and is different from the centroid.

Firstly you have to define what measure of distance you are using. If we assume you are using the standard metric of d=sqrt( (x1-x2)^2 + (y1-y2)^2) then it is not unique, and the problem is minimising this sum.

The easiest example to show this answer is not unique is the straight line example. Any point in between the two points has an equal total distance from all points.

In 1D, the correct answer will be any answer that has the same number of points to the right and the left. As long as this is true, then any move to the left and right will increase and decrease the left and right sides by the same amount, and so leave the distance the same. This also proves the centroid is not necessarily the right answer.

If we extend to 2D this is no longer the case - as the sqrt makes the problem weighted. Surprisingly to me there does not seem to be a standard algorithm! The page here seems to use a brute force method. I never knew that!

If I wanted to use an algorithm, then I would find the median point in X and Y as a start point, then use a gradient descent algorithm - this would get the answer pretty quickly. The whole equation ends up as a quadratic, so it feels like there ought to be an exact solution.

like image 182
Nick Fortescue Avatar answered Sep 22 '22 12:09

Nick Fortescue


There may be more than one point. Consider a plane with only two points on it. Those points describe a line-segment. Any point on that line-segment will have the same total distance from the two end-points.

like image 38
William Billingsley Avatar answered Sep 20 '22 12:09

William Billingsley


This is discussed in detail here http://www.ddj.com/architect/184405252?pgno=1

like image 39
Geek Avatar answered Sep 21 '22 12:09

Geek