TrajInPolygon: Test whether each of the points in a trajectory lie inside a...

View source: R/simulate.R

TrajInPolygonR Documentation

Test whether each of the points in a trajectory lie inside a polygon

Description

Simply a wrapper around point.in.polygon. The sp package must be installed for this function to be called. sp is not automatically installed as a dependency of trajr.

Usage

TrajInPolygon(trj, boundary)

Arguments

trj

Trajectory to test

boundary

A polygon defining the region to be tested against. Can be any structure that xy.coords can handle, such as a data frame with x and y columns.

Value

Integer array with a value for each point in the trajectory. Values are: 0: point is strictly exterior to boundary; 1: point is strictly interior to boundary; 2: point lies on the relative interior of an edge of boundary; 3: point is a vertex of boundary

See Also

point.in.polygon, xy.coords

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 = 10, stepLength = 2, angularErrorSd = .15)

# Test which points lie inside the boundary
print(TrajInPolygon(trj, boundary))
## [1] 1 1 1 1 1 1 0 0 0 0 0


trajr documentation built on May 29, 2024, 11:52 a.m.