Given a data frames containing tracking information for a particle, this function returns a vector containing the value of turning angle along the considered tracklet.
Usage
turnAngle(
df,
timeCol = "frame",
unit = c("radians", "degrees"),
compass = NULL,
scale = 1
)
Arguments
- df
A data frame containing x, y coordinates columns named "x.pos", "y.pos" for a given tracklet.
- timeCol
A character string corresponding to the name of the column containing Time information (default = 'frame').
- unit
A character string indicating whether the function should returns turning angle in radians or degrees (default = "radians").
- compass
A value used to specify the compass direction (in radians). If not NULL, turning angles are calculated for a directed walk, otherwise, a random walk is assumed (default = NULL).
- scale
A ratio corresponding to the scaling factor to be applied to the trajectory coordinates (e.g., size in cm / size in pixels; see
TrajScale, default = 1
.
Examples
set.seed(2023)
# generate a dummy tracklet
## start to specify some parameters to generate the tracklet
TrackL <-
100 # the length of the tracklet or a sequence to randomly sample tracklet's length
TrackDatTemp <-
trajr::TrajGenerate(sample(TrackL, 1), random = TRUE, fps = 1)
TrackDat <-
data.frame(
x.pos = TrackDatTemp[["x"]] - min(TrackDatTemp[["x"]]),
y.pos = TrackDatTemp[["y"]] - min(TrackDatTemp[["y"]]),
frame = TrackDatTemp[["time"]]
)
# compute the turning angle over the particle's trajectory
MoveR::turnAngle(TrackDat,
timeCol = "frame",
unit = "radians",
scale = 1)
#> [1] NA -0.937533661 -0.093072330 -0.316742849 0.545398732
#> [6] -0.456863637 0.500819856 -0.199633302 -0.234061527 0.163481041
#> [11] -0.206373449 0.281018235 0.331679130 -0.301448642 0.349188844
#> [16] 0.297923225 0.226045913 0.448371980 0.286108257 -0.205826507
#> [21] -0.147163573 0.609286979 0.122055713 -0.222575979 -0.923901822
#> [26] -0.314412653 -0.430540346 0.757460149 1.367619466 -0.137438532
#> [31] 0.638327033 -0.405490172 -0.022461388 -0.319706188 -0.219177998
#> [36] 0.253601101 0.564609599 0.487818826 -0.062301897 0.214168290
#> [41] 0.209363180 0.217733244 -0.102131047 0.151176746 0.347178899
#> [46] 1.186532832 0.537985143 0.167692388 0.376714117 0.332193139
#> [51] -0.545441328 -0.211385425 0.591701020 0.792413395 1.140427685
#> [56] -1.032728525 -0.204055985 0.150507283 0.348306539 0.494091934
#> [61] -0.142031617 -0.961133734 -0.586859900 0.522141372 -0.066464051
#> [66] 0.422438521 -0.185796274 0.523791926 0.462707839 -0.739302666
#> [71] -0.461317470 -0.042451219 -0.433255022 0.337521181 -0.040352453
#> [76] -0.062796305 -0.194165543 0.008413697 -0.563153295 0.109175906
#> [81] NA