Technique
Computational Geometry Primitives
Use integer cross products for orientation, segment intersection, polygon area (shoelace), and point-in-polygon tests.
Learn firstMath / Number TheoryUnlocksConvex Hull Trick / Li Chao Tree
0%
mastery
0/7 solved
0/7 solved
Recognise it
The signal
points/segments/polygons
1Brute force
Floating-point slopes and angles.
2The observation
Precision errors and special cases: exact integer cross products remove division.
3Why it works
sign(cross(b - a, c - a)) gives the orientation of (a, b, c).
Reach for it when
- +collinearity, turn direction
- +area or lattice points (Pick's theorem)
Not when
- ×problem is actually Manhattan distance (rotate 45 degrees)
Practice
0/7 solved
- Point Location TestCSESMedium
- Line Segment IntersectionCSESMedium
- Polygon AreaCSESMedium
- Point in PolygonCSESMedium
- Polygon Lattice PointsCSESMedium
- Minimum Euclidean DistanceCSESHard
- Nearest vectorsCodeforces2300
Pitfalls
Misconceptions
- !using floating slopes (vertical lines, precision)
Go deepervariants and techniques · 2 combinations · resources
Variants and techniques
- Convex Hull (Andrew's monotone chain)Sort points and build lower and upper hulls with a stack that pops non-left turns, in O(n log n).
- Manhattan <-> Chebyshev RotationInterview · medium|x1-x2| + |y1-y2| = max(|u1-u2|, |v1-v2|) with u = x+y and v = x-y. So the max/min Manhattan distance reduces to max minus min of u and of v. In k dimensions, take the max over 2^(k-1) sign patterns.
Combinations
Manhattan <-> Chebyshev Rotation+Segment Tree / Fenwick (BIT)
max Manhattan distance among points in an index range, with updates, k <= 5
- Manhattan <-> Chebyshev Rotation:
- 2^(k-1) sign patterns turn L1 distance into max - min
- Segment Tree / Fenwick (BIT):
- range max and min per sign pattern, with point updates
Manhattan <-> Chebyshev Rotation+Ordered Set / Balanced BST (TreeMap, multiset)
remove exactly one point to minimise the max Manhattan distance
- Manhattan <-> Chebyshev Rotation:
- max distance = max(range of u, range of v)
- Ordered Set / Balanced BST (TreeMap, multiset):
- multisets of u and v support removing one point and reading the new extremes