Convex Hull Using Jarvis March | Gift Wrapping Tutorial with Python

EmailTwitterLinkedInFacebookWhatsAppShare
The animation starts from the leftmost point and repeatedly selects the most counterclockwise next point. By joining these boundary points one by one, Jarvis March wraps around the set and forms the convex hull.

Jarvis March, also called the Gift Wrapping algorithm, is a simple way to find the convex hull of a set of points. In this tutorial, we explain the idea in layman terms, show how the orientation test works, provide pseudocode, and build a small animation and Python implementation.

1. Main idea in simple words

Imagine some points placed on paper.

Now think of wrapping a thread around the outermost points.

The thread touches only the boundary points.
That boundary is the convex hull.

The Jarvis March / Gift Wrapping method finds hull points one by one:

  • start from the leftmost point
  • then find the next outer point
  • then the next
  • keep going until you come back to the starting point

It is like walking around the outside fence of the points.


2. Why it is better than brute force

The brute force method checks many point pairs and is slow: (O(n^3)).

Jarvis March is smarter:

  • for each hull point, it scans all points once
  • if there are (h) hull points, time is:
    [O(nh)]
  • In the worst case, (h = n), so:
    [O(n^2)]

3. Intuition

Suppose you are standing at one hull point.

Now you want the next hull point.

So you look at all other points and choose the one such that all points lie to one side of the line.

That chosen point becomes the next point on the hull.

Then repeat.


4. Orientation test

For three points A, B, C, compute:

[(B_x-A_x)(C_y-A_y) – (B_y-A_y)(C_x-A_x)]

This tells the turn direction:

  • positive → left turn
  • negative → right turn
  • zero → collinear

Jarvis March uses this to decide which candidate point is the “most outside.”


5. Algorithm steps

  1. Find the leftmost point
  2. Put it in the hull
  3. Choose a candidate for the next point
  4. Scan all points:
  5. Move to that candidate
  6. Stop when you return to the starting point

6. Pseudocode

JARVIS_MARCH(points):
hull = empty list
leftmost = point with smallest x
current = leftmost
repeat:
add current to hull
next_point = any other point
for each point p in points:
if p is more counterclockwise than next_point
with respect to current:
next_point = p
current = next_point
until current == leftmost
return hull

7. Python implementation


8. Very short explanation for narration

“Jarvis March, also called Gift Wrapping, finds the convex hull by starting from the leftmost point and repeatedly selecting the next outermost point. At each step, it scans all points to find the most counterclockwise one. This continues until the algorithm returns to the starting point. Its worst-case time complexity is (O(n^2)).”


9. One-line summary

Jarvis March builds the convex hull by walking from one boundary point to the next, always choosing the most outside turn.


I hope this tutorial will create a good foundation for you. If you want tutorials on another topic or you have any queries, please send an mail at contact@spatial-dev.guru.

Leave a ReplyCancel reply

Discover more from Spatial Dev Guru

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Spatial Dev Guru

Subscribe now to keep reading and get access to the full archive.

Continue reading