This came up when a friend talked about a programming competition, and we wondered what the best approach was:
Given a list of points, find the centre of a circle of predetermined size that covers the most points. If there are several such circles, its only important to find one of them.
Example input: 1000 points, in a 500x500 space, and a circle of 60 diameter.
Unless I've missed something obvious I think there is a simple answer.
For a rectangular area MxN, number of points P, radius R:
This is O(P), assuming P is the variable of interest.
My best approach so far is:
Every circle containing points must have a left-most point. So it makes a list of all the points to the right of a point that are potentially within the bounds of a circle. It sorts the points by x first, to make the sweep sane.
It then sorts them again, this time by the number of neighbours to the right that they have, so that the point with the most neighbours get examined first.
It then examines each point, and for each point to the right, it computes a circle where this pair of points is on the left perimeter. It then counts the points within such a circle.
Because the points have been sorted by potential, it can early-out once it's considered all the nodes that might potentially lead to a better solution.
Very quick idea, not necessarily right one:
Seems to be N^2 complexity, provided that calculating intersections of circle shaped areas is easy
How about using a clustering algorithm to identify the cluster of points. Then ascertain the cluster with the maximum number of points. Take the mean point of the cluster having the maximum points as the center of your circle and then draw the circle.
MATLAB supports implementation of k-means algorithm and it gives back a 2-d array (a matrix to be precise) of cluster means and corresponding cluster ids.
One well known flip side of k-means is deciding on k(number of clusters) before hand. This can be resolved though - one can learn the value of k from the data points. Please check this paper.
I hope this helps.
cheers