inside.owin {spatstat} | R Documentation |
Test whether points lie inside or outside a given window.
inside.owin(x, y, w)
x |
Vector of x coordinates of points to be tested. |
y |
Vector of y coordinates of points to be tested. |
w |
A window.
This should be an object of class owin ,
or can be given in any format acceptable to as.owin() .
|
This function tests whether each of the points
(x[i],y[i])
lies inside or outside
the window w
and returns TRUE
if it is inside.
The boundary of the window is treated as being inside.
If w
is of type "rectangle"
or
"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
precision accuracy.
If 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.
Logical vector whose i
th entry is
TRUE
if the corresponding point (x[i],y[i])
is inside w
.
Adrian Baddeley adrian@maths.uwa.edu.au http://www.maths.uwa.edu.au/~adrian/ and Rolf Turner rolf@math.unb.ca http://www.math.unb.ca/~rolf
# 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)) ## Not run: plot(mas) ## End(Not run) # random points in rectangle x <- runif(30,min=-1, max=1) y <- runif(30,min=-1, max=1) ok <- inside.owin(x, y, mas) ## Not run: points(x[ok], y[ok]) points(x[!ok], y[!ok], pch="x") ## End(Not run)