Reverses the discontinuity introduced by wrapping, by accumulating the
shortest step between successive angles. A heading that crosses 2*pi
therefore continues to increase rather than jumping back to zero, which is
what makes it differentiable. NA values are preserved in place.
See also
Other angle utilities:
deg_to_rad(),
rad_to_deg(),
wrap_angle()
Examples
# A heading turning steadily past a full circle, wrapped to [0, 2*pi)
wrapped <- wrap_angle(seq(0, 3 * pi, length.out = 7), "2pi")
wrapped
#> [1] 0.000000 1.570796 3.141593 4.712389 0.000000 1.570796 3.141593
# Unwrapping restores the steady progression
unwrap_angle(wrapped)
#> [1] 0.000000 1.570796 3.141593 4.712389 6.283185 7.853982 9.424778