Im_too_old_for_this_shit's blog

By Im_too_old_for_this_shit, 10 years ago, In English

Given a convex polygon. How to find ( fast ) a point for which the maximum distance from vertices is the smallest. Here is told a way, but I can't prove it and it seems to be incorrect.

»
10 years ago, # |
  Vote: I like it +3 Vote: I do not like it

This is an instance of the Smallest circle problem (this problem doesn't specify that the points have to form a convex polygon, but as the optimal algorithm for the general case runs in linear time I guess you can't do much better).

Megiddo proposed a deterministic algorithm to solve it in linear time (you can look it up if you want), but I particularly like this randomized approach (which is expected linear):

// circle is a pair (center, radius)
circle spanning_circle(vector<point>& T) {
    int n = T.size();
    random_shuffle(all(T));
    circle C(point(), -INF);
    for (int i = 0; i < n; i++) if (!in_circle(C, T[i])) {
        C = circle(T[i], 0);
        for (int j = 0; j < i; j++) if (!in_circle(C, T[j])) {
            C = circle((T[i] + T[j]) / 2, abs(T[i] - T[j]) / 2);
            for (int k = 0; k < j; k++) if (!in_circle(C, T[k])) {
                point o = circumcenter(T[i], T[j], T[k]);
                C = circle(o, abs(o - T[k]));
            }
        }
    }
    return C;
}