How to the ramer–douglas–peucker algorithm, with a working svg simplifier
- Step 1Draw the baseline — Take the first and last point of the path and connect them with a straight line — the "baseline" for this segment.
- Step 2Find the furthest point — Measure the perpendicular distance from every intermediate point to that baseline, and find the single point furthest from it.
- Step 3Keep or discard against epsilon — If that furthest distance is greater than
epsilon(your tolerance), the point is significant: keep it, and recurse on the two sub-segments it creates. If it's within epsilon, discard every intermediate point — the baseline is a good enough approximation of them all. - Step 4Reassemble — The points that survived recursion, in order, form the simplified path. A larger epsilon keeps fewer points; a smaller epsilon stays closer to the original.
What the epsilon (tolerance) parameter does
Epsilon is the maximum distance the simplified curve may stray from the original, in the path's coordinate units. The tool's tolerance is this epsilon; it defaults to 1.0. These node-reduction figures are typical for icon-scale paths — your mileage varies with the path.
| tolerance (ε) | Effect | Typical node reduction |
|---|---|---|
| 0.5 | Barely perceptible — removes only near-collinear points | 10–25% |
| 1.0 (default) | Safe general cleanup; shape visually unchanged | 25–45% |
| 2.0 | Noticeable simplification, good for icons | 40–60% |
| 5.0 | Aggressive — only the dominant vertices survive | 60–80% |
| 10.0+ | Very rough; fine for tiny thumbnails or hit-areas only | 80%+ |
Where RDP is used
| Domain | Use |
|---|---|
| SVG / vector graphics | Shrink path data by removing redundant nodes (this tool) |
| Web mapping | Thin coastlines, borders, and routes at low zoom levels |
| GPS / tracking | Reduce a dense track log to a storable, drawable polyline |
| Computer vision | Simplify detected contours (e.g. OpenCV's approxPolyDP is RDP) |
| Handwriting / ink | Smooth and compress stylus stroke data |
Cookbook
The algorithm in pseudocode, then a worked example you can trace by hand.
RDP in pseudocode
Recursive divide-and-conquer. perpendicularDistance(p, line) is the distance from point p to the line through the segment's endpoints.
function rdp(points, epsilon):
# Find the point furthest from the baseline (first→last)
dmax = 0; index = 0
end = length(points)
for i = 2 to end - 1:
d = perpendicularDistance(points[i], line(points[1], points[end]))
if d > dmax:
index = i; dmax = d
if dmax > epsilon:
# Significant point — recurse on both halves and join
left = rdp(points[1..index], epsilon)
right = rdp(points[index..end], epsilon)
return left[1..-2] + right # drop duplicated joint
else:
# Everything between the endpoints is within tolerance — drop it
return [points[1], points[end]]A worked example
Five points; epsilon = 1.0. The middle points are nearly on the line from A to E, except C.
Points: A(0,0) B(1,0.2) C(2,2) D(3,0.1) E(4,0) Baseline A→E is the x-axis (y=0). Perp distances: B=0.2 C=2.0 D=0.1 Furthest = C at 2.0 > ε(1.0) → keep C, recurse A→C and C→E. A→C: B's distance to line A-C < 1.0 → drop B. C→E: D's distance to line C-E < 1.0 → drop D. Result: A, C, E (5 points → 3, shape preserved)
Running it on your SVG
The SVG Path Simplifier parses each <path>, converts curves to sampled polylines, runs RDP at your tolerance, and rewrites the path. Start at the 1.0 default and increase until you see the shape soften.
Drop your .svg into /svg-tools/svg-path-simplifier tolerance = 1.0 → safe cleanup tolerance = 3.0 → aggressive (check the preview) The tool reports nodes before/after and the byte saving.
Edge cases and what actually happens
Closed paths (the shape is a loop)
handledA naïve first→last baseline degenerates when the start and end points coincide. RDP implementations split a closed path at its two furthest-apart points first, then simplify each half — so loops simplify correctly rather than collapsing.
Bézier curves, not just straight segments
sampledRDP works on points, so curves are first sampled into a dense polyline, simplified, and (optionally) refitted. That's why very smooth curves can look slightly faceted after aggressive simplification — you're seeing the polyline approximation.
Tolerance set too high
over-simplifiedPast a point, RDP discards vertices that actually mattered and the shape visibly distorts — corners round off, thin features vanish. Always preview; the right tolerance is the largest value that still looks right at your display size.
Self-intersecting or very spiky paths
watch closelyRDP optimises perpendicular distance, not topology — aggressive settings can let a simplified segment cross another part of the path. For spiky or self-touching shapes, simplify gently and inspect.
The path is already minimal
no-opIf every point is further than epsilon from its baseline, nothing is removed and the output equals the input. That's correct behaviour — RDP never adds error beyond epsilon.
Units and viewBox scaling
scale-relativeEpsilon is in path coordinate units, so the same tolerance is more aggressive on a small viewBox than a large one. If results seem too strong or too weak, account for the path's coordinate scale.
Frequently asked questions
What does the Ramer–Douglas–Peucker algorithm actually do?
It decimates a curve made of line segments into a similar curve with fewer points. It recursively keeps the points that lie furthest from the straight line between a segment's endpoints (beyond a tolerance epsilon) and discards the rest, so the simplified path keeps the original's overall shape using a subset of its points.
What is epsilon / the tolerance parameter?
Epsilon (the tool calls it tolerance, default 1.0) is the maximum distance the simplified curve is allowed to deviate from the original, in the path's coordinate units. Bigger epsilon = more aggressive simplification and fewer points; smaller epsilon = closer to the original. It's the single knob that controls the whole result.
Does the JAD tool really use RDP?
Yes — the SVG Path Simplifier implements the recursive Ramer–Douglas–Peucker method described on this page, with a configurable tolerance (epsilon) that defaults to 1.0. It runs entirely in your browser.
How much smaller will my SVG get?
For paths with redundant nodes, typically 30–60% fewer points at a moderate tolerance, which translates to a similar drop in path-data bytes. Hand-drawn or auto-traced paths (lots of near-collinear points) shrink the most; already-clean paths barely change. Use the table above to pick a tolerance.
Will simplifying ruin my curves?
At a sensible tolerance, no — the shape stays visually identical. Because curves are sampled to polylines for RDP, very aggressive settings can make smooth curves look faceted, and fine detail can disappear. Preview the result and back the tolerance off if you see distortion.
Is RDP the same as what OpenCV or Google Maps use?
It's the same core algorithm. OpenCV's approxPolyDP is Ramer–Douglas–Peucker, and map libraries use it (or close relatives like Visvalingam–Whyatt) to thin geometry at low zoom. The principle — drop points within a tolerance of the simplified line — is identical.
What's the difference between RDP and Visvalingam–Whyatt?
Both reduce points, but by different criteria. RDP keeps points by perpendicular distance to a baseline (good at preserving sharp features). Visvalingam–Whyatt removes points by the area of the triangle they form with their neighbours (often gives smoother, more natural-looking results on maps). RDP is the more common default and is what this tool uses.
Does it handle closed shapes and multiple subpaths?
Yes. Closed paths are split at their two extreme points before simplification so the loop doesn't collapse, and each subpath in a compound path is simplified independently. See the edge cases above for the details and what to watch for.
What tolerance should I start with?
1.0 — the default — for a safe cleanup that won't visibly change the shape. Move up to 2–3 for icons where you want a real size cut, and preview. Only go above 5 for thumbnails or hit-test geometry where exact shape doesn't matter.
Is my file uploaded to simplify it?
No. The SVG Path Simplifier parses and simplifies your file entirely in the browser using the DOM and the RDP implementation — nothing is sent to a server.
Privacy first
Every JAD SVG tool runs entirely in your browser using the DOM API and Canvas. Your SVG files never leave your device — verified by zero outbound network requests during processing.