Intersection of two convex polygons
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Mathematical and computational geometry often involve operations on geometric entities. One such fundamental operation is the intersection of polygons. When dealing with convex polygons, the intersection operation becomes more straightforward due to the properties of convexity. This article will delve into the intersection of two convex polygons, presenting technical explanations, examples, and additional insights.
Convex Polygons in Context
A convex polygon is a polygon in which a line drawn between any two points within the polygon remains inside the polygon. Convex polygons have no indentations or "inward" vertices, simplifying many computational geometry processes.
Properties of Convex Polygons
- Line Segment Property: For any two points inside a convex polygon, the line segment connecting them lies entirely inside the polygon.
- Angle Property: All interior angles are less than or equal to 180 degrees.
- Vertex Visibility: Every vertex of a convex polygon can be "seen" from every other vertex; no vertex obstructs the view.
Intersection of Two Convex Polygons
Intersecting two convex polygons acts on the principles of geometry and computational algorithms. The result of an intersection is a new polygon that represents the overlapping area of the original polygons.
Algorithm for Intersection
One efficient algorithm often used for intersecting two convex polygons is the Sutherland–Hodgman algorithm, which clips one polygon against the edges of the other.
Steps:
- Iteration over Polygon Edges:
- Choose one polygon as the subject and the other as the clip polygon.
- Iterate over the edges of the clip polygon.
- Edge Clipping:
- For each edge of the clip polygon, clip the subject polygon's edges.
- Determine which vertices of the subject polygon lie inside the clip edge.
- Construct a new list of vertices for the subject polygon.
- Repetition for All Edges:
- Repeat the clipping for all edges of the clip polygon.
- The final subject polygon vertices describe the intersection.
Example
Consider two triangles, A and B. Triangle A has vertices (0,0), (2,0), (1,2) and triangle B has vertices (1,0), (3,0), (2,2).
- Edge Clipping: Clip A with the edges of B and vice versa.
- Intersection: The intersection result might have points from both triangles depending on their overlap, forming a potentially more complex polygon.
Special Cases and Considerations
- No Intersection: When no overlapping area exists, the result is null.
- Complete Overlap: If one polygon is fully inside the other, the intersection is the smaller polygon.
- Edge and Vertex Overlap: Special handling is necessary when polygons share vertices or edges without covering areas.
Efficiency and Complexity
The intersection algorithm for convex polygons is efficient due to their simple properties. Complexity is generally linear, dependent on the number of edges (, where and are the numbers of edges in the polygons).
Conclusion
Understanding the intersection of convex polygons is crucial in areas such as computer graphics, collision detection, and spatial analysis. The clear geometric properties of convex shapes make their intersection computationally simpler and more efficient than non-convex counterparts.
Key Points Summary
| Topic | Description |
| Convex Polygon Definition | A polygon with no indentations; line segment stays inside. |
| Properties | Every angle ≤ 180°, vertices see each other. |
| Intersection Algorithm | Sutherland–Hodgman: iterative edge clipping. |
| Complexity | Efficient, generally linear in edge count (). |
| Special Cases | No intersection or full containment scenarios. |
Computational geometry’s applications in technology and science underscore the importance of efficient operations like polygon intersection, especially in areas demanding precision and speed. Convex polygons, with their elegant structure, exemplify the harmony of mathematical beauty and practical utility.
Related reading
- Interview challenge Find the different elements in two arrays
- Interview question - Search in sorted array X for index i such that Xi i
- Interview question Check if one string is a rotation of other string
- Interview Question Data structure for a large social network
- Inverting a 4x4 matrix
- Is 161803398 A 'Special' Number? Inside of Math.Random
- Interview Question Find Median From Mega Number Of Integers
- Interview Question Merge two sorted singly linked lists without creating new nodes

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.