{"id":249,"date":"2026-11-13T12:35:52","date_gmt":"2026-11-13T04:35:52","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-rotating-calipers-walk-antipodal-pairs\/"},"modified":"2026-11-13T21:53:40","modified_gmt":"2026-11-13T13:53:40","slug":"how-rotating-calipers-walk-antipodal-pairs","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-rotating-calipers-walk-antipodal-pairs\/","title":{"rendered":"How rotating calipers walk antipodal pairs"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Rotating calipers<\/strong> compute the diameter, the width, and several other extents of a convex polygon by walking two parallel supporting lines around the boundary. The lines start on an antipodal pair, often the leftmost and rightmost vertices, and the one that can rotate less before it hits the next edge is advanced. Every antipodal pair is visited, and there are <strong>O(h)<\/strong> of them on a convex hull of h vertices. The diameter is the maximum distance among those pairs.<\/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 farthest pair of points in a finite set is realized by two vertices of the convex hull. Testing every hull pair is quadratic in h. For a convex polygon the farthest vertex from a given edge is the one that supports a parallel line, and as the edge advances that vertex advances in one direction. Two pointers that only move forward therefore see every candidate in linear time after the hull exists.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The same walk with a different score computes the minimum width, the distance between parallel supporting lines, and the minimum or maximum area bounding rectangle. The walk is the algorithm. The score changes.<\/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\">On a convex polygon given in order, one rotation visits every antipodal pair in O(h) time. The diameter is the maximum Euclidean distance among the visited pairs, and it is the diameter of the original set if the polygon is the convex hull. Extra memory is a few indices. The pointers must not both advance in a way that skips a supporting configuration. Comparing the turn angles, by a cross product of edge directions, decides which caliper hits its next vertex first.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The input has to be convex and ordered. Running the pointers on a nonconvex chain misses the hull vertices that were never built. Compute the hull first, with Andrew&#8217;s algorithm or the Graham scan, and then run the calipers.<\/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>Compute the convex hull in counterclockwise order if the input is an unordered cloud.<\/li>\n<li>Place one caliper on the lowest or leftmost vertex and the other on the vertex farthest in the opposite direction, so the supporting lines start parallel.<\/li>\n<li>At each step, compute how far each caliper can rotate before it lies along the next edge. Advance the caliper with the smaller angle. Advance both if the angles tie.<\/li>\n<li>Whenever the calipers are antipodal, score the pair: distance for the diameter, or the projected gap for the width.<\/li>\n<li>Stop when the calipers have rotated 180 degrees and returned to the swapped start. The best score is the answer.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">The linear bound is in the hull size, after an n log n hull. It is not a bound on an unordered cloud. The minimum width is not the minimum edge length. It is the smallest distance between parallel supporting lines, and the calipers compute it when the score is that gap rather than the vertex distance.<\/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 every hull pair is tested instead of the antipodes<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Check all h\u00b2 hull pairs and call it rotating calipers<\/td>\n<td>The distances can include the diameter and the time is quadratic. The calipers advance only the supporting pair.<\/td>\n<\/tr>\n<tr>\n<td>Run the pointers on the raw point set<\/td>\n<td>A non-hull point can sit between the calipers and the true support. The input of this walk is a convex polygon.<\/td>\n<\/tr>\n<tr>\n<td>Advance the same caliper every time<\/td>\n<td>The other supporting line then skips an edge that contained the true antipode. The smaller rotation angle decides which side advances.<\/td>\n<\/tr>\n<tr>\n<td>Report the longest hull edge as the diameter<\/td>\n<td>The diameter may connect two vertices that do not share an edge. The walk exists to see those pairs.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">The hull that feeds the calipers is Andrew&#8217;s monotone chain or the Graham scan. A single farthest-point query from one site is a different search. Rotating calipers are the simultaneous walk of two supports.<\/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 walks antipodal pairs on a convex hull. The diameter is the maximum distance between a pair of parallel supporting lines through vertices. On the diamond both diagonals have length 2. It prints <code>2.00<\/code>.<\/p>\n\n<pre><code class=\"language-python\">import math\nhull = [(0, 0), (1, -1), (2, 0), (1, 1)]\n\ndef dist(a, b):\n    return math.hypot(a[0] - b[0], a[1] - b[1])\n\ndef diameter(h):\n    n = len(h)\n    j = 1\n    best = 0\n    for i in range(n):\n        nxt = (i + 1) % n\n        while dist(h[i], h[(j + 1) % n]) &gt; dist(h[i], h[j]):\n            j = (j + 1) % n\n        best = max(best, dist(h[i], h[j]), dist(h[nxt], h[j]))\n    return best\n\nbrute = max(dist(a, b) for i, a in enumerate(hull) for b in hull[i + 1:])\nassert abs(diameter(hull) - brute) &lt; 1e-9\nprint(f&quot;{diameter(hull):.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\">Rotating calipers walk the antipodal pairs of a convex polygon to find its diameter and its minimum-area bounding box. Packing and collision code ask for that box. A bounding box aligned with the axes is cheaper and looser.<\/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 quadratic hull-pair loop once the polygon is convex. Walk the calipers. Keep the hull computation separate so a nonconvex cloud is not fed to the pointers.<\/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 rotating calipers returns the antipodal walk and the O(h) diameter of a convex polygon. <strong>Rotating calipers compute the diameter and the width of a convex polygon in linear time by advancing whichever parallel support hits the next vertex first.<\/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: Rotating calipers compute the diameter, the width, and several other extents of a convex polygon by walking two parallel supporting lines around the boundary. The lines start on an antipodal pair, often the leftmost and rightmost vertices, and the one that can rotate less before it hits&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-249","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\/249","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=249"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/249\/revisions"}],"predecessor-version":[{"id":648,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/249\/revisions\/648"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}