Search

Search papers and lessons

Convex Hull

Level 2 · 9 min read

The convex hull of a set of points is the smallest convex region that contains them all, like a rubber band stretched around the outermost points.

On this page

  • Colour = topic mix
  • Optimization
  • Linear algebra
  • Sign in to see your progress

TL;DR

Take a finite set of points in the plane or in space. Their convex hull is the smallest convex set that contains all of them. Stretch a rubber band around the outermost points and let it snap tight: the region it encloses is the hull. Points strictly inside the band do not change the hull at all.

Where you'll see it: collision checking in robotics, where a robot's shape is approximated by the hull of its vertices; the feasible region of a linear program when its corners are the candidate solutions; and in computational geometry, where the hull is often the first step in analysing a point cloud.

Intuition

Imagine pins pushed into a board, one per point, and a loop of string around all of them. Pull the string tight and it will bend only at the pins on the outside. The shape it traces is the convex hull. A pin in the middle of the cluster never touches the string, so it can be removed without changing the shape.

Why does the idea exist? Many questions about a set of points are easier for the hull than for the points themselves. Is a point inside the set? Where is the furthest point in a direction? Does a robot touch a wall? In each case you only need the hull, because a convex region is fully described by its boundary, and its boundary is made of straight segments between a few corner points.

The hull is also the answer to a question about combinations. Pick any two points and draw the segment between them. The hull of a set is what you get by repeatedly drawing segments between points already in the region, which is why it is convex: a convex set is one where every segment between two of its points stays inside it, and the hull has that property by construction.

The math

The Convex Set lesson defines a set as convex when every segment between two of its points stays inside. For a finite set of points P={p1,…,pn}P = \{\mathbf{p}_1, \dots, \mathbf{p}_n\} in Rd\mathbb{R}^d, a convex combination is a point of the form

x=λ1p1+⋯+λnpn,λi≥0,∑i=1nλi=1.\mathbf{x} = \lambda_1 \mathbf{p}_1 + \cdots + \lambda_n \mathbf{p}_n, \qquad \lambda_i \ge 0, \qquad \sum_{i=1}^n \lambda_i = 1.

Each λi\lambda_i is a weight, the weights are nonnegative, and they add to one. A convex combination is a weighted average of the points.

Definition: Convex hull

The convex hull of PP is the set of all convex combinations of points of PP:

conv⁡(P)={∑i=1nλipi  :  λi≥0, ∑iλi=1}.\operatorname{conv}(P) = \left\{ \sum_{i=1}^n \lambda_i \mathbf{p}_i \;:\; \lambda_i \ge 0,\ \sum_i \lambda_i = 1 \right\}.

Equivalently, it is the intersection of all convex sets that contain PP, which is the smallest such set.

The two descriptions agree. Every convex set containing PP must contain every convex combination of its points, since convexity is closed under forming averages of that kind. The set of convex combinations is itself convex and contains PP, so it is the smallest one.

Extreme points

Not every point of PP is needed. A point pk\mathbf{p}_k is an extreme point of the hull if it is not a convex combination of the other points. Only extreme points can be corners of the hull. Every interior point is a convex combination of the extreme points, so the hull is determined by its extreme points alone. In the plane the extreme points are the vertices of the hull polygon, and in three dimensions they are its corners.

Membership test

Checking whether a point x\mathbf{x} is in the hull is a linear feasibility problem. Ask whether there exist weights λi≥0\lambda_i \ge 0 with ∑iλi=1\sum_i \lambda_i = 1 and ∑iλipi=x\sum_i \lambda_i \mathbf{p}_i = \mathbf{x}. A Linear Programming solver answers this directly. In two dimensions there is a simpler test, once the hull is known: a point is inside a convex polygon when it lies on the same side of every edge.

Computing the hull

The standard algorithm for points in the plane is Andrew's monotone chain. It sorts the points by xx-coordinate, then builds the lower and upper chains of the hull with a stack. The turn test uses the Cross Product: for points OO, PP and QQ, the value (P−O)×(Q−O)(P - O) \times (Q - O) is positive when the path O→P→QO \to P \to Q turns left and negative when it turns right.

flowchart TD
    A[Sort points by x then y] --> B[Build lower chain with a stack]
    B --> C[Build upper chain in reverse order]
    C --> D{Next point makes a non-left turn?}
    D -- yes --> E[Pop the stack top]
    E --> D
    D -- no --> F[Push the point]
    F --> G[Join the two chains into the hull]

Sorting costs O(nlog⁡n)O(n \log n) and the stack pass is linear, so the whole algorithm runs in O(nlog⁡n)O(n \log n). This is optimal for planar hulls, because sorting can be reduced to finding the hull.

Worked examples

Example
A tiny hull by hand

Take four points: A=(0,0)A = (0, 0), B=(4,0)B = (4, 0), C=(1,3)C = (1, 3) and D=(2,1)D = (2, 1).

  1. Find the hull's edges. The bottom edge joins AA and BB because all points lie on or above the line y=0y = 0.
  2. The right edge joins B=(4,0)B = (4, 0) and C=(1,3)C = (1, 3). This line is x+y=4x + y = 4. Check the other points: AA gives 0<40 \lt 4 and DD gives 2+1=3<42 + 1 = 3 \lt 4, so both are on the same side.
  3. The left edge joins C=(1,3)C = (1, 3) and A=(0,0)A = (0, 0). This line is y=3xy = 3x. The point BB gives 0<120 \lt 12 and DD gives 1<61 \lt 6, so both are below it.
  4. Since DD satisfies every edge inequality, it is inside. The hull is the triangle ABCABC, and DD does not affect it.
  5. The area of the triangle is half the absolute value of the cross product of B−A=(4,0)B - A = (4, 0) and C−A=(1,3)C - A = (1, 3), which is 12 ∣4⋅3−0⋅1∣=6\tfrac{1}{2}\,|4 \cdot 3 - 0 \cdot 1| = 6.

Interpretation: the four points span a region of area 6. The point DD is a redundant point, and removing it changes nothing.

Example
Writing an interior point as a convex combination

Show that D=(2,1)D = (2, 1) is in the hull of A=(0,0)A = (0,0), B=(4,0)B = (4,0) and C=(1,3)C = (1,3) by finding weights λA,λB,λC≥0\lambda_A, \lambda_B, \lambda_C \ge 0 that sum to 1 and average to DD.

  1. The yy-coordinates give 0⋅λA+0⋅λB+3λC=10\cdot\lambda_A + 0\cdot\lambda_B + 3\lambda_C = 1, so λC=13\lambda_C = \tfrac13.
  2. The xx-coordinates give 4λB+1⋅λC=24\lambda_B + 1\cdot\lambda_C = 2, so 4λB=2−13=534\lambda_B = 2 - \tfrac13 = \tfrac53 and λB=512\lambda_B = \tfrac{5}{12}.
  3. The weights sum to 1, so λA=1−512−13=14\lambda_A = 1 - \tfrac{5}{12} - \tfrac13 = \tfrac14.
  4. All three are nonnegative. Check: x=512⋅4+13⋅1=53+13=2x = \tfrac{5}{12}\cdot 4 + \tfrac13\cdot 1 = \tfrac53 + \tfrac13 = 2 and y=13⋅3=1y = \tfrac13 \cdot 3 = 1.

Interpretation: DD is a weighted average of the three corners, with most weight on BB and least on CC. Had any weight come out negative, the point would lie outside the hull.

Tradeoffs and failure modes

SituationProblemBetter choice
Points in the plane or 3D, many of themNaive pairwise tests are slowMonotone chain for the plane; a dedicated library such as Qhull for 3D
Very high dimensionThe number of facets can explodeAvoid the exact hull; use a linear program or an approximation
Nearly collinear pointsFloating-point error can flip a turn test and add or drop a vertexUse exact arithmetic or a tolerance and state it
You only need membership, not the shapeBuilding the full hull is wasted workSolve a linear feasibility problem for the one point
Data with outliersThe hull is dominated by a single far pointUse a robust summary, such as a percentile region

A common pitfall is treating the hull as a model of the data. It is only the outer boundary. A cloud of points that is shaped like a ring has a filled-in hull, so the hull says nothing about the hole in the middle.

History

The notion of a convex set and the idea of a hull were developed in the late nineteenth and early twentieth centuries, when geometers studied convex bodies and their supporting planes. Carathéodory's theorem, which says that a point in the hull of a set in dd dimensions is a convex combination of at most d+1d+1 of the points, dates to the early 1900s and is the reason the hull of a planar set is determined by only a few vertices.

Algorithms came later, with the rise of computing. Ronald Graham published a scan that sorts by angle around a chosen interior point in 1972. Jarvis's "gift wrapping" method, which walks around the hull one vertex at a time, appeared in the early 1970s. Andrew's monotone chain, a simpler sort-and-scan approach, followed in the late 1970s and remains the usual choice in code. The idea caught on in computational geometry and later in optimization, because linear programs and support-vector methods can be stated in terms of hulls.

Check yourself

QuestionRecall: what is the convex hull of a set of points?Show answer

It is the smallest convex set containing all the points. Equivalently, it is the set of all convex combinations of the points, meaning weighted averages with nonnegative weights that sum to one.

QuestionCompute the area of the hull of the three points (0,0)(0, 0), (6,0)(6, 0) and (0,4)(0, 4).Show answer

The hull of three points that are not collinear is the triangle they form. Its area is half the absolute value of the cross product of (6,0)(6, 0) and (0,4)(0, 4), which is 12 ∣6⋅4−0⋅0∣=12\tfrac{1}{2}\,|6 \cdot 4 - 0 \cdot 0| = 12.

QuestionWhy does an interior point never change the convex hull, and why is that useful?Show answer

An interior point is a convex combination of the other points, so it is already inside the hull they define. Removing it leaves the hull unchanged. This is why algorithms only need to track the extreme points, which often are far fewer than the whole set.

QuestionA robot arm's shape is approximated by the convex hull of its vertices, and a wall is a flat line. Explain how the hull helps decide whether the arm touches the wall.Show answer

A convex polygon lies entirely on one side of the wall if all its vertices do. So it is enough to check the vertices: if all lie strictly on one side, the hull does not touch the wall. If vertices lie on both sides, the hull crosses it and the arm touches. Only the vertices are needed, not every point of the arm.

Sources