Polygon enclosing a set of points
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Polygonal enclosures are a fascinating area of study in computational geometry, applicable to various fields such as computer graphics, geographic information systems (GIS), and robotics. The primary problem is formulating a polygon that entirely encapsulates a set of given points on a plane. Various algorithms achieve this, each with different efficiencies and applicability. Below, we delve into the technical aspects of enclosing polygons, discuss notable algorithms, and explore their real-world applications.
Key Concepts and Definitions
- Convex Hull: The smallest convex polygon that can enclose a given set of points. Every point on the convex hull is a "vertex" of the polygon.
- Algorithmic Complexity: The efficiency of an algorithm is evaluated based on time complexity, typically denoted as , , etc., where is the number of input points.
- Non-Convex Polygons: Though the convex hull is often used for enclosure, some applications require non-convex polygons to tightly fit into the points' distribution.
- Applications: An enclosing polygon is used in pathfinding, collision detection, and spatial analysis.
Algorithms for Enclosing a Polygon
Several algorithms efficiently compute an enclosing polygon:
1. Graham’s Scan
- Description: This algorithm finds the convex hull of a set of points in time using a sorting step by angular coordinates.
- Steps:
- Find the point with the lowest y-coordinate; this serves as the reference point.
- Sort the points based on the polar angle with the reference point.
- Traverse the sorted list, and use a stack to manage the vertices of the convex hull efficiently.
- Use Case: Best for applications requiring balanced performance without complex implementation.
2. Jarvis’s March (Gift Wrapping)
- Description: Also finds the convex hull, with a simpler but less efficient complexity, where is the number of vertices on the hull.
- Steps:
- Start from the leftmost point and wrap around the points, choosing the next point as the one that is the most counterclockwise relative to the current point.
- Use Case: Preferred when the dataset is small or if is much smaller than .
3. QuickHull
- Description: An efficient divide-and-conquer algorithm akin to QuickSort, operating in average time but can degenerate to .
- Steps:
- Find the furthest points along the x-axis as the start of the hull.
- Recursively find points outside the line segment formed by current hull and add them to the hull.
- Use Case: Useful with datasets having a more pronounced linear distribution.
4. Chan’s Algorithm
- Description: Combines existing algorithms to achieve time, where is the number of points on the hull.
- Steps:
- Use other algorithms like Graham’s, combined iteratively with a binary search to quickly identify the hull's perimeter points.
- Use Case: Effective for large datasets with a smaller number of hull points.
Enclosing Non-convex Polygons
For scenarios where the tightest fit is essential, and a convex hull is too loose, non-convex solutions such as alpha shapes or boundary extraction from Delaunay triangulations are used.
- Alpha Shapes: Adjust the shape parameter to control the tightness of the fit, encompassing concavities in the making.
- Boundary Extraction: By filtering Delaunay triangulations, non-convex boundaries that fit internal voids and recesses can be crafted.
Applications
- Robotics: Pathfinding and obstacle avoidance require accurate mapping of environments, often using non-convex polygons to model spaces.
- Spatial Data Analysis: GIS employs these algorithms to demarcate geographic regions based on spatial data points, aiding in urban planning and resource management.
- Computer Graphics: Many rendering algorithms rely on convex hull computations for object boundary determination and collision detection.
Summary Table
| Algorithm | Time Complexity | Strengths | Limitations |
| Graham’s Scan | Balanced performance, moderate implementation | More vertices complicate time efficiency | |
| Jarvis’s March | Simple to understand, minimal sorting required | Inefficient for large or datasets | |
| QuickHull | Average | Simple recursive structure | Can degenerate for certain datasets |
| Chan’s Algorithm | Combination of efficiency and manageable implementation | Complex iterative method |
In conclusion, selecting the proper algorithm and polygon type hinges on the specific requirements of your application, data size, and distribution. By understanding these foundational techniques, you'll be equipped to handle a broad array of computational geometry challenges.
Related reading
- Populate nested array in mongoose
- Possible collisions in the standard JavaScript Object hash table implementation?
- Possible permutations of BST's input
- Postfix notation to expression tree
- Polygon infill algorithm
- polygon union without holes
- potential On solution to Longest Increasing Subsequence
- Pre-order to post-order traversal

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.