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