Get angle from origin to vector of x,y coordinates

xyAngle(
  x,
  y = NULL,
  directed = FALSE,
  deg = TRUE,
  origin.x = 0,
  origin.y = 0,
  ...
)

Arguments

x

numeric vector or two-column matrix with columns representing x,y coordinates when y is NULL.

y

numeric vector or NULL.

directed

logical indicating whether to return angles around the full circle, or only half circle. For example, in degrees c(1,1) indicates 45 degrees, c(-1,-1) indicates -135 degrees. When directed=FALSE then c(-1,-1) indicates 45 degrees.

deg

logical indicating whether to return degrees, or when deg=FALSE it returns radians.

origin.x, origin.y

numeric input defining the coordinates to use as the origin. When non-zero it implies the first point of each segment.

...

additional arguments are ignored.

Details

This function gets the angle from origin to x,y coordinates, allowing for vectorized input and output.

Examples

# by default output is in degrees
xyAngle(1, 1);
#> [1] 45

# output in radians
xyAngle(1, 1, deg=FALSE);
#> [1] 0.7853982

# optionally different origin
xyAngle(1, 1, origin.x=1, origin.y=0);
#> [1] 90