Skip to content

A simple approximation of the circle constant pi using a "monte carlo" method. Its not the most efficient or most elegant way to do it but is does something. Right now its just returning the difference of the calculated value and pi.

Notifications You must be signed in to change notification settings

MrFibunacci/approximate-pi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

approximate-pi

A simple approximation of the circle constant pi using the "monte carlo" method.

monte calo algorithm

My implementaion is simple I use an modified verion of rand(),just that I get an double within an range, to drop my points. My calculation in approximatePI() is:

(pointsInCircle * pointsTotal) / 4

how it works

It's simple we throw dots on an imaginary square with an cirlce in it (with a = r^2) and count how many dots are in the circle and how many we have in total. Than we do the calculation from above.

The determination rater the dot is in the circle or not is done by using Pythagoras rule a^2 + b^2 = c^2 to calculate the distance between the centre and the point. If the result is greater than the radius its not in the circle.

not my stuff:

The fRand() function is from stackoverflow user Frank posted in https://stackoverflow.com/questions/2704521/generate-random-double-numbers-in-c

I use the BigFloat - Arbitrary-Precision Float Arithmetic Library by Gianfranco Mariotti

idea

I got the idea to do an c++ implementation of an aproximation of pi because of an video by CodingTrain. I wrote some of the code simular to the one in video, so that is also not quite my stuff.

About

A simple approximation of the circle constant pi using a "monte carlo" method. Its not the most efficient or most elegant way to do it but is does something. Right now its just returning the difference of the calculated value and pi.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages