This is a simulation which uses a cannon to calculate PI.
Given a circular pond in a square field where the pond and field have the same diameter, we fire a cannon into the field over and over, hitting randomly and count the number of times we hit the pond.
Because the area of a square is (W squared) where "W" is the width of the square and because the area of a circle is (PI times D squared) where "D" is the diameter of the circle, if a circle and square have the same width, the ratio of the area of the circle to the area of the square is PI / 4.
So we keep shooting cannonballs into the field and then we check the ratio of times we hit the pond divided by the times we fired in total. Take that ratio, multiply by 4 and we get our current guess at the value of PI. As the number of cannonballs fired increases, we should get closer and closer to PI.
Keep in mind that, while this is a valid method of calculating PI, it is also very inefficient as each additional digit of accuracy requires 10x as many shots as the previous digit.
No. My BA degree is in Animation. But I almost majored in Computer Science and I've been programming almost as long as I have been drawing. I took honors math classes in high school and was nominated to the NC School of Science and Math but just missed making it in on a technicality.
I thought the area of a circle was simply Pi r2, and the circumference formula was the one that required the coefficient of two (i.e. 2 Pi r). Then factoring out the r2 from your area equation you get a ratio of Pi: 4, which is what you have based your program on... I'm sorry if I come across as... something. I'm just confused myself and trying to clarify =]