Skip to contents

Spread angles to minimum degrees difference

Usage

spread_degrees(
  degrees,
  min_degrees = 10,
  iteration = 1,
  max_iterations = 20,
  verbose = FALSE,
  ...
)

Arguments

degrees

numeric vector of angles in degrees, expected to range from 0 to 360. Values are fit to the range c(0, 360) using degrees %% 360.

min_degrees

numeric indicating the minimum angle in degrees to allow between adjacent angles.

...

additional arguments are ignored.

Details

The function takes a vector of angles in degrees, and adjusts any angles with adjacent angle below a minimum angle min_degrees until the minimum angle is min_degrees. If all input angles fit this criteria, it is returned unchanged, otherwise it will adjust angles then iteratively call itself until the condition is met.

If all angles are less the min_degrees degrees from the nearest adjacent angle, then all angles are equally spaced around 360 degrees.

Examples

degrees <- c(5, 10, 15, 100, 105, 110, 200, 300, 358);
degrees
#> [1]   5  10  15 100 105 110 200 300 358
spread_degrees(degrees);
#> [1]   2  12  22  95 105 115 200 300  -8

degrees2 <- sample(degrees);
degrees2
#> [1] 200  15 358 110  10 300   5 100 105
spread_degrees(degrees2);
#> [1] 200  22  -8 115  12 300   2  95 105