| TrajSplitAtFirstCrossing {trajr} | R Documentation |
Split a trajectory into two parts, separated at the first boundary crossing
Description
This is basically a wrapper around TrajInPolygon and
TrajSplit.
Usage
TrajSplitAtFirstCrossing(trj, boundary)
Arguments
trj |
The trajectory to split. |
boundary |
A polygon defining the boundary. Can be any structure that
|
Value
A list with 1 or 2 elements. If trj lies entirely inside or
outside boundary, then the list simply contains trj. If
trj crosses the boundary, then the list contains 2 trajectories. The
first is the longest part of trj that lies entirely inside or
outside boundary, and the second is the remainder of trj.
See Also
Examples
# Square arena
boundary <- data.frame(x = c(-10, 10, 10, -10), y = c(-10, -10, 10, 10))
# Generate a random trajectory
set.seed(1)
trj <- TrajGenerate(n = 8, stepLength = 3, angularErrorSd = .4)
# Split the trajectory where it crosses the boundary
l <- TrajSplitAtFirstCrossing(trj, boundary)
# Plot the boundary and the two trajectories
plot(NULL, xlim = range(c(boundary$x, trj$x)), ylim = range(c(boundary$y, trj$y)), asp = 1)
polygon(boundary, border = "brown", lwd = 2)
lines(l[[1]], col = "#2040ff80", lwd = 3)
lines(l[[2]], col = "#ff204080", lwd = 3)
[Package trajr version 1.5.1 Index]