Skip to contents

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.

Usage

curve_simplify(
  x,
  y,
  method = "rdp",
  tolerance = NULL,
  num_to_keep = NULL,
  look_ahead = NULL,
  order_x = "ascending",
  order_y = "ascending",
  strict_x = TRUE,
  strict_y = TRUE
)

Arguments

x, y

numeric vectors of equal length (at least two), the curve's ordinates.

method

one of "rdp" (default), "visvalingam", or "lang".

tolerance

perpendicular-distance tolerance; required for method "rdp" or "lang".

num_to_keep

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).

look_ahead

the Lang algorithm's look-ahead window; required for method = "lang".

order_x, order_y

one of "ascending" (default), "descending", or "none".

strict_x, strict_y

require x/y to strictly increase/decrease (per order_x/order_y) between consecutive ordinates. Default TRUE.

Value

a data frame with columns x and y.

Examples

x <- c(0, 1.57, 3.14, 4.71, 6.28)
y <- c(0, 1, 0, -1, 0)
curve_simplify(x, y, method = "rdp", tolerance = 0.01, strict_y = FALSE, order_y = "none")
#>      x  y
#> 1 0.00  0
#> 2 1.57  1
#> 3 4.71 -1
#> 4 6.28  0