Geometry in competitive programming is an intriguing realm. It stands apart from other topics in a way that is difficult to describe until you’ve spent enough time grappling with it. Where graph theory revolves around connections and distances between abstract nodes, and dynamic programming shapes problems into subproblems and transitions, computational geometry demands a certain quiet precision. It forces you to see space, shape, orientation, and boundaries through a lens that blends mathematics, logic, and spatial intuition all at once.
Among all the topics inside geometry, polygons form a world of their own—rich, diverse, and filled with challenging patterns. They appear constantly in problems: area computations, perimeter queries, convex hull building, shape reconstruction, intersection checks, point containment queries, triangulation, polygon clipping, Minkowski sums, and countless others. Understanding polygons deeply opens up key parts of the competitive programming landscape.
This course—spread across a hundred detailed articles—aims to take you on a long, immersive journey into the heart of polygon-based geometric algorithms. It will start with the essentials, move steadily into advanced techniques, unravel subtle pitfalls, and eventually reveal the elegant structures and shortcuts that experienced contestants rely on during contests.
Before entering that world, it’s important to understand what makes polygons such an essential chapter in computational geometry.
Polygons feel familiar because they come from everyday experiences. The edges we draw on paper, the boundaries of land plots, the shapes detected in computer vision, or the simple outlines used in games—all carry the essence of polygons. This familiarity makes many people underestimate the depth hidden behind them. But in the realm of competitive programming, polygons demand not just recognition, but rigorous algorithmic understanding.
One of the earliest realizations you'll encounter is that polygon problems are not really about “shapes” in the casual sense. They're about maintaining accuracy under strict constraints, controlling rounding errors, reasoning through edge cases, and working with mathematical representations that computers must interpret flawlessly. The difference between a beginner and an experienced solver often lies in how naturally one handles these details.
For instance, consider the classic problem of determining whether a point lies inside a polygon. It sounds like a question from a high-school math book, yet solving it reliably in code—where vertices might be collinear, where edges can extend infinitely in mental models, and where precision errors lead to misclassification—requires careful thought. Ray casting and winding numbers are not just definitions; they’re algorithms with subtleties, and those subtleties are exactly what competitive problems love to expose.
When you move to polygon intersections, things get even more interesting. Intersecting two convex polygons is straightforward for someone who has mastered rotational sweeps or the two-finger technique. But intersecting general polygons—which might be concave, self-touching, or containing tricky boundary cases—is a beast of its own. The slightest oversight may produce incorrect results or overlooked intersection points. Competitive environments don’t forgive such mistakes.
This is where geometry begins to teach you discipline. Unlike other domains where small inaccuracies might still pass through hidden test cases, computational geometry often has no tolerance for sloppy thinking. If you make a mistake in orientation checks, or if your cross-product sign calculation fails in extreme cases, the entire result collapses. The beauty, however, is that once you internalize these foundations, the confidence you feel while tackling geometry problems is unmatched.
The world of polygon algorithms is also notably diverse. You start with the basic building blocks: computing area using the shoelace formula, checking convexity, understanding orientation tests, computing cross products, detecting segment intersections, and checking point-on-segment conditions. Every advanced algorithm builds on these basics.
As the course progresses, you’ll explore convex hulls—one of the most iconic structures in computational geometry. The hull is the polygon that wraps around a set of points most tightly, like pulling a rubber band over scattered nails. Constructing it efficiently (with Graham’s scan or the Monotonic Chain algorithm) is one of the first major milestones in your journey. But even convex hulls extend far beyond construction. You’ll encounter advanced hull applications: rotating calipers for diameter and width, hull trick variants used in optimization, intersection tests between hulls, and merging hulls in logarithmic time.
After hulls, the journey flows into polygon decomposition. Triangulation is a powerful concept: breaking a polygon into triangles opens up a host of computational opportunities. With triangulation, area becomes easier to compute, dynamic programming becomes applicable, queries become faster, and intersection algorithms can run more efficiently. But triangulation itself is subtle—especially when the polygon is concave or has holes embedded within it.
The more you explore, the more you notice that many algorithms that seem difficult at first become natural once you visualize them properly. Geometry rewards imagination. Sometimes the key to solving a complex polygon problem is drawing the configuration in your mind and noticing a symmetry or a constraint that wasn’t obvious numerically.
Competitive programmers often talk about geometry as a “hard” topic, but what they actually mean is that geometry demands precision. Once you treat precision as a discipline rather than an obstacle, doors begin to open. Many problems that look intimidating because of their diagram-like statements turn out to have beautifully simple solutions—if you know which properties to use.
This course aims to walk you through that transformation. A hundred articles give us enough room not only to teach algorithms but also to develop geometric intuition. We will examine polygons through many viewpoints: algebraic, geometric, algorithmic, and conceptual. You’ll see how simple operations like computing cross products turn into powerful primitives for checking orientation, detecting convexity, distinguishing between tangent and intersecting lines, and computing distances.
One of the things that makes polygon algorithms compelling is how naturally they extend into motion and dynamic situations. For example, when two polygons move relative to each other, collision detection becomes essential. Understanding the separating axis theorem and Minkowski sums opens doors to solving many motion-based tasks. These ideas might seem like they belong in physics engines rather than programming contests, yet they appear surprisingly often in competitive problems, especially in harder rounds.
Another aspect you’ll encounter is polygon clipping—cutting a polygon using a line or another polygon. It sounds simple but becomes incredibly useful for solving problems that involve layering shapes, computing intersections, or answering queries about partially defined regions. Line-sweep techniques, half-plane intersections, and Sutherland–Hodgman algorithms come to life here, each suited for different contexts and constraints.
And then there's the fascinating world of convexity. Many algorithms become significantly easier when dealing with convex polygons. A convex polygon has predictable properties: every internal angle is less than 180°, every segment connecting two inside points stays inside, and intersection operations become cleaner. The course will give you a deep understanding of working with convex polygons—how to exploit their structure for efficiency, how to detect convexity, how to maintain convex structures under dynamic updates, and how to solve queries over them.
But polygons are not always friendly. Concave polygons bring their own flavor of challenges. They can hide pockets, fold inward sharply, or create deceptive intersections. Algorithms that work gracefully on convex shapes often stumble in concave settings. In competitive programming, many tasks will provide general polygons, and you must be ready to handle both cases gracefully.
One important theme you’ll revisit often is accuracy and numerical stability. Even though many coding platforms use integers for geometry problems, floating-point calculations inevitably appear in tasks involving angles, distances, or arbitrary inputs. You’ll learn strategies to maintain stability: using epsilons, preferring cross products over angle computations, avoiding trigonometry when possible, and using robust line-intersection formulas. With practice, you’ll see how small improvements in numerical handling significantly reduce the risk of wrong answers.
Another fascinating subject you’ll explore is polygon union, intersection, and difference. Problems that ask you to compute the area of union of multiple shapes or the region formed by clipping polygons are classic in higher-level contests. Implementing these algorithms requires both conceptual understanding and meticulous coding, but once mastered, they become a powerful addition to your toolkit.
You will also engage with spatial queries. Polygon-based range queries, such as checking whether points lie within a dynamically changing region or finding distances from points to polygon boundaries, are common in problems that mix geometry with data structures. You’ll learn how to combine tree-based query solutions with geometric primitives, allowing you to handle thousands or millions of operations efficiently.
What makes polygon algorithms so engaging is that they often link multiple mathematical ideas. You’ll draw upon vector algebra, trigonometry (sparingly), complex numbers, coordinate transformations, and even number theory when dealing with lattice polygons. When these fields blend together, geometric problems reveal their full richness.
Toward the advanced sections of the course, you’ll discover structures like Delaunay triangulations, Voronoi diagrams, planar subdivision techniques, and polygon partitioning algorithms. While these topics can be quite deep, understanding their simplified contest-oriented versions can dramatically increase your problem-solving range. They appear in tasks involving nearest neighbors, minimum spanning structures, region growth, pathfinding around obstacles, and more.
Alongside theory, this course will also emphasize the mindset required for geometry in competitive programming. Geometry problems often include tricky edge cases: collinear points, degenerate polygons, overlapping edges, repeated points, floating-point inaccuracy, and unexpected corner configurations. Learning how to anticipate and handle these issues is as important as learning the algorithms themselves. Over time, you’ll develop the instinct to test your logic against these corner scenarios before you finalize your solution.
You’ll also learn the practical art of writing clean geometric code. Geometry often involves repeated operations—computing cross products, finding intersections, normalizing vectors, checking ranges. Organizing these operations into clean functions not only makes your code resilient but also reduces the cognitive load during contests. Many experienced contestants maintain their own geometry libraries. By the end of this course, you may feel inclined to craft your own.
Another key insight you’ll acquire is the elegance of geometric proofs. Unlike many discrete algorithms that rely on counting or combinatorial logic, geometry often proves correctness visually or through orientation arguments. This visual intuition becomes a powerful ally in discovering new approaches or debugging errors.
Through these hundred articles, the goal is not just to teach you algorithms but to help you grow comfortable with the geometric way of thinking. With time, polygons will no longer feel like complicated shapes defined by lists of vertices. They will start feeling like dynamic structures that reveal their secrets when you apply the right perspective.
You'll reach a point where handling intersection cases, computing areas, building convex hulls, or answering containment queries becomes second nature. And when you read a contest problem describing shapes or boundaries, instead of feeling intimidated, you’ll feel curious—ready to break down the geometry and find the solution.
Polygon algorithms are about exploring the harmony between mathematics and imagination. They invite you to blend precision with creativity. Once you embrace that, the world of computational geometry becomes not just a topic in competitive programming but an inspiring field of problem solving in its own right.
This course is here to guide you through that transformation. Step by step, concept by concept, insight by insight, you’ll build a profound understanding of polygon algorithms and the confidence to apply them in any contest scenario. The journey is long, but incredibly rewarding.
Let’s begin the exploration.
1. Introduction to Polygons: Definitions and Properties
2. Basic Polygon Representation: Vertex Lists and Edge Lists
3. Convex vs. Concave Polygons: Key Differences
4. Area of a Simple Polygon: Shoelace Formula
5. Perimeter of a Polygon: Calculation Techniques
6. Checking if a Point Lies Inside a Polygon: Ray Casting Algorithm
7. Orientation of Points: Cross Product Basics
8. Convex Hull: Graham’s Scan Algorithm
9. Convex Hull: Andrew’s Monotone Chain Algorithm
10. Polygon Triangulation: Ear Clipping Method
11. Polygon Intersection: Simple Cases and Concepts
12. Polygon Union: Basic Approaches
13. Polygon Containment: Point-in-Polygon Tests
14. Polygon Translation, Rotation, and Scaling
15. Polygon Mirroring and Reflection
16. Polygon Simplification: Douglas-Peucker Algorithm
17. Polygon Offsetting: Minkowski Sum Basics
18. Polygon Clipping: Sutherland-Hodgman Algorithm
19. Polygon Coloring: Two-Coloring for Bipartite Graphs
20. Polygon Visibility: Basic Concepts and Applications
21. Convex Polygon Properties: Diagonals and Angles
22. Polygon Decomposition: Convex Partitioning
23. Polygon Intersection: Weiler-Atherton Algorithm
24. Polygon Union: Advanced Techniques
25. Polygon Difference: Boolean Operations
26. Polygon Offsetting: Minkowski Difference
27. Polygon Triangulation: Monotone Partitioning
28. Polygon Triangulation: Delaunay Triangulation
29. Voronoi Diagrams: Basics and Applications
30. Voronoi Diagrams: Fortune’s Algorithm
31. Polygon Intersection with Circles: Basic Cases
32. Polygon Intersection with Lines: Line Clipping
33. Polygon Intersection with Rectangles: Axis-Aligned Cases
34. Polygon Intersection with Other Polygons: General Cases
35. Polygon Containment: Convex vs. Concave Cases
36. Polygon Containment: Winding Number Algorithm
37. Polygon Containment: Ray Casting Optimization
38. Polygon Containment: Bounding Box Optimization
39. Polygon Containment: Hierarchical Methods
40. Polygon Containment: Grid-Based Methods
41. Polygon Containment: Quadtree-Based Methods
42. Polygon Containment: Sweep Line Algorithm
43. Polygon Containment: Plane Sweep Algorithm
44. Polygon Containment: Randomized Algorithms
45. Polygon Containment: Parallel Algorithms
46. Polygon Containment: GPU-Based Methods
47. Polygon Containment: Approximation Algorithms
48. Polygon Containment: Exact Algorithms
49. Polygon Containment: Heuristic Methods
50. Polygon Containment: Hybrid Methods
51. Polygon Intersection: Boolean Operations on Convex Polygons
52. Polygon Intersection: Boolean Operations on Concave Polygons
53. Polygon Intersection: Boolean Operations on Self-Intersecting Polygons
54. Polygon Intersection: Boolean Operations on Non-Simple Polygons
55. Polygon Intersection: Boolean Operations on 3D Polygons
56. Polygon Intersection: Boolean Operations on Nested Polygons
57. Polygon Intersection: Boolean Operations on Multi-Polygons
58. Polygon Intersection: Boolean Operations on Polygons with Holes
59. Polygon Intersection: Boolean Operations on Polygons with Curved Edges
60. Polygon Intersection: Boolean Operations on Polygons with Non-Linear Edges
61. Polygon Intersection: Boolean Operations on Polygons with Non-Uniform Edges
62. Polygon Intersection: Boolean Operations on Polygons with Non-Planar Edges
63. Polygon Intersection: Boolean Operations on Polygons with Non-Manifold Edges
64. Polygon Intersection: Boolean Operations on Polygons with Non-Orientable Edges
65. Polygon Intersection: Boolean Operations on Polygons with Non-Simple Edges
66. Polygon Intersection: Boolean Operations on Polygons with Non-Convex Edges
67. Polygon Intersection: Boolean Operations on Polygons with Non-Concave Edges
68. Polygon Intersection: Boolean Operations on Polygons with Non-Self-Intersecting Edges
69. Polygon Intersection: Boolean Operations on Polygons with Non-Nested Edges
70. Polygon Intersection: Boolean Operations on Polygons with Non-Multi-Polygons
71. Polygon Intersection: Boolean Operations on Polygons with Non-Holes
72. Polygon Intersection: Boolean Operations on Polygons with Non-Curved Edges
73. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Linear Edges
74. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Uniform Edges
75. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Planar Edges
76. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Manifold Edges
77. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Orientable Edges
78. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Simple Edges
79. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Convex Edges
80. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Concave Edges
81. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Self-Intersecting Edges
82. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Nested Edges
83. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Multi-Polygons
84. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Holes
85. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Curved Edges
86. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Linear Edges
87. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Uniform Edges
88. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Planar Edges
89. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Manifold Edges
90. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Orientable Edges
91. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Simple Edges
92. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Convex Edges
93. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Concave Edges
94. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Self-Intersecting Edges
95. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Nested Edges
96. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Multi-Polygons
97. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Holes
98. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Curved Edges
99. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Non-Linear Edges
100. Polygon Intersection: Boolean Operations on Polygons with Non-Non-Non-Non-Uniform Edges