in reply to Improve my coding

Suppose you had to loop from 1 to 1000000 in steps of square root of 2. Would you have precalculated all the intermediate points and put them in an array? I certainly wouldn't. I'd write your loop as:
for (my $r = 1; $r <= 100; $r += 2) { ... }
I'd also declare the variables I only used in the body of the loop in the body, and I wouldn't make them global. Furthermore, if I were to make constants pi and 2pi, I'd define the latter as a function of the first:
$twopi = 2 * $pi;
If you then use a better approximation of pi, you'd only have to update the program once.