Discuss Scratch
- -MePix-
- Scratcher
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
I don't copy this every time I post, Under that grey line (⬆️) Is my signature, I can put whatever I want in it and it's not spam
Hold Shift+Click to see more of my signature
I have an account on the Scratch Wiki
click the link above to visit my user page
- lgrov44
- Scratcher
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.
lgrov44, an Australian Scratcher whose most famous for his follows, followed by his activity, especially on Discussion Forums, and his follower count. Is also a remix chainer and school student. Identifies as bisexual.
My top 3 favourite people:
1. @Higgies (deleted) - First Follower, Thank you so much! (Wish you could see this…)
2. @Dubstepv1 (Banned/Moved) - Remix Chainer
3. @GIitchInTheMatrix (Moved to @GlitchedThrough) - Many small things.
Still looking for one of my first followers who are still active.
- -MePix-
- Scratcher
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
I don't copy this every time I post, Under that grey line (⬆️) Is my signature, I can put whatever I want in it and it's not spam
Hold Shift+Click to see more of my signature
I have an account on the Scratch Wiki
click the link above to visit my user page
- lgrov44
- Scratcher
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
lgrov44, an Australian Scratcher whose most famous for his follows, followed by his activity, especially on Discussion Forums, and his follower count. Is also a remix chainer and school student. Identifies as bisexual.
My top 3 favourite people:
1. @Higgies (deleted) - First Follower, Thank you so much! (Wish you could see this…)
2. @Dubstepv1 (Banned/Moved) - Remix Chainer
3. @GIitchInTheMatrix (Moved to @GlitchedThrough) - Many small things.
Still looking for one of my first followers who are still active.
- mumu245
- Scratcher
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
- Scratcher
1000+ posts
How to calculate Pi?
Even though Scratch isn't precise enough, you can try this algorithm:
set [pi v] to [3]
set [i v] to [2]
forever
change [pi v] by ((4) * (((i) * (((i) + (1)) * ((i) + (2)))) - (((i) + (2)) * (((i) + (3)) * ((i) + (4))))))
change [i v] by (4)
end
Last edited by mumu245 (March 28, 2024 14:51:39)
- MrKingofScratch
- Scratcher
100+ posts
How to calculate Pi?
here's a funny approach
https://scratch.mit.edu/projects/682780554/
https://scratch.mit.edu/projects/682780554/
- lgrov44
- Scratcher
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
lgrov44, an Australian Scratcher whose most famous for his follows, followed by his activity, especially on Discussion Forums, and his follower count. Is also a remix chainer and school student. Identifies as bisexual.
My top 3 favourite people:
1. @Higgies (deleted) - First Follower, Thank you so much! (Wish you could see this…)
2. @Dubstepv1 (Banned/Moved) - Remix Chainer
3. @GIitchInTheMatrix (Moved to @GlitchedThrough) - Many small things.
Still looking for one of my first followers who are still active.
- PhiPhenomenon
- Scratcher
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:
([atan v] of ())
Last edited by PhiPhenomenon (March 30, 2024 01:31:27)
- -MePix-
- Scratcher
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:set [pi v] to [3]
set [i v] to [2]
forever
change [pi v] by ((4) * (((i) * (((i) + (1)) * ((i) + (2)))) - (((i) + (2)) * (((i) + (3)) * ((i) + (4))))))
change [i v] by (4)
end
I don't copy this every time I post, Under that grey line (⬆️) Is my signature, I can put whatever I want in it and it's not spam
Hold Shift+Click to see more of my signature
I have an account on the Scratch Wiki
click the link above to visit my user page
- BigNate469
- Scratcher
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
Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
foreverPlease read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
This signature is designed to be as helpful as possible.
View all of the topics you've posted in:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=topics
View all of your posts:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=posts
Forum tips:
Don't post in topics where the latest post is over ~2 months old, unless you have something critical to add. Especially in topics that are several years old- it isn't helpful, and is known as necroposting.
Don't post unrelated things in topics, including questions of your own. Make a new topic for your questions.
You can use the
[color=color name or hexadecimal value here] and [/color]
Lesser-known Scratch URLs:
https://scratch.mit.edu/projects/PROJECT ID HERE/remixtree (replace “PROJECT ID HERE” with project id number. Shows all the remixes of the project, and the remixes of those projects, and the remixes of those projects, and so on, as a chart. Link currently redirects to one of my projects)
View a larger list at: https://scratch.mit.edu/discuss/topic/542480/
Why @Paddle2See's responses are so often identical: https://scratch.mit.edu/discuss/topic/762351/
1000th post
- homewins
- Scratcher
45 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
- Scratcher
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
- Scratcher
39 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
- Scratcher
1000+ posts
How to calculate Pi?
That is a terrible estimation of pi compared to what OP's asking for. 22/7 = pi
- TheUltimateHoodie
- Scratcher
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)
can somebody give me something to put in my signature
- PhiPhenomenon
- Scratcher
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
- Scratcher
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?
can somebody give me something to put in my signature