Navigation

Convex hull algorithm

Demo (JavaScript)

Random static pointsRandom moving pointsManual positioning

This JavaScript program computes the smallest convex polygon that encloses an arbitrary set of points in the plane. Points defining the convex hull are colored red; points in the interior are colored gray. Instructions for manual positioning mode:

Left-click in a blank space to add a new point

Left-click an existing point and drag to move it

Right-click an existing point to delete it

Description

This library computes the convex hull polygon that encloses a collection of points on the plane. Andrew’s monotone chain algorithm is used, which runs in Θ(n log n) time in general, or Θ(n) time if the input is already sorted.

The code of the algorithm is available in multiple languages. The JavaScript version has a live demo that is shown at the top of the page.