# [R] [OOPS] Re: Drawing sample from a circle

(Ted Harding) Ted.Harding at manchester.ac.uk
Fri Jun 18 11:48:17 CEST 2010

```OOPS: AN error on the code below! See in-line.
Ted.

On 18-Jun-10 09:33:04, Ted Harding wrote:
> On 18-Jun-10 08:04:36, Ron Michael wrote:
>> Hi, I would like to draw 10 uniformly distributed sample points from a
>> circle with redius one and centered at (0,0). Is there any R function
>> to do that?
>> _
>> Thanks,
>
> You can quite easily write one.
>
> [A]
> Sampling uniformly on the circumference of the circle:
>
>     x0 <- centre[1] ; y0 <- centre[2]
>     u <- 2*pi*runif(n)
>   }
>
># Returns an nx2 matrix whose two columns are the x and y coordinates
CORRECTION:

x0 <- centre[1] ; y0 <- centre[2]
u <- 2*pi*runif(n)
}

# Returns an nx2 matrix whose two columns are the x and y coordinates

> [B]
> Sampling uniformaly within the circle
>
>     x0 <- centre[1] ; y0 <- centre[2]
>     u <- 2*pi*runif(n)
>     r <- sqrt(runif(n))
> }
>
># Returns an nx2 matrix whose two columns are the x and y coordinates
CORRECTION:

x0 <- centre[1] ; y0 <- centre[2]
u <- 2*pi*runif(n)
r <- sqrt(runif(n))
}

# Returns an nx2 matrix whose two columns are the x and y coordinates

> [C]
> Examples:
>
>   plot(csamp(100),asp=1)
>
>   plot(Csamp(1000),asp=1)
>
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 18-Jun-10                                       Time: 10:33:00
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help