I want to visualize the the Algorithm of the Polar method from two perspectives (bird’s-eye and frog’s eye view).
To draw the first step of the method I need random number of the uniform distribution in a square and a circle.
I’ve already been able to plot the circle in a square, but how to plot random numbers (z1) inside of this construct?
require (plotrix)
require (grid)
z1 = runif (100)
plot (c(-1,1), c(-1,1), type="n", asp=1)
rect(-1,-1,1,1)
draw.circle (0,0,1)
And how to change the perspective?
You can do without ‘rejecting’ any points. The following R function needs
3*nrandom numbers and will generatenrandomly chosen points in a circle of radiusr: