R/rotate_points.R

Defines functions rotate_points

Documented in rotate_points

#' Rotate points about
#'
#' @description take a set of and rotate it in degrees
#'
#' @param data a data.frame
#' @param x column with x coordinates
#' @param y column with y coordinates
#' @param deg the degree to rotate the points
#' @param cx the x coordinate to rotate around
#' @param cy the y coordinate to rotate around
#'
#' @return a data.frame
#'
#' @export

rotate_points <- function(data, x,y, deg = 0, cx=0, cy=0){
  rad <- deg*pi/180
  data %>%
    dplyr::mutate(
      {{x}} := cx + ({{x}} - cx) * cos(rad) - ({{y}} - cy) * sin(rad),
      {{y}} := cy + ({{y}} - cy) * cos(rad) + ({{x}} - cx) * sin(rad)
    )
}
delabj/delabjGenArt documentation built on Jan. 25, 2022, 3:45 a.m.