|
The value of pi is approximated by
- Generating random x and y coordinates, between -1 and 1.
- These random dots will fit inside a square measuring 2 x 2 units.
- Some will fit inside a 1 unit radius circle as well, others will not.
- The ratio of dots inside the circle, to the total number of dots; will be about the same as the ratio of area of the circle, to the area of the square
- Let c = number of dots inside the circle
- Let n = number of dots
- Let ac = area of circle
- Let as = area of square
- Let r = radius of circle
- Then, c / n = ac / as
- Or, c / n = (pi x r x r) / (2 x 2)
- As r=1, c / n = pi / (2 x 2)
- Or, pi = c / n x 4
Therefore, the value of pi can be approximated simply by counting the number of dots inside the circle, dividing this by the number of tries, and multiplying by 4.
Dot is inside the circle if it's distance from the center is less than the radius of the circle
- Let d = Distance of dot from center, or dot radius
- Using Pythagoras' Theorem, x2 + y2 = d2
- Therefore, dot is inside the circle if d2 < r2
- Since r = 1, r2 = 1 x 1 = 1
- Therefore, dot is inside the circle if x2 + y2 < 1
Or instead of
d2 < r2
should it be
d2 <= r2
instead?
What difference would it make, in theory and in practice?
Pi Approximation Day - 22/7. Celebrate 22nd July by eating something round, like a pizza.
|