← back to algorithms

Geometric Algorithms

Nievergelt & Hinrichs · Ch. 8 · Algorithms and Data Structures

Convex hull wraps a point set in the smallest convex polygon. Graham scan does it in O(n log n). Line intersection, closest pair, and Voronoi diagrams extend these ideas to richer geometric problems.

Convex hull: the rubber band around the nails

Cross product orientation test

The foundation of computational geometry. Given three points P, Q, R: the cross product (Q-P) x (R-P) tells you whether R is left of, right of, or on the line PQ. Positive = left turn, negative = right turn, zero = collinear.

Scheme

Graham scan

Sort points by polar angle around the lowest point. Walk through the sorted points, keeping only left turns. O(n log n) for the sort, O(n) for the scan.

Scheme
Neighbors

Cross-references