runifpoint(n, win=owin(c(0,1),c(0,1)), giveup=1000)
"owin"
or something acceptable to as.owin
."ppp"
).n
independent random points,
uniformly distributed in the window win
.
(For nonuniform distributions, see rpoint
.)The algorithm depends on the type of window, as follows:
win
is a rectangle then$n$independent random points, uniformly distributed
in the rectangle, are generated by assigning uniform random values to their
cartesian coordinates.win
is a binary image mask, then a random sequence of
pixels is selected (usingsample
)
with equal probabilities. Then for each pixel in the sequence
we generate a uniformly distributed random point in that pixel.win
is a polygonal window, the algorithm uses the rejection
method. It finds a rectangle enclosing the window,
generates points in this rectangle, and tests whether they fall in
the desired window. It gives up whengiveup * n
tests
have been performed without yieldingn
successes.ppp.object
,
owin.object
,
rpoispp
,
rpoint
# 100 random points in the unit square
pp <- runifpoint(100)
# irregular window
data(letterR)
# polygonal
pp <- runifpoint(100, letterR)
# binary image mask
pp <- runifpoint(100, as.mask(letterR))
Run the code above in your browser using DataLab