The Ramer–Douglas–Peucker (RDP) algorithm (also called Douglas–Peucker) is a classic path / polyline simplification algorithm. It reduces the number of points in a curve while preserving its overall shape within a specified error tolerance.
It is widely used in:
Given:
Goal:
Remove “unnecessary” intermediate points while ensuring the simplified path never deviates more than ( \varepsilon ) from the original.
Imagine stretching a rubber band from the first point to the last point:
The algorithm keeps points only when they are needed to preserve shape.
For each intermediate point ( p_i ), compute its perpendicular distance to the line segment ( \overline{p_1 p_n} ).
For point ( P ) and line ( AB ):
[ d = \frac{|(B-A) \times (A-P)|}{|B-A|} ]
Expanded:
[ d = \frac{|(x_2-x_1)(y_1-y_0) - (x_1-x_0)(y_2-y_1)|}{\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}} ]
pointsεStart with first and last point
points[0] and points[n-1]Find max deviation
For each intermediate point:
(start → end)Find the point with maximum distance d_max
Decision
If d_max > ε:
Keep that point
Recursively apply RDP to:
Left segment
Right segment
Else:
Combine results
Original path:
A ---- x ---- y ---- z ---- B
If:
x, y, z are close to line AB → simplify to A ---- By deviates too much → split:
A ---- y ---- B
Then recurse on A → y and y → B.
RDP(points, ε):
if points.length < 3:
return points
start = points[0]
end = points[last]
maxDist = 0
index = 0
for i in 1 to n-2:
d = perpendicularDistance(points[i], start, end)
if d > maxDist:
maxDist = d
index = i
if maxDist > ε:
left = RDP(points[0..index], ε)
right = RDP(points[index..end], ε)
return left + right[1:]
else:
return [start, end]
Used to avoid deep recursion:
stack.push((0, n-1))
keep[0] = keep[n-1] = true
while stack not empty:
(start, end) = stack.pop()
maxDist = 0
index = -1
for i in start+1 to end-1:
d = distance(points[i], points[start], points[end])
if d > maxDist:
maxDist = d
index = i
if maxDist > ε:
keep[index] = true
stack.push((start, index))
stack.push((index, end))
| ε value | Result |
|---|---|
| Small | High fidelity, little simplification |
| Medium | Balanced |
| Large | Aggressive simplification |
Rule of thumb:
RDP keeps only the points that matter.
By recursively removing points that do not significantly alter shape, it achieves high compression with controlled error, making it one of the most important algorithms in geometric processing.
If you want:
Just tell me 👍