Algorithms

Convex Hull

Graham scan sorts points by angle and walks around the outside, discarding clockwise turns until the convex hull remains.

5 minLevel 2/3The interactive stage stays ad-free.
Points42Hull vertices10Edges drawn10

The cyan polygon is the convex hull. It is the smallest convex shape containing every point. New points changes the cloud; Reset replays the hull edges.

What you are seeing

1

Start from the lowest point and sort the rest by polar angle.

2

Walk through the sorted points, keeping only counter-clockwise turns.

3

The stack at the end is the convex hull: the smallest convex polygon containing every point.

Why it matters

Convex hulls are used in collision detection, computer vision, geographic information systems, and robotics.

Complexity & details

Time: O(n log n) because of the angular sort. Space: O(n).

Frequently asked questions

What happens with collinear points?+

Collinear points on an edge are not vertices of the minimal hull. This demo keeps only strict turns, so they are omitted.

Why sort by angle?+

Sorting gives a consistent boundary walk. Without it, you would repeatedly scan all points and lose the O(n log n) bound.