R/arch-spiral.R

Defines functions arch_spiral

Documented in arch_spiral

#' Get coordination of spiral curve
#' @param theta a numeric vector of radius.
#' @param a,b scalar numeric value that control the shape of the spiral curve.
#' @param clockwise logical, direction of rotation of the spiral curve.
#' @rdname arch_spiral
#' @examples
#' arch_spiral(seq(0, 2 * pi, length.out = 200))
#' arch_spiral(seq(0, 2 * pi, length.out = 200), clockwise = TRUE)
#' @author Houyun Huang
#' @export
arch_spiral <- function(theta, a = 0.2, b = 0.1, clockwise = FALSE) {
  t <- (a + b * theta)
  if(identical(clockwise, TRUE)) {
    x <- t * sin(theta)
    y <- t * cos(theta)
  } else {
    x <- t * cos(theta)
    y <- t * sin(theta)
  }
  angle <- if(clockwise) {
    (atan2(y, x) * 180 / pi) %% 360
  } else {
    (theta * 180 / pi) %% 360
  }

  data.frame(x = x,
             y = y,
             angle = angle)
}
houyunhuang/archncov documentation built on April 2, 2020, 9:41 p.m.