Calculate internal track angle on longitude, latitude input vectors. The unit of angle is degrees.

track_angle(x, y)

Arguments

x

longitude

y

latitude

Value

a numeric vector of the relative internal angle between sequential locations in degrees, see Details

Details

By convention the first and last values are set to NA missing value, because the angle applies to the location between each previous and next location.

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

The maximum possible value is 180 and the minimum is 0.

Examples

track_angle(trips0$x, trips0$y)[1:10]
#>  [1]        NA 119.59007   4.42864  13.08789  72.38663  25.59564  89.52224
#>  [8] 159.23186  23.76860  64.29873

## maximum value
track_angle(c(0, 0, 0), c(0, 1, 2))
#> [1]  NA 180  NA
## minimum value
track_angle(c(0, 0, 0), c(0, 1, 0))
#> [1] NA  0 NA