Rotation angle of two speed vector

cal_angle(v1, v2, clockwise = -1)

cal_azimuth(v, refer = c(0, 1))

Arguments

v1, v2

speed vector, in deg, (lon, lat).

  • v1 is the previous time.

  • v2 is the current time;

clockwise

one of c(-1, 1): -clockwise = -1: clockwise corresponds to negative angle -clockwise = 1: clockwise corresponds to positive angle (azimuth angle in this style)

Value

v2 -> v1:

  • rotation angle (in deg, [-180, 180])

    • counterclockwise is positive

    • clockwise is negative

  • azimuth angle (in deg, [-180, 180])

    • the angle with north (c(0, 1))

Examples

cal_angle(c(1, 0), c(2, 0)) # == 0
#> [1] 0
cal_angle(c(0, 1), c(0, 2)) # == 0
#> [1] 0

p1 <- c(1, 0)
p2 <- c(0, 1)

cal_angle(p1, p2) # == 90, counterclockwise
#> [1] 90
cal_angle(p2, p1) # == -90, clockwise
#> [1] -90