Learn R Programming

berryFunctions (version 1.4)

randomPoints: distanced random points

Description

arranges points in square randomly, but with certain minimal distance to each other

Usage

randomPoints(xmin, xmax, ymin, ymax, number, mindist, plot=TRUE, ...)

Arguments

xmin
Minimum x coordinate
xmax
Upper limit x values
ymin
Ditto for y
ymax
And yet again: Ditto.
number
How many points should be randomly + uniformly distributed
mindist
Minimum DIstance each point should have to others
plot
Plot the result? DEFAULT: TRUE
...
Further arguments passed to plot

Value

  • data.frame with x and y coordinates.

See Also

distance

Examples

Run this code
P <- randomPoints(xmin=200,xmax=700, ymin=300,ymax=680, number=60,mindist=10, asp=1)
rect(xleft=200, ybottom=300, xright=700, ytop=680, col=NA, border=1)

format( round(P,4), trim=FALSE)

windows(record=TRUE)
for(i in 1:10)
{
rp <- randomPoints(xmin=0,xmax=20, ymin=0,ymax=20, number=20, mindist=3, plot=FALSE)
plot(rp, las=1, asp=1, pch=16)
abline(h=0:30*2, v=0:30*2, col=8); box()
for(i in 1:nrow(rp))
    circle(rp$x[i],rp$y[i], r=3, col=rgb(1,0,0,alpha=0.2), border=NA)
}

Run the code above in your browser using DataLab