R/calculate_vector_direction.R

Defines functions calculate_vector_direction

Documented in calculate_vector_direction

#' Front wave velocity direction
#'
#'  Determines the direction of a vector given magnitude in x and y direction
#' @param x The magnitude of a vector in x
#' @param y The magnitude of a vector in y
#' @export
calculate_vector_direction = function(x,y) {
  theta = 0
  for(i in 1:length(x))
    if ( (x[i] > 0) && (y[i] > 0) ) { theta[i] = atan( y[i]/x[i]) } 
  else if ( (x[i] > 0) && (y[i] < 0) ) { theta[i] = 2*pi + atan( y[i]/x[i]) } 
  else if ( (x[i] < 0) && (y[i] < 0) ) { theta[i] = pi + atan( y[i]/x[i]) } 
  else if ( (x[i] < 0) && (y[i] > 0) ) { theta[i] = pi + atan( y[i]/x[i]) } 
  else (theta[i] = NA)
  return(theta)
}
kathryntmorrison/outbreakvelocity documentation built on May 20, 2019, 7:41 a.m.