<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Gift_wrapping_algorithm</id>
	<title>Gift wrapping algorithm - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Gift_wrapping_algorithm"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Gift_wrapping_algorithm&amp;action=history"/>
	<updated>2026-05-04T18:47:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Gift_wrapping_algorithm&amp;diff=4790449&amp;oldid=prev</id>
		<title>imported&gt;HeccinTech: I just uploaded an animation I created that I thought better represented what&#039;s going on because the previous one randomly samples the points and is confusing when it comes to the users behalf in terms of interpretation.</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Gift_wrapping_algorithm&amp;diff=4790449&amp;oldid=prev"/>
		<updated>2025-12-02T20:39:27Z</updated>

		<summary type="html">&lt;p&gt;I just uploaded an animation I created that I thought better represented what&amp;#039;s going on because the previous one randomly samples the points and is confusing when it comes to the users behalf in terms of interpretation.&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Previous revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:39, 2 December 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{short description|Algorithm for computing convex hulls in a set of points}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{short description|Algorithm for computing convex hulls in a set of points}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Animation depicting the gift &lt;/del&gt;wrapping &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;algorithm&lt;/del&gt;.gif|thumb|Animation of the gift wrapping algorithm. &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;The red lines are already placed &lt;/del&gt;lines, the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;black line is &lt;/del&gt;the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;current best guess for the new line, and the green line is the next guess&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Gift &lt;/ins&gt;wrapping &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;angles&lt;/ins&gt;.gif|thumb|Animation of the gift wrapping algorithm. &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;With different colored &lt;/ins&gt;lines &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;where it shows different angles&lt;/ins&gt;, the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;color changes each time when it finishes finding &lt;/ins&gt;the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;optimal point.&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In [[computational geometry]], the &amp;#039;&amp;#039;&amp;#039;gift wrapping algorithm&amp;#039;&amp;#039;&amp;#039; is an [[algorithm]] for computing the [[convex hull]] of a given set of points.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In [[computational geometry]], the &amp;#039;&amp;#039;&amp;#039;gift wrapping algorithm&amp;#039;&amp;#039;&amp;#039; is an [[algorithm]] for computing the [[convex hull]] of a given set of points.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;HeccinTech</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Gift_wrapping_algorithm&amp;diff=246932&amp;oldid=prev</id>
		<title>imported&gt;Atomvinter at 12:25, 19 June 2024</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Gift_wrapping_algorithm&amp;diff=246932&amp;oldid=prev"/>
		<updated>2024-06-19T12:25:08Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{short description|Algorithm for computing convex hulls in a set of points}}&lt;br /&gt;
[[File:Animation depicting the gift wrapping algorithm.gif|thumb|Animation of the gift wrapping algorithm. The red lines are already placed lines, the black line is the current best guess for the new line, and the green line is the next guess]]&lt;br /&gt;
&lt;br /&gt;
In [[computational geometry]], the &amp;#039;&amp;#039;&amp;#039;gift wrapping algorithm&amp;#039;&amp;#039;&amp;#039; is an [[algorithm]] for computing the [[convex hull]] of a given set of points.&lt;br /&gt;
&lt;br /&gt;
==Planar case==&lt;br /&gt;
In the two-dimensional case the algorithm is also known as &amp;#039;&amp;#039;&amp;#039;Jarvis march&amp;#039;&amp;#039;&amp;#039;, after R. A. Jarvis, who published it in 1973; it has [[Big O notation|O]](&amp;#039;&amp;#039;nh&amp;#039;&amp;#039;) [[time complexity]], where &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is the number of points and &amp;#039;&amp;#039;h&amp;#039;&amp;#039; is the number of points on the convex hull. Its real-life performance compared with other convex hull algorithms is favorable when n is small or h is expected to be very small with respect to n{{citation needed|date=March 2018}}. In general cases, the algorithm is outperformed by many others (see [[Convex hull algorithms]]).&lt;br /&gt;
&lt;br /&gt;
==Algorithm==&lt;br /&gt;
For the sake of simplicity, the description below assumes that the points are in [[general position]], i.e., no three points are [[collinear]]. The algorithm may be easily modified to deal with collinearity, including the choice whether it should report only  [[extreme point]]s (vertices of the convex hull) or all points that lie on the convex hull{{citation needed|reason=Link to a resource describing the details for these degenerate cases required.|date=March 2018}}. Also, the complete implementation must choose how to deal with [[degenerate case]]s when the convex hull has only 1 or 2 vertices, as well as with the issues of limited [[arithmetic precision]], both of computer computations and input data.&lt;br /&gt;
 &lt;br /&gt;
