polykin.math¤
simplify_polyline ¤
simplify_polyline(
points: FloatMatrix, tol: float
) -> FloatMatrix
Simplify an N-dimensional polyline using the Ramer-Douglas-Peucker algorithm.
The Ramer-Douglas-Peucker algorithm is considered the best global polyline simplification algorithm. This particular implementation is based on the recursive version of the method.
References
- Ramer, Urs. "An iterative procedure for the polygonal approximation of plane curves." Computer graphics and image processing 1.3 (1972): 244-256.
- Douglas, David H., and Thomas K. Peucker. "Algorithms for the reduction of the number of points required to represent a digitized line or its caricature." Cartographica: the international journal for geographic information and geovisualization 10.2 (1973): 112-122.
PARAMETER | DESCRIPTION |
---|---|
points
|
Matrix of point coordinates.
TYPE:
|
tol
|
Point-to-edge distance tolerance. Points closer than
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
FloatMatrix
|
Simplified polyline. |
Examples:
Simplify a 2D polyline.
>>> from polykin.math import simplify_polyline
>>> p = np.array([[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]])
>>> simplify_polyline(p, tol=1.0)
array([[ 0. , 0. ],
[ 2. , -0.1],
[ 3. , 5. ],
[ 7. , 9. ],
[ 9. , 9. ]])
Source code in src/polykin/math/filters.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|