Skip to contents

Monotonicity describes the property that values along a line is ever increasing or decreasing, i.e. f(x) > f(x + 1) || f(x) < f(x + 1). The weak version allows equality as well, i.e. f(x) >= f(x + 1) || f(x) <= f(x + 1).

Usage

is_monotone(x, dim = "both")

is_weakly_monotone(x, dim = "x")

is_selfintersecting(x)

Arguments

x

A polyclid_polyline vector

dim

Either "x" or "y" to indicate in which dimension to test monotonicity in

Value

A logical vector with the same length as x

Details

If a polyline is not at least weakly monotone in one dimension there is a chance that it intersects with itself. This can be queried by is_selfintersecting().

Examples

sine <- polyline(
  seq(0, 2*pi, length.out = 20),
  sin(seq(0, 2*pi, length.out = 20))
)
is_monotone(sine, "x")
#> [1] TRUE
is_monotone(sine, "y")
#> [1] FALSE

poly <- polyline(
  c(0, 1, 1, 2),
  c(0, 1, 2, 3)
)

is_monotone(sine, "x")
#> [1] TRUE
is_weakly_monotone(sine, "x")
#> [1] TRUE