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 500×500 space, and a circle of 60 diameter.
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.