[R] monte carlo method for circle area
Douglas Trainor
trainor at uic.edu
Tue Apr 1 00:27:22 CEST 2003
Roxana,
Ignoring R for the moment...
I'm not sure I understand your nxn window thing, but:
if you have a circle with center (A,B) and radius R,
and you have a given point (X,Y), if you conceptually
translate everything by (-A,-B), so now you have a circle
with center (0,0) and radius R, and the point (X-A,Y-B).
The given point (X,Y) is inside the original circle
if sqrt((X-A)*(X-A)+(Y-B)*(Y-B)) < R.
The given point (X,Y) is outside the original circle
if sqrt((X-A)*(X-A)+(Y-B)*(Y-B)) > R.
If sqrt((X-A)*(X-A)+(Y-B)*(Y-B)) = R,
then it's exactly on the edge of the circle.
If you generate many pseudo-random points (X,Y) uniformly
within a box where: A-R < X < A+r and B-R < Y < B+r, then
you just need to count how many satisfy
sqrt((X-A)*(X-A)+(Y-B)*(Y-B)) < R and how many
do not. Or should that be <= R ? I just got off an
airplane, but it goes something like that.
For extra credit, how many points (X,Y) do you
need on average to calculate the area within some
margin of error (delta)?
douglas
Roxana Bravo wrote:
>Hello everyone
>
>I hope Im not bothering you all again. I have just begun to use R and so Im not yet familiarized with it..
>
>I ve got an assignment which consists in calculating the area of a circle given a certain radius and center using the monte carlo method, which means that I have to plot a circle given its parameters. Limit the area inside it...with as many sample points as possible...and all of this inside a nxn size window, which could be 1x1, or any size actually. I wonder how I could just limit the area inside the circle..that would be great help for me. Some of you have given me several suggestions about plotting a circle using some built-in functions but I wonder if its suits my problem since I have to somehow limit the circles inner area.
>
>thanks a lot
>
>
More information about the R-help
mailing list