Test Whether Points Are Inside A Window
Test whether points lie inside or outside a given window.
inside.owin(x, y, w)
This function tests whether each of the points
(x[i],y[i]) lies inside or outside
w and returns
TRUE if it is inside.
The boundary of the window is treated as being inside.
w is of type
"polygonal", the algorithm uses analytic geometry
(the discrete Stokes theorem).
Computation time is linear in the number of points
and (for polygonal windows) in the number of vertices of the
boundary polygon. Boundary cases are correct to single
w is of type
"mask" then the
pixel closest to
(x[i],y[i]) is tested. The
results may be incorrect for points lying within
one pixel diameter of the window boundary.
y must be numeric vectors of
equal length (length zero is allowed) containing the coordinates
of points. Alternatively
can be a point pattern (object of class
is missing; then the coordinates of the point pattern are extracted.
- Logical vector whose
ith entry is
TRUEif the corresponding point
# hexagonal window k <- 6 theta <- 2 * pi * (0:(k-1))/k co <- cos(theta) si <- sin(theta) mas <- owin(c(-1,1), c(-1,1), poly=list(x=co, y=si)) plot(mas) # random points in rectangle x <- runif(30,min=-1, max=1) y <- runif(30,min=-1, max=1) ok <- inside.owin(x, y, mas) points(x[ok], y[ok]) points(x[!ok], y[!ok], pch="x")