Anonymous user
Ramer-Douglas-Peucker line simplification: Difference between revisions
Ramer-Douglas-Peucker line simplification (view source)
Revision as of 17:20, 9 July 2020
, 3 years ago→{{header|REXX}}: changed whitespace, simplified some code.
m (Fixed spelling error) |
m (→{{header|REXX}}: changed whitespace, simplified some code.) |
||
Line 1,186:
=={{header|REXX}}==
The computation for the ''perpendicular distance'' was taken from
the '''GO''' example.
<lang rexx>/*REXX program uses the Ramer─Douglas─Peucker (RDP) line simplification algorithm for*/
/*───────────────────────────── reducing the number of points used to define its shape. */
Line 1,193 ⟶ 1,194:
if pts='' then pts= '(0,0) (1,0.1) (2,-0.1) (3,5) (4,6) (5,7) (6,8.1) (7,9) (8,9) (9,9)'
pts= space(pts) /*elide all superfluous blanks. */
$= RDP(pts) /*invoke Ramer─Douglas─Peucker function*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 1,202 ⟶ 1,203:
px: parse arg _; return word( translate(_, , ','), 1) /*obtain the X coörd.*/
py: parse arg _; return word( translate(_, , ','), 2) /* " " Y " */
reb: parse arg a,b,,_; do k=a to b;
rez: parse arg z,_; do k=1 for words(z); _= _ '('word(z, k)") "; end; return strip(_)
/*──────────────────────────────────────────────────────────────────────────────────────*/
RDP: procedure expose epsilon;
L= px(@.#) - px(@.1)
H= py(@.#) - py(@.1)
do i=2 to #-1
d= abs(H*px(@.i) - L*py(@.i) + px(@.#)*py(@.1) - py(@.#)*px(@.1)
if d>dMax then do; idx= i; dMax= d
end
end /*i*/
if dMax>epsilon then do; r= RDP( reb(1, idx) )
|