geometry
computational-geometry
polygon-construction
convex-hull
point-set-enclosure

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.

Practice algorithms

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

  1. 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.
  2. Algorithmic Complexity: The efficiency of an algorithm is evaluated based on time complexity, typically denoted as O(nlogn)O(n \log n), O(n2)O(n^2), etc., where nn is the number of input points.
  3. 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.
  4. 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 O(nlogn)O(n \log n) 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 O(nh)O(nh) complexity, where hh 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 hh is much smaller than nn.

3. QuickHull

  • Description: An efficient divide-and-conquer algorithm akin to QuickSort, operating in average O(nlogn)O(n \log n) time but can degenerate to O(n2)O(n^2).
  • 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 O(nlogh)O(n \log h) time, where hh 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

  1. Robotics: Pathfinding and obstacle avoidance require accurate mapping of environments, often using non-convex polygons to model spaces.
  2. Spatial Data Analysis: GIS employs these algorithms to demarcate geographic regions based on spatial data points, aiding in urban planning and resource management.
  3. Computer Graphics: Many rendering algorithms rely on convex hull computations for object boundary determination and collision detection.

Summary Table

AlgorithmTime ComplexityStrengthsLimitations
Graham’s ScanO(nlogn)O(n \log n)Balanced performance, moderate implementationMore vertices complicate time efficiency
Jarvis’s MarchO(nh)O(nh)Simple to understand, minimal sorting requiredInefficient for large hh or datasets
QuickHullAverage O(nlogn)O(n \log n)Simple recursive structureCan degenerate for certain datasets
Chan’s AlgorithmO(nlogh)O(n \log h)Combination of efficiency and manageable implementationComplex 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
Course
Intermediate
27 lessons
15 hours
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 course
Track 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.

Practice algorithms

All Rights Reserved.