# [R] random point in a circle centred in a geographical position

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 far I have used the following formula (see code below): random_x = original_x + radius*cos(angle) random_y = original_y + radius*sin(angle) where radius is a random number between 0 and the radius of the circle and angle is between 0 and 360 degrees

The code bellow works fine however some people argue that this method will produce uneven locations… I really do not understand why.

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.

# Generate a random angle
>angle<-runif(1,0,360)

#Generate a random x coordinate
#Generate a random y coordinate
>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.