Sample uniformly within a fixed radius.

May 16, 2014

[This article was first published on Quantitative Ecology, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I was asked how to do this today and thought that I would share the answer:

## Sample points uniformly within a fixed radius


## Sample data
## NB: To get a truly uniform sample over the circle, you must
## sample the square of the distance and then transform back.
tempdat<-data.frame(X0=0,Y0=0, bearing0=0,
bad.dist= runif(nrand)*maxstep,

##convert Turning angle to bearing (in this case no change)

## Convert from polar to cartesian coordinates


##make plots
plot(Ybad~Xbad, data=tempdat, asp=1, main="Center is oversampled")
plot(Y~X, data=tempdat, asp=1, main="Uniform across space")

To leave a comment for the author, please follow the link and comment on their blog: Quantitative Ecology. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)