[Math] Find polygon with smallest perimeter that encompasses all points

computational geometrygeneral-topologygeometry

Given a random set of points in 2D space such as:

Random points

How would one go about finding the smallest perimeter polygon that encompasses all points and has a point as each one of its vertices? For the above diagram the polygon would be:

Corrected points with polygon

Best Answer

This problem can be solved using the Graham scan. How does it work?

  1. Take a pivot point, let's say the point with the smallest y-coordinate. If there are two or more eligible candidates, take the one with smallest x-coordinate.
  2. Sort the remaining points by comparing the angle that they form with the horizontal line passing through the pivot point.
  3. Scan the sorted points: if you obtain a left turn, add the point to the temporarily solution, else remove the point from the collection and check backward until you obtain a left turn.

This is how the Graham scan works - my explanation is really simplified, but you'll find the detailed mechanism explanation on the Wikipedia page.

Related Question