Convex Hulls by Monotone Chains
Maintain lower and upper boundaries of a point set using a stack and a precise policy for collinear points.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A wrong turn reveals a middle point above the lower boundary
Sort distinct planar points lexicographically. Sweep left to right and tentatively append each point to the lower chain. If the last triple makes a clockwise turn, remove its middle point and test again before appending. With the standard orientation, that turn places the middle point above the direct segment connecting its neighbors. It cannot be a lower extreme in the current prefix. An increasing stack of counterclockwise turns records the current lower boundary.
Each point enters and leaves each stack at most once
Construct the upper chain by scanning in reverse with the same turn convention. Combine the two without duplicating endpoints. Popping collinear triples keeps only extreme endpoints of a straight run. A policy retaining boundary points must also handle all-collinear data consistently. Sorting dominates at \(O(n\log n)\). The stack work follows aggregate amortized analysis. Orientation predicates determine which points survive every local turn test.[1][2]