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