curve_simplify
curve_simplify(
x,
y,
method='rdp',
tolerance=None,
num_to_keep=None,
look_ahead=None,
order_x='ascending',
order_y='ascending',
strict_x=True,
strict_y=True,
)Simplify a paired x-y curve.
Mirrors the C# OrderedPairedData’s three curve-simplification algorithms: Douglas-Peucker (method="rdp", needs tolerance), Visvalingam-Whyatt (method="visvalingam", needs num_to_keep), and Lang (method="lang", needs tolerance and look_ahead). NOTE: unlike rdp/visvalingam, which always keep the curve’s first and last point, lang does not force-keep the trailing point – a real, verified-against-the-real-C#-library upstream behavior (see ordered_paired_data.hpp’s sixth transcription note), not a port bug.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | array_like | Equal-length curve ordinates, at least two elements. | required |
| y | array_like | Equal-length curve ordinates, at least two elements. | required |
| method | ('rdp', 'visvalingam', 'lang') | "rdp" |
|
| tolerance | float | Perpendicular-distance tolerance; required for method "rdp" or "lang". |
None |
| num_to_keep | int | Number of points to keep; required for method="visvalingam", and must be at least 2 (the algorithm always keeps the curve’s first and last point, and needs at least 3 ordinates to triangulate at every intermediate step). |
None |
| look_ahead | int | The Lang algorithm’s look-ahead window; required for method="lang". |
None |
| order_x | ('ascending', 'descending', 'none') | "ascending" |
|
| order_y | ('ascending', 'descending', 'none') | "ascending" |
|
| strict_x | bool | True |
|
| strict_y | bool | True |
Returns
| Name | Type | Description |
|---|---|---|
| numpy.ndarray | An (n, 2) array with columns [x, y]. |
Examples
>>> from corehydropy import curve_simplify
>>> x = [0, 1.57, 3.14, 4.71, 6.28]
>>> y = [0, 1, 0, -1, 0]
>>> curve_simplify(x, y, method="rdp", tolerance=0.01, strict_y=False, order_y="none")
array([[ 0. , 0. ],
[ 1.57, 1. ],
[ 4.71, -1. ],
[ 6.28, 0. ]])