http://mathworld.wolfram.com/PiFormulas.html
Have fun
Ugh. Pi pissing me off
quote:
Original post by Divide
... use the contour (not sure if this is the right word; correct me if I''m wrong) ...
I think you mean circumference.
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
and wouldn''t you need Pi to make the circle for the rope?
[edited by -
on December 25, 2002 11:41:33 PM]
[edited by -

quote:
I think you mean circumference.
Thats the one I meant, thanks!
quote:
and wouldn't you need Pi to make the circle for the rope?
Nope, the idea is to measure pi. I think you'll only need to use pythagoras' rule to calculate how much rope you need [sqrt(x*x+y*y) = r], but it'll be a hell of a job

[edited by - Divide on October 12, 2002 1:46:52 PM]
October 12, 2002 03:36 PM
Indeed the best way to calculate PI:
srand( time(NULL) ); int hitcircle = 0, hitoutside = 0; static const int N = 1500000; for( int curr = 0; curr < N; curr++ ) { // Monte Carlo method, unit circle // double x = static_cast< double >( rand() )/static_cast< double >( RAND_MAX ) * 2; double y = static_cast< double >( rand() )/static_cast< double >( RAND_MAX ) * 2; double dist = sqrt((x-1) * (x-1) + (y-1) * (y-1)); if( dist == 1 ) continue; // Not counted, but rare case // if( dist < 1 ) hitcircle++; else hitoutside++; } double PI = 4 * static_cast< double >( hitcircle )/static_cast< double >( hitcircle + hitoutside );
int A=1500000;
long double dx=1.0/A, pi=0;
for(int i=1;i{
pi+=0.5*sqrt(1.0-( i *dx)*( i *dx))*dx;
pi+=0.5*sqrt(1.0-((i+1)*dx)*((i+1)*dx))*dx;
}
pi*=4;
(I would put it in one of those code boxes, but I don''t know how)
Higher A = greater precision
long double dx=1.0/A, pi=0;
for(int i=1;i{
pi+=0.5*sqrt(1.0-( i *dx)*( i *dx))*dx;
pi+=0.5*sqrt(1.0-((i+1)*dx)*((i+1)*dx))*dx;
}
pi*=4;
(I would put it in one of those code boxes, but I don''t know how)
Higher A = greater precision
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement