Take a quarter of a circle and divide it in squares as shown in the (very badly drawn) picture:
Every time you draw a new square take as much space as possible from the circle. This way every square touches the previous drawn squares with the bottom and the left sides, and touches the circumference with the upper-right corner. This way every square forms a right triangle where the hypotenuse is the radius of the circle and each cathetus is the sum of the side of the square plus the sides of adjacent drawn squares.
You can then find the side $s$ of each square by solving the following equation, where $r$ is the radius of the circle, $x$ the sum of the sides of the adjacent squares on the x-axis and $y$ the sum of the sides of the adjacent squares on the y-axis: $$ r^2=(x+s)^2+(y+s)^2 $$ We can arrange it to form a quadratic equation: $$ (2)s^2+(2x+2y)s+(x^2+y^2-r^2)=0 $$ With a few more steps we find the positive solution: $$ s=\frac{\sqrt{2r^2-(x-y)^2}-(x+y)}{2} $$ As to how find the value of $x$ and $y$ we can use a recursive function to calcolate the area of the quarter of the circle. We can change the previously found solution as follow: $$ S(x,y,r)=\frac{\sqrt{2r^2-(x-y)^2}-(x+y)}{2} $$ We can state the recursive function of the area of a portion of the quarter of the circle as follow: $$ F(x,y,r)=S(x,y,r)^2+F(x+S(x,y,r),y,r)+F(x,y+S(x,y,r),r) $$ Each iteration returns the area of a single square and then recall itself twice to find the area of the right side and the area of the upper side of the circle not yet divided.
We can then find the area $A$ of the circle of radius $r$ starting with the full quarter of the circle as follow: $$ A = 4F(0,0,r) $$ I was wondering if a non-recursive function of this procedure was known since I wasn't able to find anything regarding this method. Since it calculates the area of a circle it can be used as a probably very inefficient way to find an approximation of pi. Here's a small code in TypeScript where $e$ is the length of the side I start to ignore to stop the recursion:
function F(x: number, y: number, r: number, e: number): number {
const l = L(x, y, r);
if (l < e) return 0;
return Math.pow(l, 2) + F(x + l, y, r, e) + F(x, y + l, r, e);
}
function L(x: number, y: number, r: number): number {
return (-(x + y) + Math.sqrt(2 * Math.pow(r, 2) - Math.pow(x - y, 2))) / 2;
}
for (let e = 1; true; e /= 1.01) {
const pi = 4 * F(0, 0, 1, e);
console.log(e, pi);
}
If something seems off, sorry in advance. I'm not a mathematician but I like to meddle with it.
