Skip to content

Geometry Cheatsheet

Use this page when the geometry problem is mostly about choosing the right exact predicate and boundary policy.

Do Not Use When

  • the main difficulty is sweep-line bookkeeping rather than predicates
  • floating-point approximation is the true topic and exact integer predicates do not apply
  • you have not fixed whether boundary counts as inside / intersecting / touching

Choose By Signal

Core Primitives

  • point subtraction
  • dot product
  • cross product
  • orientation sign

Template start:

Orientation

cross(b - a, c - a) > 0  => counterclockwise
cross(b - a, c - a) < 0  => clockwise
cross(b - a, c - a) = 0  => collinear

Safety

  • prefer integers when possible
  • use __int128 for large cross products
  • define whether boundary counts as inside
  • keep one strict vs non-strict intersection policy all the way through the solution

Main Trap

Most geometry wrong answers come from policy drift, not the formula:

  • strict vs non-strict
  • open vs closed segment
  • boundary vs inside
  • inconsistent kept-side policy across directed lines in half-plane intersection

Pick the policy once and keep it everywhere.

Quick Anchors In This Repo

Convex Hull / Half-Plane Split

  • sort points
  • build lower hull
  • build upper hull
  • choose collinear policy once and keep it consistent

If the boundary comes from input points, it is usually hull.

If the boundary comes from directed line constraints, it is usually Half-Plane Intersection.

If the goal is one global closest distance, it is usually Nearest Pair of Points.

If the goal is pointwise addition of convex regions, it is usually Minkowski Sum.

Reopen Paths