Ramer-Douglas-Peucker line simplification: Difference between revisions
Content deleted Content added
m →{{header|Phix}}: syntax coloured |
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
||
Line 22: | Line 22: | ||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="11l">F rdp(l, ε) -> [(Float, Float)] |
||
V x = 0 |
V x = 0 |
||
V dMax = -1.0 |
V dMax = -1.0 |
||
Line 49: | Line 49: | ||
(7.0, 9.0), |
(7.0, 9.0), |
||
(8.0, 9.0), |
(8.0, 9.0), |
||
(9.0, 9.0)], 1.0))</ |
(9.0, 9.0)], 1.0))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 57: | Line 57: | ||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <assert.h> |
||
#include <math.h> |
#include <math.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 126: | Line 126: | ||
print_points(out, n); |
print_points(out, n); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 135: | Line 135: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.Collections.Generic; |
using System.Collections.Generic; |
||
using System.Linq; |
using System.Linq; |
||
Line 224: | Line 224: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Points remaining after simplification: |
<pre>Points remaining after simplification: |
||
Line 235: | Line 235: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#include <cmath> |
#include <cmath> |
||
#include <utility> |
#include <utility> |
||
Line 343: | Line 343: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 355: | Line 355: | ||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<syntaxhighlight lang="d">import std.algorithm; |
||
import std.exception : enforce; |
import std.exception : enforce; |
||
import std.math; |
import std.math; |
||
Line 443: | Line 443: | ||
output ~= pointList[end]; |
output ~= pointList[end]; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 456: | Line 456: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
{{trans|Yabasic}} |
{{trans|Yabasic}} |
||
< |
<syntaxhighlight lang="freebasic"> |
||
Function DistanciaPerpendicular(tabla() As Double, i As Integer, ini As Integer, fin As Integer) As Double |
Function DistanciaPerpendicular(tabla() As Double, i As Integer, ini As Integer, fin As Integer) As Double |
||
Dim As Double dx, dy, mag, pvx, pvy, pvdot, dsx, dsy, ax, ay |
Dim As Double dx, dy, mag, pvx, pvy, pvdot, dsx, dsy, ax, ay |
||
Line 518: | Line 518: | ||
Next i |
Next i |
||
Sleep |
Sleep |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 527: | Line 527: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 559: | Line 559: | ||
fmt.Println(RDP([]point{{0, 0}, {1, 0.1}, {2, -0.1}, |
fmt.Println(RDP([]point{{0, 0}, {1, 0.1}, {2, -0.1}, |
||
{3, 5}, {4, 6}, {5, 7}, {6, 8.1}, {7, 9}, {8, 9}, {9, 9}}, 1)) |
{3, 5}, {4, 6}, {5, 7}, {6, 8.1}, {7, 9}, {8, 9}, {9, 9}}, 1)) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 567: | Line 567: | ||
=={{header|J}}== |
=={{header|J}}== |
||
'''Solution:''' |
'''Solution:''' |
||
< |
<syntaxhighlight lang="j">mp=: +/ .* NB. matrix product |
||
norm=: +/&.:*: NB. vector norm |
norm=: +/&.:*: NB. vector norm |
||
normalize=: (% norm)^:(0 < norm) |
normalize=: (% norm)^:(0 < norm) |
||
Line 590: | Line 590: | ||
({. ,: {:) points |
({. ,: {:) points |
||
end. |
end. |
||
)</ |
)</syntaxhighlight> |
||
'''Example Usage:''' |
'''Example Usage:''' |
||
< |
<syntaxhighlight lang="j"> Points=: 0 0,1 0.1,2 _0.1,3 5,4 6,5 7,6 8.1,7 9,8 9,:9 9 |
||
1.0 rdp Points |
1.0 rdp Points |
||
0 0 |
0 0 |
||
Line 598: | Line 598: | ||
3 5 |
3 5 |
||
7 9 |
7 9 |
||
9 9</ |
9 9</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
{{works with|Java|9}} |
{{works with|Java|9}} |
||
< |
<syntaxhighlight lang="java">import javafx.util.Pair; |
||
import java.util.ArrayList; |
import java.util.ArrayList; |
||
Line 697: | Line 697: | ||
pointListOut.forEach(System.out::println); |
pointListOut.forEach(System.out::println); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Points remaining after simplification: |
<pre>Points remaining after simplification: |
||
Line 708: | Line 708: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang="javascript">/** |
|||
<lang JavaScript>/** |
|||
* @typedef {{ |
* @typedef {{ |
||
* x: (!number), |
* x: (!number), |
||
Line 752: | Line 752: | ||
{x: 9, y: 9}]; |
{x: 9, y: 9}]; |
||
console.log(RDP(points, 1));</ |
console.log(RDP(points, 1));</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>[{x: 0, y: 0}, |
<pre>[{x: 0, y: 0}, |
||
Line 764: | Line 764: | ||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<syntaxhighlight lang="julia">const Point = Vector{Float64} |
||
function perpdist(pt::Point, lnstart::Point, lnend::Point) |
function perpdist(pt::Point, lnstart::Point, lnend::Point) |
||
Line 805: | Line 805: | ||
plist = Point[[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]] |
plist = Point[[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]] |
||
@show plist |
@show plist |
||
@show rdp(plist)</ |
@show rdp(plist)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 813: | Line 813: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<syntaxhighlight lang="scala">// version 1.1.0 |
||
typealias Point = Pair<Double, Double> |
typealias Point = Pair<Double, Double> |
||
Line 888: | Line 888: | ||
println("Points remaining after simplification:") |
println("Points remaining after simplification:") |
||
for (p in pointListOut) println(p) |
for (p in pointListOut) println(p) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 901: | Line 901: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import math |
||
type |
type |
||
Line 938: | Line 938: | ||
var line: seq[Point] = @[(0.0, 0.0), (1.0, 0.1), (2.0, -0.1), (3.0, 5.0), (4.0, 6.0), |
var line: seq[Point] = @[(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)] |
(5.0, 7.0), (6.0, 8.1), (7.0, 9.0), (8.0, 9.0), (9.0, 9.0)] |
||
echo rdp(line, line.low, line.high)</ |
echo rdp(line, line.low, line.high)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 948: | Line 948: | ||
{{works with|Openscad|2019.05}} |
{{works with|Openscad|2019.05}} |
||
< |
<syntaxhighlight lang="openscad">function slice(a, v) = [ for (i = v) a[i] ]; |
||
// Find the distance from the point to the line |
// Find the distance from the point to the line |
||
Line 1,023: | Line 1,023: | ||
$fn=16; |
$fn=16; |
||
points = [[0,0], [1,0.1], [2,-0.1], [3,5], [4,6], [5,7], [6,8.1], [7,9], [8,9], [9,9]]; |
points = [[0,0], [1,0.1], [2,-0.1], [3,5], [4,6], [5,7], [6,8.1], [7,9], [8,9], [9,9]]; |
||
demo(points);</ |
demo(points);</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,030: | Line 1,030: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use feature 'say'; |
use feature 'say'; |
||
Line 1,073: | Line 1,073: | ||
say '(' . join(' ', @$_) . ') ' |
say '(' . join(' ', @$_) . ') ' |
||
for Ramer_Douglas_Peucker( [0,0],[1,0.1],[2,-0.1],[3,5],[4,6],[5,7],[6,8.1],[7,9],[8,9],[9,9] )</ |
for Ramer_Douglas_Peucker( [0,0],[1,0.1],[2,-0.1],[3,5],[4,6],[5,7],[6,8.1],[7,9],[8,9],[9,9] )</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>(0 0) |
<pre>(0 0) |
||
Line 1,083: | Line 1,083: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">rdp</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">e</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">rdp</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">e</span><span style="color: #0000FF;">)</span> |
||
Line 1,110: | Line 1,110: | ||
<span style="color: #0000FF;">{</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8.1</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">}}</span> |
<span style="color: #0000FF;">{</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8.1</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">},</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">}}</span> |
||
<span style="color: #0000FF;">?</span><span style="color: #000000;">rdp</span><span style="color: #0000FF;">(</span><span style="color: #000000;">points</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> |
<span style="color: #0000FF;">?</span><span style="color: #000000;">rdp</span><span style="color: #0000FF;">(</span><span style="color: #000000;">points</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,118: | Line 1,118: | ||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<syntaxhighlight lang="php">function perpendicular_distance(array $pt, array $line) { |
||
// Calculate the normalized delta x and y of the line. |
// Calculate the normalized delta x and y of the line. |
||
$dx = $line[1][0] - $line[0][0]; |
$dx = $line[1][0] - $line[0][0]; |
||
Line 1,190: | Line 1,190: | ||
foreach ($result as $point) { |
foreach ($result as $point) { |
||
print $point[0] . ',' . $point[1] . "\n"; |
print $point[0] . ',' . $point[1] . "\n"; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,205: | Line 1,205: | ||
{{libheader|Shapely}} |
{{libheader|Shapely}} |
||
An approach using the shapely library: |
An approach using the shapely library: |
||
< |
<syntaxhighlight lang="python">from __future__ import print_function |
||
from shapely.geometry import LineString |
from shapely.geometry import LineString |
||
if __name__=="__main__": |
if __name__=="__main__": |
||
line = LineString([(0,0),(1,0.1),(2,-0.1),(3,5),(4,6),(5,7),(6,8.1),(7,9),(8,9),(9,9)]) |
line = LineString([(0,0),(1,0.1),(2,-0.1),(3,5),(4,6),(5,7),(6,8.1),(7,9),(8,9),(9,9)]) |
||
print (line.simplify(1.0, preserve_topology=False))</ |
print (line.simplify(1.0, preserve_topology=False))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>LINESTRING (0 0, 2 -0.1, 3 5, 7 9, 9 9)</pre> |
<pre>LINESTRING (0 0, 2 -0.1, 3 5, 7 9, 9 9)</pre> |
||
Line 1,216: | Line 1,216: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
(require math/flonum) |
(require math/flonum) |
||
;; points are lists of x y (maybe extensible to z) |
;; points are lists of x y (maybe extensible to z) |
||
Line 1,260: | Line 1,260: | ||
(module+ test |
(module+ test |
||
(require rackunit) |
(require rackunit) |
||
(check-= ((⊥-distance '(0 0) '(0 1)) '(1 0)) 1 epsilon.0))</ |
(check-= ((⊥-distance '(0 0) '(0 1)) '(1 0)) 1 epsilon.0))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,270: | Line 1,270: | ||
{{trans|C++}} |
{{trans|C++}} |
||
<lang |
<syntaxhighlight lang="raku" line>sub norm (*@list) { @list»².sum.sqrt } |
||
sub perpendicular-distance (@start, @end where @end !eqv @start, @point) { |
sub perpendicular-distance (@start, @end where @end !eqv @start, @point) { |
||
Line 1,294: | Line 1,294: | ||
say Ramer-Douglas-Peucker( |
say Ramer-Douglas-Peucker( |
||
[(0,0),(1,0.1),(2,-0.1),(3,5),(4,6),(5,7),(6,8.1),(7,9),(8,9),(9,9)] |
[(0,0),(1,0.1),(2,-0.1),(3,5),(4,6),(5,7),(6,8.1),(7,9),(8,9),(9,9)] |
||
);</ |
);</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>((0 0) (2 -0.1) (3 5) (7 9) (9 9))</pre> |
<pre>((0 0) (2 -0.1) (3 5) (7 9) (9 9))</pre> |
||
Line 1,301: | Line 1,301: | ||
The computation for the ''perpendicular distance'' was taken from |
The computation for the ''perpendicular distance'' was taken from |
||
the '''GO''' example. |
the '''GO''' example. |
||
< |
<syntaxhighlight lang="rexx">/*REXX program uses the Ramer─Douglas─Peucker (RDP) line simplification algorithm for*/ |
||
/*───────────────────────────── reducing the number of points used to define its shape. */ |
/*───────────────────────────── reducing the number of points used to define its shape. */ |
||
parse arg epsilon pts /*obtain optional arguments from the CL*/ |
parse arg epsilon pts /*obtain optional arguments from the CL*/ |
||
Line 1,331: | Line 1,331: | ||
return subword(r, 1, words(r) - 1) RDP( reb(idx, #) ) |
return subword(r, 1, words(r) - 1) RDP( reb(idx, #) ) |
||
end |
end |
||
return @.1 @.#</ |
return @.1 @.#</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 1,341: | Line 1,341: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
===An implementation of the algorithm=== |
===An implementation of the algorithm=== |
||
< |
<syntaxhighlight lang="rust">#[derive(Copy, Clone)] |
||
struct Point { |
struct Point { |
||
x: f64, |
x: f64, |
||
Line 1,409: | Line 1,409: | ||
println!("{}", p); |
println!("{}", p); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,423: | Line 1,423: | ||
The geo crate contains an implementation of the Ramer-Douglas-Peucker line |
The geo crate contains an implementation of the Ramer-Douglas-Peucker line |
||
simplification algorithm. |
simplification algorithm. |
||
< |
<syntaxhighlight lang="rust">// [dependencies] |
||
// geo = "0.14" |
// geo = "0.14" |
||
Line 1,445: | Line 1,445: | ||
println!("({}, {})", p.x, p.y); |
println!("({}, {})", p.x, p.y); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,458: | Line 1,458: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="ruby">func perpendicular_distance(Arr start, Arr end, Arr point) { |
||
((point == start) || (point == end)) && return 0 |
((point == start) || (point == end)) && return 0 |
||
var (Δx, Δy ) = ( end »-« start)... |
var (Δx, Δy ) = ( end »-« start)... |
||
Line 1,485: | Line 1,485: | ||
say Ramer_Douglas_Peucker( |
say Ramer_Douglas_Peucker( |
||
[[0,0],[1,0.1],[2,-0.1],[3,5],[4,6],[5,7],[6,8.1],[7,9],[8,9],[9,9]] |
[[0,0],[1,0.1],[2,-0.1],[3,5],[4,6],[5,7],[6,8.1],[7,9],[8,9],[9,9]] |
||
)</ |
)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,492: | Line 1,492: | ||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang="swift">struct Point: CustomStringConvertible { |
||
let x: Double, y: Double |
let x: Double, y: Double |
||
Line 1,550: | Line 1,550: | ||
Point(x: 9.0, y: 9.0) |
Point(x: 9.0, y: 9.0) |
||
] |
] |
||
print("\(ramerDouglasPeucker(points: points, epsilon: 1.0))")</ |
print("\(ramerDouglasPeucker(points: points, epsilon: 1.0))")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,560: | Line 1,560: | ||
{{trans|Go}} |
{{trans|Go}} |
||
{{libheader|Wren-dynamic}} |
{{libheader|Wren-dynamic}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/dynamic" for Tuple |
||
var Point = Tuple.create("Point", ["x", "y"]) |
var Point = Tuple.create("Point", ["x", "y"]) |
||
Line 1,591: | Line 1,591: | ||
Point.new(5, 7), Point.new(6, 8.1), Point.new(7, 9), Point.new(8, 9), Point.new(9, 9) |
Point.new(5, 7), Point.new(6, 8.1), Point.new(7, 9), Point.new(8, 9), Point.new(9, 9) |
||
] |
] |
||
System.print(rdp.call(points, 1))</ |
System.print(rdp.call(points, 1))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,599: | Line 1,599: | ||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
< |
<syntaxhighlight lang="yabasic">sub perpendicularDistance(tabla(), i, ini, fin) |
||
local dx, cy, mag, pvx, pvy, pvdot, dsx, dsy, ax, ay |
local dx, cy, mag, pvx, pvy, pvdot, dsx, dsy, ax, ay |
||
Line 1,658: | Line 1,658: | ||
for i = 1 to 10 |
for i = 1 to 10 |
||
if matriz(i, 3) print matriz(i, 1), matriz(i, 2) |
if matriz(i, 3) print matriz(i, 1), matriz(i, 2) |
||
next</ |
next</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="zkl">fcn perpendicularDistance(start,end, point){ // all are tuples: (x,y) -->|d| |
||
dx,dy := end .zipWith('-,start); // deltas |
dx,dy := end .zipWith('-,start); // deltas |
||
dpx,dpy := point.zipWith('-,start); |
dpx,dpy := point.zipWith('-,start); |
||
Line 1,680: | Line 1,680: | ||
RamerDouglasPeucker(points[index,*],epsilon))) |
RamerDouglasPeucker(points[index,*],epsilon))) |
||
} else return(points[0],points[-1]); |
} else return(points[0],points[-1]); |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang="zkl">RamerDouglasPeucker( |
||
T( T(0.0, 0.0), T(1.0, 0.1), T(2.0, -0.1), T(3.0, 5.0), T(4.0, 6.0), |
T( T(0.0, 0.0), T(1.0, 0.1), T(2.0, -0.1), T(3.0, 5.0), T(4.0, 6.0), |
||
T(5.0, 7.0), T(6.0, 8.1), T(7.0, 9.0), T(8.0, 9.0), T(9.0, 9.0) )) |
T(5.0, 7.0), T(6.0, 8.1), T(7.0, 9.0), T(8.0, 9.0), T(9.0, 9.0) )) |
||
.println();</ |
.println();</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |