Wraps a vector of angles to a standard interval using modulo arithmetic.
Usage
wrap_angle(x, modulo = c("2pi", "pi", "asis"))Arguments
- x
A numeric vector of angles, in radians.
- modulo
A character string (default
"2pi") giving the target range:"2pi"Wrap to
[0, 2*pi)."pi"Wrap to
(-pi, pi]."asis"Return unchanged.
[0, 2pi)
.} \item{"pi"}{Wrap to(-pi, pi]: R:0,%202pi)%60.%7D%0A%20%20%5C%5Citem%7B%60%22pi%22%60%7D%7BWrap%20to%20%60(-pi,%20pi
See also
Other angle utilities:
deg_to_rad(),
rad_to_deg(),
unwrap_angle()
Examples
angles <- c(-pi, 0, pi, 2 * pi, 3 * pi)
wrap_angle(angles, "2pi")
#> [1] 3.141593 0.000000 3.141593 0.000000 3.141593
# The same angles on the signed interval
wrap_angle(angles, "pi")
#> [1] 3.141593 0.000000 3.141593 0.000000 3.141593
# "asis" is a no-op, useful when the range is chosen by a caller
wrap_angle(angles, "asis")
#> [1] -3.141593 0.000000 3.141593 6.283185 9.424778