TrajSplitAtFirstCrossing | R Documentation |
This is basically a wrapper around TrajInPolygon
and
TrajSplit
.
TrajSplitAtFirstCrossing(trj, boundary)
trj |
The trajectory to split. |
boundary |
A polygon defining the boundary. Can be any structure that
|
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
.
TrajInPolygon
, TrajSplit
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.