From: Albert Picado <albert_picado_at_yahoo.fr>

Date: Sat 07 Oct 2006 - 07:32:52 GMT

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Oct 07 17:43:34 2006

Date: Sat 07 Oct 2006 - 07:32:52 GMT

I am trying to find a way to generate a random point in a circle centred in a geographical location.

So,

1. Is there any package that generates random points in a circle? (I couldn’t find any) 2. Do you think the code bellow produces uneven locations? 3. Any suggestions to programme the “rejection method”? Maybe someone has already used it...

Cheers

albert

#Code random location in a circle

# Generate UTM coordinates (original location)

*> x_utm<-c(289800)
**> y_utm<-c(4603900)
*

> coord<-as.data.frame(cbind(x_utm,y_utm))

# Generate a random radius with a maximum distance of 1000 meters from the original location.

*>radius<-runif(1,0,1000)
*

# Generate a random angle

*>angle<-runif(1,0,360)
*

#Generate a random x coordinate

*>x_rdm<-coord$x_utm[1]+radius*cos(angle)
*

#Generate a random y coordinate

*>y_rdm<-coord$y_utm[1]+radius*sin(angle)
**>result<-as.data.frame(cbind(x_rdm,y_rdm, x_utm, y_utm))
*

# We can calculate the distance between the original and the random location

*> result$dist_m<-sqrt(((coord$x_utm-result$x_rdm)^2+(coord$y_utm-result$y_rdm)^2))
**>result
*

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Oct 07 17:43:34 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Sat 07 Oct 2006 - 09:30:09 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*