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?

lgrov44 wrote:

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.

Thanks!

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?

-MePix- wrote:

lgrov44 wrote:

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.

Thanks!
No worries.

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.
NIKI-KOLCHAGOV
Scratcher
100+ posts

How to calculate Pi?

This topic should probably be closed since it looks resolved





mumu245
Scratcher
1000+ posts

How to calculate Pi?

-MePix- wrote:

(#3)

lgrov44 wrote:

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.

Thanks!
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.

Last edited by mumu245 (March 28, 2024 14:42:07)


select this text then press Ctrl+Shift+Down to read more
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)


select this text then press Ctrl+Shift+Down to read more
MrKingofScratch
Scratcher
100+ posts

How to calculate Pi?

here's a funny approach
https://scratch.mit.edu/projects/682780554/

Last edited by kaj (Tomorrow 00:00:00)
100th post!
Shrek_em
Scratcher
34 posts

How to calculate Pi?

circumference / diameter

Shrek_em

Really bad coder

Really good ideas

Want to make a signature?
Click this purple thing to figure out how
lgrov44
Scratcher
500+ posts

How to calculate Pi?

mumu245 wrote:

-MePix- wrote:

(#3)

lgrov44 wrote:

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.

Thanks!
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.
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.

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:
([atan v] of ())

Last edited by PhiPhenomenon (March 30, 2024 01:31:27)

-MePix-
Scratcher
24 posts

How to calculate Pi?

mumu245 wrote:

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
Can you make a project with the script? It is kinda hard to tell what it is through forums

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
500+ posts

How to calculate Pi?

Shrek_em wrote:

circumference / diameter
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…

Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
forever
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
Please read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
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 title topics something like “HELP ME!!!”. It's not helpful, and won't get you as many responses.
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
 [code] and [/code] 
tags to show other users how to format something that Scratch would otherwise format.
You can use the
 [color=color name or hexadecimal value here] and [/color] 
tags to color text.
Little-known Scratch URLs:
scratch.pizza (redirects to main page)
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)
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.

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.
london11gm
Scratcher
29 posts

How to calculate Pi?

22/7 = pi
You can also check out @DadOfMrLog 's super pi calculator
https://scratch.mit.edu/projects/47680290

Last edited by london11gm (March 29, 2024 05:47:47)

Vaibhs11
Scratcher
1000+ posts

How to calculate Pi?

london11gm wrote:

22/7 = pi
That is a terrible estimation of pi compared to what OP's asking for.
TheUltimateHoodie
Scratcher
1000+ posts

How to calculate Pi?

Vaibhs11 wrote:

london11gm wrote:

22/7 = pi
That is a terrible estimation of pi compared to what OP's asking for.
but my teacher said to use that

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?

TheUltimateHoodie wrote:

but my teacher said to use that

did my teacher lie to me?
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.
TheUltimateHoodie
Scratcher
1000+ posts

How to calculate Pi?

PhiPhenomenon wrote:

TheUltimateHoodie wrote:

but my teacher said to use that

did my teacher lie to me?
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.
so…my teacher lied…she said 22/7 WAS pi

can somebody give me something to put in my signature

Powered by DjangoBB