Computing in comfort
At the moment I'm lying in a hammock on our front porch, enjoying the weather. It's warm and sunny but the trees provide some nice shade. The birds are chirping, and except for a lawnmower running across the street, it's quite relaxing.
Internet connectivity is provided to my laptop via an open wireless access point. It must be from one of our neighbours, but I don't even know which one. Until I get my own access point, this will do. :)
Security is provided via openvpn, which I'm using to connect back into my own LAN.
Posted by Jason Hildebrand <jason@opensky.ca> Saturday Jul 9, 2005 at 0:00 PMI'll call the points on the circle A and B (I'll use capital letters for vectors and lower case otherwise). Then the middle between them is (A+B)/2. I'll call that one M. The distance of M to the center of the circle (call it C) is
dist = sqrt(r^2-(A-B)^2/4)
with r being the radius of the circle (simple Pythagoras on the triangle A,M,C). I made a drawing, that makes it much easier to see.
The distance of M to the circle is then r-dist. You now need a normalized vector orthogonal to (B-A) to go from M to the two points you're looking for:
N = 1 / sqrt((ay-by)^2+(bx-ax)^2) * [(ay-by), (bx-ax)]
and your two points are then M+dist*N and M-dist*N
So, there's a lot of squares and square roots in there, but no arctan :-)
Regards, Torsten Posted by: Torsten on Sunday Jul 24, 2005 at 7:17 AM
sqrt(1-x^2) is the semi-circle function (radius 1), so yes, if you integrate that from 0 to 1, you get pi/4. But I'm afraid that won't take you anywhere - if there is a closed expression for that integral, it will be arctan(1) again or something similar, like arcsin(1/sqrt(2)).
The arctan(1) method would work as an approximation, I guess. I don't have the Taylor expansion for arctan ready, but you could use
arcsin(x) = x + 1/2 x^3/3 + (1/2)(3/4) x^5/5 + (1/2)(3/4)(5/6) x^7/7 + ...and evaluate arcsin(1/sqrt(2)) which gives you pi/4:
pi*sqrt(2)/4 = 1 + 1/2*(1/2^1/3) + 1/2*3/4*(1/2^2/5) + 1/2*3/4*5/6*(1/2^3/7) + ...
which you can compute e.g. like that (C snippet):
int step; double y=1, factor=1, count=1; for( step=0; step<50; ++step ) { factor *= 0.5 * count / (count+1); count += 2; y += factor / count; printf("step %i: pi is approximately %.20g\n", step, y*4.0/sqrt(2)); }
This doesn't converge very fast, though. I know there are lots of much better algorithms for calculating pi. The fastest I've heard of quintuples the number of correct digits in every step, but I don't know how it works.
Regards, Torsten Posted by: Torsten on Tuesday Jul 26, 2005 at 0:39 PM