Skip to contents

angle() creates angle vectors with user specified angular unit. around as_angle() for those angular units.

Usage

angle(x = numeric(), unit = getOption("affiner_angular_unit", "degrees"))

degrees(x)

gradians(x)

pi_radians(x)

radians(x)

turns(x)

Arguments

x

An angle vector or an object to convert to it (such as a numeric vector)

unit

A string of the desired angular unit. Supports the following strings (note we ignore any punctuation and space characters as well as any trailing s's e.g. "half turns" will be treated as equivalent to "halfturn"):

  • "deg" or "degree"

  • "half-revolution", "half-turn", or "pi-radian"

  • "gon", "grad", "grade", or "gradian"

  • "rad" or "radian"

  • "rev", "revolution", "tr", or "turn"

Value

A numeric vector of class "angle". Its "unit" attribute is a standardized string of the specified angular unit.

See also

as_angle(), angular_unit(), and angle-methods. https://en.wikipedia.org/wiki/Angle#Units for more information about angular units.

Examples

  # Different representations of the "same" angle
  angle(180, "degrees")
#> <angle<degrees>[1]>
#> [1] 180°
  angle(pi, "radians")
#> <angle<radians>[1]>
#> [1] 3.141593 rad
  angle(0.5, "turns")
#> <angle<turns>[1]>
#> [1] 0.5 tr
  angle(200, "gradians")
#> <angle<gradians>[1]>
#> [1] 200 gon
  pi_radians(1)
#> <angle<pi-radians>[1]>
#> [1] 1π rad

  a1 <- angle(180, "degrees")
  angular_unit(a1)
#> [1] "degrees"
  is_angle(a1)
#> [1] TRUE
  as.numeric(a1, "radians")
#> [1] 3.141593
  cos(a1)
#> [1] -1

  a2 <- as_angle(a1, "radians")
  angular_unit(a2)
#> [1] "radians"
  is_congruent(a1, a2)
#> [1] TRUE