The application let's you visualize π approximation. Written using Windows Presentation Foundation.
If you just want to run the application you can download the dist/
folder. Then double click on MonteCarloVisualization.application
Application runs only under Windows. If you don't have .NET run time installed run dist/setup.exe
The implementation takes a random point inside the square and checks if that point lies within the circle. The ratio of points inside the circle to all generated points is p. Multiplying p by 4 gives the approximate value of π.
Calculates π value for given number of points.
Calculates π value in multiple steps, each time for different number of points. You can see as the animation progresses the value of π is approximated with better accuracy.
1. WPF is not the best technology to draw a lot of points on Canvas. The default mechanisms of the framework don't support such oppertations.
First of all UI is single thread so each paint operation freezes the application (keep in mind freeze the application is something different than disabling UI controls). The solution works this way:
- Shapes (rectangle and circle) are drawn on canvas
- All points are drawn to
WritableBitmap
which is later drawn onImage
This way the application performance is much better