Skip to contents

Make degrees angles into clockwise arc

Usage

make_degrees_clockwise(x)

Arguments

x

numeric vector of degree angles.

Value

data.frame with three columns:

  • 'x': the numeric vector of degrees, sorted in increasing order, with values adjusted so that the difference between angle is positive, and has consistent numeric difference. When the arc crosses zero, the first angle will therefore be negative.

  • 'idx': the integer index position of input degrees, which may be used as the equivalent of order().

  • 'xdiff': the numeric difference between each degree angle, and the next angle in the sequence. The last value should always be the largest, representing the gap between the end of the arc, and the start of the arc.

Details

The purpose is very specific, it takes a vector of degree angles, determines the correct sequence of angles to constitute the proper arc. A proper arc is defined as a series of points where there is only one "largest gap" and this gap represents the open space. When the arc crosses zero, angles are shifted to negative values so that the numeric difference between each angle is consistent.

For this purpose, "clockwise" is defined "increasing numeric order".

The assumption is that values in x only represent one contiguous arc, that does not loop around itself, and therefore that values in x may be provided in any order. Values returned will be sorted to start with the first angle in the series, so that the last angle in the series is positive and less than 360. If the arc crosses zero, the first value in the series will be negative.

Examples

x <- c(355, 5, 10, 350, 15, 20)
make_degrees_clockwise(x)
#>     x idx xdiff
#> 4 -10   4     5
#> 1  -5   1    10
#> 2   5   2     5
#> 3  10   3     5
#> 5  15   5     5
#> 6  20   6   330

# re-order the original angles
x[make_degrees_clockwise(x)$idx]
#> [1] 350 355   5  10  15  20

make_degrees_clockwise(c(100, 200))
#>     x idx xdiff
#> 1 100   1   100
#> 2 200   2   260
make_degrees_clockwise(c(200, 100, 300) + 110)
#>      x idx xdiff
#> 2 -150   2   100
#> 1  -50   1   100
#> 3   50   3   160