{"id":296,"date":"2026-11-13T12:37:17","date_gmt":"2026-11-13T04:37:17","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-welzl-encloses-points-in-a-disk\/"},"modified":"2026-11-13T21:58:46","modified_gmt":"2026-11-13T13:58:46","slug":"how-welzl-encloses-points-in-a-disk","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-welzl-encloses-points-in-a-disk\/","title":{"rendered":"How Welzl encloses points in a disk"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Welzl&#8217;s algorithm<\/strong> computes the smallest enclosing disk of a finite planar point set. It is incremental and randomized. The recursive call returns the smallest disk of a subset, defined by at most three boundary points. A point that falls outside that disk is moved onto the boundary and the disk is recomputed. In random order the expected time is <strong>O(n)<\/strong>. The disk is unique. A deterministic incremental construction exists and is slower to analyze.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">The smallest enclosing disk is determined by two points that form a diameter or by three points on the boundary whose triangle contains the center. Trying every pair and triple is cubic and correct. Welzl&#8217;s recursion builds that set of at most three definers on the way back from a random permutation. A point inside the disk returned for the previous points does not change the answer. A point outside must lie on the boundary of the new disk, which is the inductive fact.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The randomization is in the input order. The geometry of the disk through two or three points is deterministic. An adversarial order can force the algorithm toward quadratic behavior. Shuffling is part of the algorithm.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">The returned disk contains every point and has the minimum radius. Expected time is linear after a random shuffle. Extra memory is the recursion of depth n in the naive form, which should be rewritten as an explicit loop or a recursion on the boundary set only, so the stack stays small. The boundary set never exceeds three points for a disk in the plane. A fourth point on the boundary is redundant or a sign that the previous disk was wrong.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Numerical computation of the circle through three points needs a stable circumcenter formula. A nearly collinear triple produces a huge circle and is a bad boundary set. The algorithm&#8217;s combinatorics are exact. The floating-point circumcenter is the practical hazard.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Shuffle the points. Call a recursion that receives the remaining points and a boundary set R, initially empty.<\/li>\n<li>If no points remain or R has three points, return the unique disk defined by R: empty, a point, the diameter segment, or the circumcircle of a triangle.<\/li>\n<li>Otherwise remove one point p. Compute the disk for the rest with the same R.<\/li>\n<li>If p lies in that disk, return it. Otherwise return the disk for the rest with p added to R.<\/li>\n<li>The disk defined by two points is the diametral disk. The disk defined by three noncollinear points is their circumcircle. Reject a collinear triple as a boundary. It does not define a finite minimal disk with all three on the boundary in a way the recursion should keep.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">Expected linear time needs the shuffle. The same recursion on a sorted order is not expected linear. The algorithm is planar. The smallest enclosing ball in higher dimensions uses the same idea with more boundary points. A bounding box is not this disk and is larger than necessary for a round cluster.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when the input order is left sorted<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Skip the shuffle<\/td>\n<td>Correctness can survive and the expected-time proof does not. A sorted cloud is a classic slow order for this recursion.<\/td>\n<\/tr>\n<tr>\n<td>Keep more than three boundary points<\/td>\n<td>A disk is defined by two or three points. A larger boundary set means an earlier &#8220;inside&#8221; test was wrong or a point was added without recomputing.<\/td>\n<\/tr>\n<tr>\n<td>Use the axis-aligned bounding box and take its circumcircle<\/td>\n<td>That circle encloses the points and is not always the smallest. The minimal disk can be smaller than the box&#8217;s circumcircle.<\/td>\n<\/tr>\n<tr>\n<td>Compute a circumcenter of three nearly collinear points with an unstable formula<\/td>\n<td>The radius blows up and a later inside test rejects points that are geometrically inside the true disk. Use a stable predicate.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">A convex hull does not by itself name the minimal disk, although the definers lie on the hull. Welzl&#8217;s algorithm is the randomized incremental disk. An approximate smallest disk is a different, often faster, numerical method when a strict minimum is not required.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment shuffles the points and grows a disk from a boundary of at most three points. Two points give the diametral disk. Three points give the circumcircle. The smallest disk of (0, 0), (2, 0), (1, 1) is the circumcircle of radius <code>1.00<\/code>.<\/p>\n\n<pre><code class=\"language-python\">import math, random\n\ndef circum(a, b, c=None):\n    if c is None:\n        center = ((a[0] + b[0]) \/ 2, (a[1] + b[1]) \/ 2)\n        return center, math.hypot(a[0] - b[0], a[1] - b[1]) \/ 2\n    d = 2 * (a[0] * (b[1] - c[1]) + b[0] * (c[1] - a[1]) + c[0] * (a[1] - b[1]))\n    ux = ((a[0] ** 2 + a[1] ** 2) * (b[1] - c[1]) + (b[0] ** 2 + b[1] ** 2) * (c[1] - a[1]) + (c[0] ** 2 + c[1] ** 2) * (a[1] - b[1])) \/ d\n    uy = ((a[0] ** 2 + a[1] ** 2) * (c[0] - b[0]) + (b[0] ** 2 + b[1] ** 2) * (a[0] - c[0]) + (c[0] ** 2 + c[1] ** 2) * (b[0] - a[0])) \/ d\n    return (ux, uy), math.hypot(ux - a[0], uy - a[1])\n\ndef covers(center, radius, pts):\n    return all(math.hypot(p[0] - center[0], p[1] - center[1]) &lt;= radius + 1e-9 for p in pts)\n\ndef welzl(points):\n    pts = points[:]\n    random.Random(0).shuffle(pts)\n    def rec(i, boundary):\n        if i == 0 or len(boundary) == 3:\n            if not boundary:\n                return (0, 0), 0\n            if len(boundary) == 1:\n                return boundary[0], 0\n            center, radius = circum(*boundary)\n            return center, radius\n        center, radius = rec(i - 1, boundary)\n        if math.hypot(pts[i - 1][0] - center[0], pts[i - 1][1] - center[1]) &lt;= radius + 1e-9:\n            return center, radius\n        return rec(i - 1, boundary + [pts[i - 1]])\n    return rec(len(pts), [])\n\npts = [(0, 0), (2, 0), (1, 1)]\ncenter, radius = welzl(pts)\nassert covers(center, radius, pts)\nprint(f&quot;{radius:.2f}&quot;)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Welzl&#8217;s algorithm computes a smallest enclosing disk, the bounding circle of a point set in collision detection and in mapping. <strong>CGAL<\/strong>&#8216;s miniball routines solve that problem. An axis-aligned box is cheaper and is not the smallest disk.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop the cubic triple loop. Shuffle and run Welzl. Keep a stable circumcircle primitive, because the combinatorics will call it on skinny triangles.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for Welzl&#8217;s algorithm returns the boundary set of at most three points and the expected linear time after a shuffle. <strong>Welzl&#8217;s algorithm computes the smallest enclosing disk in expected linear time by forcing any excluded point onto a boundary set of size at most three.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: Welzl&#8217;s algorithm computes the smallest enclosing disk of a finite planar point set. It is incremental and randomized. The recursive call returns the smallest disk of a subset, defined by at most three boundary points. A point that falls outside that disk is moved onto the boundary&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,40],"tags":[],"class_list":["post-296","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-geometry"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=296"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/296\/revisions"}],"predecessor-version":[{"id":695,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/296\/revisions\/695"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}