https://dvjn.github.io/CalcuPi/
Calculate Pi using Monte Carlo method
https://dvjn.github.io/CalcuPi/
Last synced: 8 months ago
JSON representation
Calculate Pi using Monte Carlo method
- Host: GitHub
- URL: https://dvjn.github.io/CalcuPi/
- Owner: dvjn
- License: mit
- Created: 2021-03-15T21:01:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-27T07:15:12.000Z (over 3 years ago)
- Last Synced: 2025-03-24T18:05:26.016Z (9 months ago)
- Language: Rust
- Homepage: https://dvjn.github.io/CalcuPi/
- Size: 1.66 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-seed-rs - CalcuPi - A beautiful Monte Carlo simulation for approximating the value of pi. (Projects Using Seed)
README
# **[`CalcuPi 🚀`](https://dvjn.github.io/CalcuPi/)**
> Calculate Pi using Monte Carlo method
Please ⭐ if you like it!
## Explanation 🤔
### Steps 🎲
- Use a square of arbitrary side length and inscribe a circle inside it.
- Put random points on the square using a uniform distribution.
- Count the number of random points falling inside the circle.
- Calculate the approximate value of pi using,
`4 * points inside the circle / total number of points`.
### Maths 📏
Why 4 * points inside the circle / total number of points?
Let's consider,
Radius of circle, **`r`**
Side of square, **`2r`**
Number of points inside the circle, **`C`**
Total number of points, **`S`**
Thus,
Area of circle = **`πr²`**
Area of square = **`4r²`**
For large enough number of random points, we can consider that the ratio of areas of circle to square is equal to the ratio of points inside the circle to the total number of points, ie, **`πr²/4r² = C/S`**.
Which can be simplified to, **`π = 4*C/S`**
## Links ✨
- [What is Monte Carlo Method? 🤓](https://en.wikipedia.org/wiki/Monte_Carlo_method "Monte Carlo method - Wikipedia")
- [Inspiration for the Project 💖](https://www.youtube.com/watch?v=5cNnf_7e92Q "Coding Challenge #95: Approximating the Value of Pi - Youtube")