Advertisement

Ugh. Pi pissing me off

Started by October 10, 2002 03:24 PM
15 comments, last by black_mage_s 22 years, 4 months ago
In the lounge, there is a topic floating around about pi and e. So I was just messsing around on my computer, and decided to make a program to calculate pi to varying degrees of accuracy. I was using this formula here:
quote:
to calculate pi: n/2 * sin(360/n) The larger n is, the more accurate pi is where sine is in degrees.
Now, when I enter this into a calculator, using the value 2 for N, it comes out all fine and dandy, but when I threw it into my C++ program, I get all weird results. Basically, I have this for my output
quote:
std::cout << number/2*sin(360/number)
Now, when I enter the number 2, it gives me the result 0.8128... but this isn''t the right answer, on the calculator, it said, 3.141... What giveS? http://www.big-mommas-titty-warehouse.tk unzip; strip; touch; finger; mount; fsck; more; yes; fsck; fsck; fsck; umount; sleep;
"Luck is for people without skill."- Robert (I Want My Island)"Real men eat food that felt pain before it died."- Me
I can''t remember if the sin finction uses radians or degrees, but make sure it''s using the same unit your calculator does, or convert it. That will mess up your calculation real quick .
Advertisement
360 degrees? I''ll be that''s the problem. That formula''s correct if sine is in degrees. However, the default for C++ functions is in radians. Problem is, 360 degrees in radians is 2*pi. Thus, pi is required for the calculation of pi. There are, however, other methods. Google for it.

3.14159265358979323846264338327950288

From memory.

Ciao,
Eyrian
Oh hooray. Now I have to figure out how to convert it.

http://www.big-mommas-titty-warehouse.tk
unzip; strip; touch; finger; mount; fsck; more; yes; fsck; fsck; fsck; umount; sleep;
"Luck is for people without skill."- Robert (I Want My Island)"Real men eat food that felt pain before it died."- Me
The sine functin definitely uses radians. Want to know the funny part? Pi must be used in converting between degrees and radians.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
But I want to figure out pi! Without pi!

http://www.big-mommas-titty-warehouse.tk
unzip; strip; touch; finger; mount; fsck; more; yes; fsck; fsck; fsck; umount; sleep;
"Luck is for people without skill."- Robert (I Want My Island)"Real men eat food that felt pain before it died."- Me
Advertisement
<a href="http://www.google.ca/search?q=calculating+pi">Calculating Pi</a>
quote:
Original post by black_mage_s
But I want to figure out pi! Without pi!


Pi = 4.0*atan(1.0);

And the atan can be evaluated using a truncated series.

Pi without Pi!



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
quote:
Original post by black_mage_s
But I want to figure out pi! Without pi!
Then why did you use that equation?
My old math teacher explained it to me some years ago. You can use the contour (not sure if this is the right word; correct me if I'm wrong) to decide pi.

We know that the contour of a circle is 2*PI*r.

With this you can decide pi

pi = C/(2*r)

So basically, all you have to do is to write a rope simulator which measures a rope by winding it around a circle once.



[edited by - Divide on October 12, 2002 5:38:03 AM]

This topic is closed to new replies.

Advertisement