Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- We draw a square whose side is 2cm long and inside it a circle with r=1cm. The square is defined by [-1,-1] and [1,1] in a cartesian coordinate system.
- Obviously the area of the square is 2x2 = 4cm.
- We begin generating random points which are inside the square but may not be inside the circle.
- The point dimensions ∈[0, 1] but they may as well be negative because the hypotenuse is independent of sign of either of sides.
- The square area to circle area ratio is equal to the points inside square to points inside circle ratio.
- So by generating more points we keep getting closer to the circle area.
- When we find it we divide by the squared radius(1*1, which turns out to be a no-op) to get PI.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement