diff_rad: Difference of two angles measured in radians

View source: R/internal.R

diff_radR Documentation

Difference of two angles measured in radians

Description

Internal function

Usage

diff_rad(x, y, signed = FALSE, return_units = FALSE)

Arguments

x

angle in radians

y

angle in radians

signed

boolean if signed difference should be returned, default FALSE

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.

References

adapted from https://stackoverflow.com/a/7869457

Examples

# Load data.table
library(data.table)


# 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'),
  projection = 32736
)

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

ropensci/spatsoc documentation built on Feb. 12, 2025, 7:16 a.m.