Computational geometry is the branch of computer science devoted to algorithms and data structures for geometric problems arising in graphics, GIS, CAD, robotics, and scientific computing. This cheat sheet covers the essential primitives, classical algorithms (convex hull, sweep line, Voronoi, Delaunay), polygon operations, spatial data structures, and robustness techniques that form the backbone of practical geometric computing.
What This Cheat Sheet Covers
This topic spans 15 focused tables and 129 indexed concepts, 112 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Point and Vector Primitives
The basic building blocks of all computational geometry algorithms are operations on 2D points and vectors. These primitives—dot product, cross product, distance, and the orientation predicate—appear in virtually every higher-level algorithm.
| Technique / Algorithm | Example | Description | |
|---|---|---|---|
$\vec{a} \cdot \vec{b} = a_x b_x + a_y b_y$ | • Returns scalar • positive if vectors point same direction, zero if perpendicular • Used to project one vector onto another | ||
$\vec{a} \times \vec{b} = a_x b_y - a_y b_x$ | Returns signed scalar (z-component of 3D cross product). Positive = CCW turn from a to b, negative = CW. | ||
$v = (b.x-a.x)(c.y-a.y)-(b.y-a.y)(c.x-a.x)$ | • Sign of cross product of (b−a) and (c−a) • v>0 = CCW, v<0 = CW, v=0 = collinear • Core primitive used in convex hull, point-in-polygon, and segment intersection | ||
$d(p,q) = \sqrt{(q.x-p.x)^2+(q.y-p.y)^2}$ | • Straight-line distance between two points • Avoid sqrt when comparing distances (compare squared distances instead). | ||
$d^2(p,q) = (q.x-p.x)^2+(q.y-p.y)^2$ | • Avoids expensive square root • sufficient for distance comparisons and closest-pair strip checks | ||
cross=0 AND $\min(a.x,b.x) \le p.x \le \max(a.x,b.x)$ | P lies on segment AB iff cross product (B−A)×(P−A)=0 (collinear) and P is within bounding box of AB. | ||
signs of orient(A,B,C) and orient(A,B,D) differ | Two segments AB and CD properly intersect iff each endpoint of one straddles the line through the other (opposite orientation signs). Handle collinear/endpoint cases separately. | ||
$\theta = \text{atan2}(p.y - o.y,, p.x - o.x)$ | • Angle of point p relative to origin o • used in Graham scan sorting. atan2 handles all quadrants correctly | ||
$\hat{v} = \vec{v} / | \vec{v} | ||
$(x,y) \to (-y,x)$ | Rotates vector 90° CCW; yields the inward or outward normal of a line segment, used in half-plane intersection. |