The gift wrapping algorithm begins with &amp;#039;&amp;#039;i&amp;#039;&amp;#039;=0 and a point &amp;#039;&amp;#039;p&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt;&amp;#039;&amp;#039; known to be on the convex hull, e.g., the leftmost point, and selects the point &amp;#039;&amp;#039;p&amp;lt;sub&amp;gt;i+1&amp;lt;/sub&amp;gt;&amp;#039;&amp;#039; such that all points are to the right of the line &amp;#039;&amp;#039;p&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; p&amp;lt;sub&amp;gt;i+1&amp;lt;/sub&amp;gt;&amp;#039;&amp;#039;. This point may be found in &amp;#039;&amp;#039;O&amp;#039;&amp;#039;(&amp;#039;&amp;#039;n&amp;#039;&amp;#039;) time by comparing [[Polar coordinate system|polar angle]]s of all points with respect to point &amp;#039;&amp;#039;p&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;#039;&amp;#039; taken for the center of [[polar coordinates]]. Letting &amp;#039;&amp;#039;i&amp;#039;&amp;#039;=&amp;#039;&amp;#039;i&amp;#039;&amp;#039;+1, and repeating with until one reaches &amp;#039;&amp;#039;p&amp;lt;sub&amp;gt;h&amp;lt;/sub&amp;gt;&amp;#039;&amp;#039;=&amp;#039;&amp;#039;p&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt;&amp;#039;&amp;#039; again yields the convex hull in &amp;#039;&amp;#039;h&amp;#039;&amp;#039; steps.  In two dimensions, the gift wrapping algorithm is similar to the process of winding a string (or wrapping paper) around the set of points.&lt;br /&gt;
&lt;br /&gt;
The approach can be extended to higher dimensions.&lt;br /&gt;
&lt;br /&gt;
==Pseudocode==&lt;br /&gt;
[[File:Jarvis march convex hull algorithm diagram.svg|thumb|280px|right|Jarvis&amp;#039;s march computing the convex hull.]]&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;algorithm&amp;#039;&amp;#039;&amp;#039; jarvis(S) &amp;#039;&amp;#039;&amp;#039;is&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
     // &amp;#039;&amp;#039;S&amp;#039;&amp;#039; is the set of points&lt;br /&gt;
     // &amp;#039;&amp;#039;P&amp;#039;&amp;#039; will be the set of points which form the convex hull. Final set size is i.&lt;br /&gt;
     pointOnHull := leftmost point in S // which is guaranteed to be part of the CH(S)&lt;br /&gt;
     i := 0&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;repeat&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
         P[i] := pointOnHull&lt;br /&gt;
         endpoint := S[0]      // initial endpoint for a candidate edge on the hull&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;for&amp;#039;&amp;#039;&amp;#039; j from 0 to |S| &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
             // endpoint == pointOnHull is a rare case and can happen only when j == 1 and a better endpoint has not yet been set for the loop&lt;br /&gt;
             &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; (endpoint == pointOnHull) or (S[j] is on left of line from P[i] to endpoint) &amp;#039;&amp;#039;&amp;#039;then&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
                 endpoint := S[j]   // found greater left turn, update endpoint&lt;br /&gt;
         i := i + 1&lt;br /&gt;
         pointOnHull := endpoint&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;until&amp;#039;&amp;#039;&amp;#039; endpoint == P[0]      // wrapped around to first hull point&lt;br /&gt;
&lt;br /&gt;
==Complexity==&lt;br /&gt;
The inner loop checks every point in the set &amp;#039;&amp;#039;S&amp;#039;&amp;#039;, and the outer loop repeats for each point on the hull.  Hence the total run time is &amp;lt;math&amp;gt;O(nh)&amp;lt;/math&amp;gt;.  The run time depends on the size of the output, so Jarvis&amp;#039;s march is an [[output-sensitive algorithm]].&lt;br /&gt;
&lt;br /&gt;
However, because the running time depends [[linear time|linearly]] on the number of hull vertices, it is only faster than  &amp;lt;math&amp;gt;O(n \log n)&amp;lt;/math&amp;gt; algorithms such as [[Graham scan]] when the number &amp;#039;&amp;#039;h&amp;#039;&amp;#039; of hull vertices is smaller than log&amp;amp;nbsp;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;. [[Chan&amp;#039;s algorithm]], another convex hull algorithm, combines the logarithmic dependence of Graham scan with the output sensitivity of the gift wrapping algorithm, achieving an asymptotic running time  &amp;lt;math&amp;gt;O(n \log h)&amp;lt;/math&amp;gt;  that improves on both Graham scan and gift wrapping.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Convex hull algorithms]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{refbegin}}&lt;br /&gt;
* {{Introduction to Algorithms|2|chapter=33.3: Finding the convex hull|pages= 955&amp;amp;ndash;956}}&lt;br /&gt;
*{{cite journal&lt;br /&gt;
 | author = Jarvis, R. A.&lt;br /&gt;
 | title = On the identification of the convex hull of a finite set of points in the plane&lt;br /&gt;
 | journal = [[Information Processing Letters]]&lt;br /&gt;
 | volume = 2&lt;br /&gt;
 | year = 1973&lt;br /&gt;
 | pages = 18–21&lt;br /&gt;
 | doi = 10.1016/0020-0190(73)90020-3}}&lt;br /&gt;
{{refend}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Polytopes]]&lt;br /&gt;
[[Category:Convex hull algorithms]]&lt;br /&gt;
[[Category:Articles with example pseudocode]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Atomvinter</name></author>
	</entry>
</feed>