Ramer-Douglas-Peucker line simplification: Difference between revisions
Content added Content deleted
(Added Swift solution) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 18: | Line 18: | ||
:* the Wikipedia article: [https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm Ramer-Douglas-Peucker algorithm]. |
:* the Wikipedia article: [https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm Ramer-Douglas-Peucker algorithm]. |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Go}} |
|||
<lang 11l>F rdp(l, epsilon) -> [(Float, Float)] |
|||
V x = 0 |
|||
V dMax = -1.0 |
|||
V p1 = l[0] |
|||
V p2 = l.last |
|||
V p21 = p2 - p1 |
|||
L(p) l[1.<(len)-1] |
|||
V d = abs(cross(p, p21) + cross(p2, p1)) |
|||
I d > dMax |
|||
x = L.index + 1 |
|||
dMax = d |
|||
I dMax > epsilon |
|||
R rdp(l[0..x], epsilon) [+] rdp(l[x..], epsilon)[1..] |
|||
R [l[0], l.last] |
|||
print(rdp([(0.0, 0.0), |
|||
(1.0, 0.1), |
|||
(2.0,-0.1), |
|||
(3.0, 5.0), |
|||
(4.0, 6.0), |
|||
(5.0, 7.0), |
|||
(6.0, 8.1), |
|||
(7.0, 9.0), |
|||
(8.0, 9.0), |
|||
(9.0, 9.0)], 1.0))</lang> |
|||
{{out}} |
|||
<pre> |
|||
[(0, 0), (2, -0.1), (3, 5), (7, 9), (9, 9)] |
|||
</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |