Douglas-Peucker Polygon Simplification

Simplify polylines and polygons by recursively discarding vertices whose perpendicular deviation from a chord falls below a chosen tolerance, using the Douglas-Peucker algorithm.

Step 1 of 157%

Tutorial

Introduction and Perpendicular Distance

In Live Air Routing, polygons describing airspace boundaries, restricted zones, and weather cells are often produced from rasterized satellite data and contain far more vertices than necessary for routing computation. The Douglas-Peucker algorithm simplifies such a polyline (and by extension, a closed polygon) by discarding vertices whose perpendicular deviation from a chord falls below a chosen tolerance ε.\varepsilon.

The basic subroutine is the perpendicular distance from a point P=(x0,y0)P=(x_0,y_0) to the line through A=(x1,y1)A=(x_1,y_1) and B=(x2,y2):B=(x_2,y_2){:}

d=(x2x1)(y1y0)(x1x0)(y2y1)(x2x1)2+(y2y1)2.d = \dfrac{\big|(x_2-x_1)(y_1-y_0) - (x_1-x_0)(y_2-y_1)\big|}{\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}}.

The numerator is the magnitude of the 2D cross product (BA)×(PA),(B-A) \times (P-A), which equals twice the area of triangle ABP.\triangle ABP. The denominator is the length of the chord AB.\overline{AB}.

For example, with A=(0,0),A=(0,0), B=(6,0),B=(6,0), and P=(2,3),P=(2,3),

d=(6)(03)(02)(00)36+0=186=3.\begin{align*} d &= \dfrac{|(6)(0-3) - (0-2)(0-0)|}{\sqrt{36 + 0}} \\[3pt] &= \dfrac{|{-18}|}{6} \\[3pt] &= 3. \end{align*}
navigate · Enter open · Esc close · ⌘K/Ctrl K toggle