# 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")
  }  
Run the code above in your browser using DataLab