Calculate relative track turning angle on longitude, latitude input vectors. The unit of turn angle is degrees.

track_turn(x, y)

Arguments

x

longitude

y

latitude

Value

a numeric vector of absolute turn angles, in degrees

Details

By convention the last value is set to NA missing value, because the angle applies to the relative turn from the current location.

To use this on multiple track ids, use a grouped data frame with tidyverse code like data %>% group_by(id) %>% mutate(turn = track_turn(lon, lat)).

The maximum possible value is 180 degrees and the minimum is -180, although these particular values are a special case and will probably always be positive. Turn angle is a signed quantity with negative values for a left turn and positive values for a right turn.

Examples

track_turn(trips0$x, trips0$y)[1:10]
#>  [1]         NA  -60.99577 -175.45007 -167.27394  107.65275 -155.18283
#>  [7]   90.85982  -21.24632  156.01156 -115.82731

## maximum turn angle
track_turn(c(0, 0, 0), c(0, 1, 0))
#> [1]  NA 180  NA
## minimum turn angle
track_turn(c(0, 0, 0), c(0, 1, 2))
#> [1] NA  0 NA