# R/anglecheck.R In monogeneaGM: Geometric Morphometric Analysis of Monogenean Anchors

#### Documented in anglecheck

```#' Angle swept by a ray
#'
#' This function computes angle swept by a ray in anti-clockwise direction.
#' The ray starts at the half-line pointing towards the positive x direction,
#' and passes through the origin and a point defined by the user.
#' @param x a vector of length 2 giving the xy-coordinates of the point defined by the user
#' @author Tsung Fei Khang \email{tfkhang@@um.edu.my}
#' @references Khang TF, Soo OYM, Tan WB, Lim LHS. (2016). Monogenean anchor morphometry: systematic value, phylogenetic signal, and evolution. PeerJ 4:e1668.
#' @examples
#'

if(x[1] == 0 & x[2] == 0) return(0)

theta <- atan(abs(x[2])/abs(x[1]))

theta2 <- (sign(x[1])==1)*(sign(x[2])==1)*theta +
(sign(x[1])==-1)*(sign(x[2])==1)*(pi-theta) +
(sign(x[1])==-1)*(sign(x[2])==-1)*(pi+theta) +
(sign(x[1])==1)*(sign(x[2])==-1)*(2*pi-theta) +
(x[1] == 0) * sign(x[2] > 0) * pi/2 +
(x[1] == 0) * sign(x[2] < 0) * 3*pi/2 +
(x[1] > 0) * sign(x[2] == 0) * 0 +
(x[1] < 0) * sign(x[2] == 0) * pi