I'll try to explain my method.
For any set of points in the plane, there is exactly one smallest circle that encloses them all. Let this circle have radius
minr. We also know that at least two of the points should lie on the boundary of the circle. Now consider a bigger circle with radius
r >
minr with the same center. Because this circle is bigger, none of the points will be on the boundary. We can, however, move this circle in the plane until at least two points are on its boundary and all other points are within the circle (this can be done in many ways).
So, to solve this problem, we look for two points from the original set, on the boundary of a circle with radius
r, while all other points lie within the circle. If such a pair of points can be found, the answer to this problem is yes. This leads to a straight forward O(n^3) algorithm:
Code: Select all
for all pairs of points in the original set:
if their distance is bigger than 2*r goto impossible
else if their distance is equal to 2*r:
form a circle through these points and check if all other points lie within this circle
if they do goto possible
else goto impossible
else (their distance is smaller than 2*r):
form the two circles through these points; for both circles check if all other points lie within it
if for any one of them they do, goto possible
else continue to the next pair
if, after searching all pairs, no jump to possible is made, goto impossible
Note 1: if two points are less than 2*
r apart, two circles can be constructed, one with the center 'above' the connecting line, and one with the center 'below' the connecting line.
Note 2: If you give it some thought, you can reduce the number of pairs to consider thereby making the method faster. For the given input, however, the given method is fast enough: my program runs in 0.002 seconds.
Hope it helps.