% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/internal.R
\name{diff_rad}
\alias{diff_rad}
\title{Difference of two angles measured in radians}
\usage{
diff_rad(x, y, signed = FALSE, return_units = FALSE)
}
\arguments{
\item{x}{angle in radians}

\item{y}{angle in radians}

\item{signed}{logical if signed difference should be returned, default FALSE}

\item{return_units}{return difference with units = 'rad'}
}
\value{
Difference between x and y in radians. If signed is TRUE, the signed
difference is returned. If signed is FALSE, the absolute difference is
returned. Note: The difference is the smallest difference, eg. the
difference between 2 rad and -2.5 rad is 1.78.
}
\description{
\strong{Internal function} - not developed to be used outside of spatsoc functions
}
\examples{
# Load data.table, units
library(data.table)
library(units)
\dontshow{data.table::setDTthreads(1)}

# Read example data
DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc"))

# Cast the character column to POSIXct
DT[, datetime := as.POSIXct(datetime, tz = 'UTC')]

# Set order using data.table::setorder
setorder(DT, datetime)

# Calculate direction
direction_step(
  DT = DT,
  id = 'ID',
  coords = c('X', 'Y'),
  crs = 32736
)

# Differences
spatsoc:::diff_rad(DT[1, direction], DT[2, direction])

# Note smallest difference returned
spatsoc:::diff_rad(as_units(2, 'rad'), as_units(-2.5, 'rad'))
}
\references{
adapted from https://stackoverflow.com/a/7869457
}
\keyword{internal}
