Discuss Scratch
- -MePix-
-
24 posts
How to calculate Pi?
How to calculate Pi
How do I calculate Pi accurately with scratch blocks?
I am making a Pi game where the digits go on forever
- lgrov44
-
500+ posts
How to calculate Pi?
There are many ways to do this. For your example, try just downloading and saving the digits, however, if a script is what you need, you can try the long script from this project.
- -MePix-
-
24 posts
How to calculate Pi?
long script from this project.Thanks! There are many ways to do this. For your example, try just downloading and saving the digits, however, if a script is what you need, you can try the
- lgrov44
-
500+ posts
How to calculate Pi?
No worries.long script from this project.Thanks! There are many ways to do this. For your example, try just downloading and saving the digits, however, if a script is what you need, you can try the
- NIKI-KOLCHAGOV
-
500+ posts
How to calculate Pi?
This topic should probably be closed since it looks resolved
- mumu245
-
1000+ posts
How to calculate Pi?
(#3)That doesn't compute pi. It renders a fixed list of digits. Scratch isn't precise enough to hold more than 9 or 10 digits of pi.long script from this project.Thanks! There are many ways to do this. For your example, try just downloading and saving the digits, however, if a script is what you need, you can try the
Last edited by mumu245 (March 28, 2024 14:42:07)
- mumu245
-
1000+ posts
How to calculate Pi?
Even though Scratch isn't precise enough, you can try this algorithm:
Last edited by mumu245 (March 28, 2024 14:51:39)
- MrKingofScratch
-
100+ posts
How to calculate Pi?
here's a funny approach
https://scratch.mit.edu/projects/682780554/
https://scratch.mit.edu/projects/682780554/
- lgrov44
-
500+ posts
How to calculate Pi?
What do you mean? You can store that many digits. You would, at most, save it as an item of a list, but you can definitely store all of those digits, specifically, you can definitely store more than the mentioned 9 or 10 digits.(#3)That doesn't compute pi. It renders a fixed list of digits. Scratch isn't precise enough to hold more than 9 or 10 digits of pi.long script from this project.Thanks! There are many ways to do this. For your example, try just downloading and saving the digits, however, if a script is what you need, you can try the
- PhiPhenomenon
-
500+ posts
How to calculate Pi?
There's a pretty cool infinite sum that can be used to calculate pi:

However, it's pretty slow. You have to sum like the first thousand terms of the terms to get like the first four places of pi.
There's a faster one called the Machin formula, but it requires a little more math:

You can find the arctangent block from the operators section:

However, it's pretty slow. You have to sum like the first thousand terms of the terms to get like the first four places of pi.
There's a faster one called the Machin formula, but it requires a little more math:

You can find the arctangent block from the operators section:
Last edited by PhiPhenomenon (March 30, 2024 01:31:27)
- -MePix-
-
24 posts
How to calculate Pi?
Can you make a project with the script? It is kinda hard to tell what it is through forums Even though Scratch isn't precise enough, you can try this algorithm:
- BigNate469
-
1000+ posts
How to calculate Pi?
The issue with that is to know both the circumference and diameter you have to know Pi and all of its digits, and Pi is indefinitely long… circumference / diameter
- homewins
-
46 posts
How to calculate Pi?
https://scratch.mit.edu/projects/47680290/ is the fastest Scratch pi calculator I know of.
If you really wanted to you could even use mine: https://scratch.mit.edu/projects/991482978/
2000 digits in ~3 seconds on @DadOfMrLog's ~112 seconds on mine, so mine is 40x slower. Mine also scales worse. I hope I can make mine better.
Basically the idea behind both it is Machin-like formulas, of the form
pi/4=a*arctan(1/x)+b*arctan(1/y)…etc…
Using infinite series to calculate each arctan term.
The hard part is figuring out how to make custom blocks to do your arithmetic with thousands of digits of precision.
If you really wanted to you could even use mine: https://scratch.mit.edu/projects/991482978/
2000 digits in ~3 seconds on @DadOfMrLog's ~112 seconds on mine, so mine is 40x slower. Mine also scales worse. I hope I can make mine better.
Basically the idea behind both it is Machin-like formulas, of the form
pi/4=a*arctan(1/x)+b*arctan(1/y)…etc…
Using infinite series to calculate each arctan term.
The hard part is figuring out how to make custom blocks to do your arithmetic with thousands of digits of precision.
Last edited by homewins (March 29, 2024 02:09:32)
- Vaibhs11
-
1000+ posts
How to calculate Pi?
This is a wikipedia article on different formulae that can be used to approximate pi. Here is a list of just the formulas (ignore the integrals part). You can implement any of these into scratch, although the more efficient ones take more computing power or are prone to floating point errors, and the less efficient ones just take more time to get there.
Floating point numbers aren't precise enough for any of these formulas. So, I recommend you store the numbers as a string and make your own digit-by-digit addition, subtraction, long multiplication and long division functions for strings. Using strings can hold way more numbers than floating point can I think.
Floating point numbers aren't precise enough for any of these formulas. So, I recommend you store the numbers as a string and make your own digit-by-digit addition, subtraction, long multiplication and long division functions for strings. Using strings can hold way more numbers than floating point can I think.
- london11gm
-
42 posts
How to calculate Pi?
22/7 = (edit) roughly pi
You can also check out @DadOfMrLog 's super pi calculator
https://scratch.mit.edu/projects/47680290
You can also check out @DadOfMrLog 's super pi calculator
https://scratch.mit.edu/projects/47680290
Last edited by london11gm (May 26, 2024 19:10:24)
- Vaibhs11
-
1000+ posts
How to calculate Pi?
That is a terrible estimation of pi compared to what OP's asking for. 22/7 = pi
- TheUltimateHoodie
-
1000+ posts
How to calculate Pi?
but my teacher said to use thatThat is a terrible estimation of pi compared to what OP's asking for. 22/7 = pi
did my teacher lie to me?
Last edited by TheUltimateHoodie (March 29, 2024 10:06:07)
- PhiPhenomenon
-
500+ posts
How to calculate Pi?
The OP wants an approximation of pi that goes on as long as they can. 22/7 comes out to about 3.1428. That's a 0.0403% error from the actual value of pi, so it's fine to use in calculations. However, it's 3rd decimal place is already wrong. but my teacher said to use that
did my teacher lie to me?
- TheUltimateHoodie
-
1000+ posts
How to calculate Pi?
so…my teacher lied…she said 22/7 WAS piThe OP wants an approximation of pi that goes on as long as they can. 22/7 comes out to about 3.1428. That's a 0.0403% error from the actual value of pi, so it's fine to use in calculations. However, it's 3rd decimal place is already wrong. but my teacher said to use that
did my teacher lie to me?