The quality of Pi is directly driven by the precision of your floating point math. I did this in Pascal in 1991, and than again with C++ and got a much closer value because C++ had float64 not float32. The real magic is doing it on paper with a dice.
This is a solution indeed. Though by counting the pixels, you have to count all the pixels, this can often be computationally heavy, but by randomly selecting a fraction of a group (or pixels) you reduce dramatically the computational time and achieve a satisfying precision. This technique is a core in Path Tracing, Physics related phenomena and so on...
@@valn1xd873It's not about it. In this case it's just a circle but MC method can be great when what you're trying to estimate is some complicated integral of a more complicated function or area of some intricate shape.
that reminds me of a time some math youtuber asked his subscribers to make some code thats faster than the code he wrote(that took hours to run) and people went crazy with it, doing some advanced code chemistry to squeeze every ms out of the code and got it to run in under a second
The quality of Pi is directly driven by the precision of your floating point math.
I did this in Pascal in 1991, and than again with C++ and got a much closer value because C++ had float64 not float32.
The real magic is doing it on paper with a dice.
Thank you for pointing that out, it is important to consider float-precision when dealing with such problems.
simple but satisfying! nice explanation
Fun small project.
Thank you for this amazing explanation.
you can skip most of it and just count the pixels and divide
This is a solution indeed.
Though by counting the pixels, you have to count all the pixels, this can often be computationally heavy, but by randomly selecting a fraction of a group (or pixels) you reduce dramatically the computational time and achieve a satisfying precision. This technique is a core in Path Tracing, Physics related phenomena and so on...
you can use the gpu to do those simple operations
@@valn1xd873It's not about it. In this case it's just a circle but MC method can be great when what you're trying to estimate is some complicated integral of a more complicated function or area of some intricate shape.
@@bartx3709 yeah, i understand, but i am an egineer so efficiency is the name of the game to me lol
that reminds me of a time some math youtuber asked his subscribers to make some code thats faster than the code he wrote(that took hours to run) and people went crazy with it, doing some advanced code chemistry to squeeze every ms out of the code and got it to run in under a second