Content deleted Content added
→Similar algorithms: Added Imai-Iri (after Hiroshi Imai and Masao Iri) |
|||
(48 intermediate revisions by 27 users not shown) | |||
Line 1:
{{Short description|Curve simplification algorithm}}
The '''Ramer–Douglas–Peucker algorithm''', also known as the '''Douglas–Peucker algorithm''' and '''iterative end-point fit algorithm''', is an algorithm that [[Decimation (signal processing)|decimates]] a curve composed of line segments to a similar curve with fewer points. It was one of the earliest successful algorithms developed for [[cartographic generalization]]. It produces the most accurate generalization, but it is also more time-consuming.<ref>{{cite journal |last1=Shi |first1=Wenzhong |last2=Cheung |first2=ChuiKwan |title=Performance Evaluation of Line Simplification Algorithms for Vector Generalization |journal=The Cartographic Journal |date=2006 |volume=43 |issue=1 |pages=27–44 |doi=10.1179/000870406x93490}}</ref>
== Idea ==▼
== Algorithm ==
[[Image:Douglas-Peucker animated.gif|thumb|right|Simplifying a piecewise linear curve with the Douglas–Peucker algorithm.]]
The starting curve is an ordered set of points or lines and the distance dimension {{math|''
<!--different implementation: The algorithm uses an array of boolean flags, initially set to not-kept, one for each point.-->
The algorithm [[recursion|recursively]] divides the line. Initially it is given all the points between the first and last point. It automatically marks the first and last point to be kept. It then finds the point that is farthest from the line segment with the first and last points as end points; this point is
If the point farthest from the line segment is greater than
When the recursion is completed a new output curve can be generated consisting of all and only those points that have been marked as kept.
Line 18 ⟶ 17:
=== Non-parametric Ramer–Douglas–Peucker ===
The choice of
=== Pseudocode ===
<syntaxhighlight lang="python">
'''function''' DouglasPeucker(PointList[], epsilon)▼
// Find the point with the maximum distance▼
dmax = 0▼
end = length(PointList)
for i = 2 to (end - 1) { d = perpendicularDistance(PointList[i], Line(PointList[1], PointList[end])) ResultList[] = empty;▼
// If max distance is greater than epsilon, recursively simplify▼
'''if''' (dmax > epsilon) {▼
// Recursive call▼
recResults1[] = DouglasPeucker(PointList[1...index], epsilon)▼
recResults2[] = DouglasPeucker(PointList[index...end], epsilon)▼
// Build the result list▼
ResultList[] = {recResults1[1...length(recResults1) - 1], recResults2[1...length(recResults2)]}▼
ResultList[] = {PointList[1], PointList[end]}▼
// Return the result▼
'''return''' ResultList[]▼
▲Link: https://karthaus.nl/rdp/
▲ } else {
</syntaxhighlight>
== Application ==
The algorithm is used for the processing of [[vector graphics]] and [[cartographic generalization]].
The algorithm is widely used in robotics<ref>{{cite
== Complexity ==
The running time of this algorithm when run on a polyline consisting of
Using (fully
Given specific conditions related to the bounding metric, it is possible to decrease the computational complexity to a range between {{math|''O''(''n'')}} and {{math|''O''(''2n'')}} through the application of an iterative method.<ref>{{Cite web|url=https://gist.github.com/stohrendorf/aea5464b1a242adca8822f2fe8da6612|title=ramer_douglas_peucker_funneling.py|website=Gist}}</ref>
The running time for [[digital elevation model]] generalization using the three-dimensional variant of the algorithm is {{math|''O''(''n''<sup>3</sup>)}}, but techniques have been developed to reduce the running time for larger data in practice.<ref>{{cite journal |last1=Fei |first1=Lifan |last2=He |first2=Jin |title=A three-dimensional Douglas–Peucker algorithm and its application to automated generalization of DEMs |journal=International Journal of Geographical Information Science |date=2009 |volume=23 |issue=6 |pages=703–718 |doi=10.1080/13658810701703001}}</ref>
==Similar algorithms==
[[File:Douglas–Peucker and Visvalingam–Whyatt simplification algorithms.svg|thumb|Comparison with [[Visvalingam–Whyatt algorithm]]]]
Alternative algorithms for line simplification include:
* [[Visvalingam–Whyatt algorithm|Visvalingam–Whyatt]]
*
*
* * Zhao–Saalfeld
* Imai-Iri
* [[Curve fitting]]
== Further reading ==
{{refbegin}}
* {{cite journal|first=Urs |last=Ramer
* {{cite journal|first1=David |last1=Douglas
* {{cite conference|first1=John |last1=Hershberger
* {{cite book|first1=R.O. |last1=Duda |first2=P.E. |last2=Hart |title=Pattern Classification and Scene Analysis |date=1973 |publisher=Wiley |___location=New York |bibcode=1973pcsa.book.....D |archive-url=https://web.archive.org/web/20110715184521/http://rii.ricoh.com/~stork/DHS.html |archive-date=2011-07-15 |url=http://rii.ricoh.com/~stork/DHS.html}}
* {{cite
{{refend}}
== References ==
Line 92 ⟶ 102:
* [https://github.com/odlp/simplify_rb Ruby gem implementation]
* [https://github.com/locationtech/jts JTS, Java Topology Suite], contains Java implementation of many algorithms, including the [https://locationtech.github.io/jts/javadoc/org/locationtech/jts/simplify/DouglasPeuckerSimplifier.html Douglas-Peucker algorithm]
* [https://rosettacode.org/wiki/Ramer-Douglas-Peucker_line_simplification Rosetta Code (Implementations in many languages)]
{{DEFAULTSORT:Ramer-Douglas-Peucker algorithm}}
|