Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

inside.owin

Test Whether Points Are Inside A Window


Description

Test whether points lie inside or outside a given window.

Usage

inside.owin(x, y, w)

Arguments

x

Vector of x coordinates of points to be tested. (Alternatively, a point pattern object providing both x and y coordinates.)

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().

Details

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.

Normally x and y must be numeric vectors of equal length (length zero is allowed) containing the coordinates of points. Alternatively x can be a point pattern (object of class "ppp") while y is missing; then the coordinates of the point pattern are extracted.

Value

Logical vector whose ith entry is TRUE if the corresponding point (x[i],y[i]) is inside w.

Author(s)

and Rolf Turner r.turner@auckland.ac.nz

See Also

Examples

# 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))
  if(human <- interactive()) {
  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)

  if(human) {
  points(x[ok], y[ok])
  points(x[!ok], y[!ok], pch="x")
  }

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.