Mathematics

A Fascinating Look at ∞ Shapes

Drawing infinity and finding area and perimeter using recursion and infinite sums.

Noah Hradek
Intuition

--

Infinity shape in light
Photo by Izabel 🇺🇦 on Unsplash

Infinity has always fascinated me; I recently went through the Brilliant course on infinity, discussing shapes like the Koch Curve and fractals. Fractal shapes like these can form beautiful and intricate patterns. There are other kinds of infinite shapes than fractals as well. There is also a class of geometric shapes that form squares, circles, spirals, and more. The areas and perimeters of such shapes can often be computed with infinite series. Like the convergent series that you find in Calculus II, you can find the area and perimeter with an infinite sum. We will find these calculations often take the form of a geometric series and thus converge to a specific value.

Geometric series with constant a and ratio r

We can often find a recurrence between areas of previous and later values for the area, perimeter, and side length. Thus we can calculate these values recursively and generate the resulting shape. This generates beautiful shapes that are almost fractal but not quite, more platonic and geometric instead.

Infinite Squares

Our first shape is a series of infinite squares that get smaller as you iterate. We subdivide a square into fourths and color in the top-left square at each iteration in each smaller subdivision. Each square has a side that is 1/2 smaller than the previous square with an area 1/4 the size of the previous square such that for a side length of size s, we have a recurrence of.

Assuming our base square is the unit square with a total area of 1, our largest filled square has an area of 1/4. We can see that the area of all the filled squares becomes a convergent infinite sum. Our total square area is A, and each term in the sum becomes smaller by a factor of 1/4, just like the area of each smaller square. Thus our r = 4, and we have a ratio of 1/4 between each term.

The sum eventually grows and grows slower until it converges at infinity. The final area of the whole shape in red is simply 1/3 or a repeating fraction of 0.333 indefinitely. This is a counterintuitive result; why would an infinite shape have an area at all, much less a third of the total unit square?

Series of smaller squares in red
Infinite Squares

In processing, the code would look like this to draw the series of infinite squares. We recurse with a base case where our side length is at most 1, and our recursion halves the side length each time. This ensures we hit the base case and draw all the squares properly.

void setup() {
size(500, 500);
}


void drawInfiniteSquare(int x, int y, int s) {
if(s <= 1) {
return;
}
int mid = s/2;
noFill();
square(x+mid, y, mid);
square(x, y+mid, mid);
square(x+mid, y+mid, mid);
fill(255, 0, 0);
square(x, y, mid);
drawInfiniteSquare(x + s/2, y + s/2, s/2);
}

void draw() {
drawInfiniteSquare(0, 0, 500);
save("infinitesquares.png");
}

Infinite Rings

Infinite rings are a series of concentric circles, with each radius being halved each iteration. This shape forms a series of rings which look like a tunnel or an eye.

Infinite number of rings
Infinite Rings

The recurrence of this relation between radii would be a halving of the previous radius.

You can already guess that our r=2 and our ratio is 1/2 based on that. To formally define it, however, we will be using the equation for the perimeter of a circle. Thus we can find the perimeter of each circle as.

Suppose we define the largest circle as the unit circle with radius one and add each successive term as the perimeter of each new circle with a radius of half of the previous circle. In that case, we have an infinite sum that converges to 4π.

The code is straightforward, using a simple recursive algorithm.

void setup() {
size(500, 500);
}


void drawInfiniteRings(int x, int y, int r) {
if(r <= 1) {
return;
}
circle(x, y, 2*r);
drawInfiniteRings(x, y, r/2);
}


void draw() {
drawInfiniteRings(250, 250, 250);
save("/Users/nhradek/Desktop/InfiniteRings.png");
}

Infinite Caterpillar

A related shape but slightly different is the infinite caterpillar. We have a series of circles, with each circle next in the sequence having a radius of half the previous circle. In a recurrence, the relation between radii of sequential circles would be.

Infinite caterpillar in green
Infinite Caterpillar

The summation uses the area formula of a circle, π times the radius squared.

Our ratio now would be 1/2 squared rather than just 1/2. Which would be 1/4, and assuming our largest circle is the unit circle with a radius of 1, our area calculation for the shape would be.

Another strange infinite shape, this time with the shape of a caterpillar but ending with a convergent sum which means the area is finite. You might notice that this sum is similar to our sum for a series of infinite squares, and you’re right. It is. Both have a ratio of 1/4, and the sum is just offset by 1 because we include the unit circle in the area calculation. The processing code is also recursive and simple except for the x offset calculation which I experimented with to find the right offset.


void setup() {
size(500, 500);
}

void drawCaterpillar(int x, int y, int r) {
if(r <= 1) {
return;
}
fill(0, 255, 0);
circle(x, y, r);
drawCaterpillar(x+r/2+r/4, y, r/2);
}


void draw() {
drawCaterpillar(150, 250, 100);
save("/Users/nhradek/Desktop/InfiniteCaterpillar.png");
}

Nested Rotated Squares

This shape is produced by nesting squares rotated at a 45° angle such that the corner of the smaller square is touching the midpoint of the larger square forming a 45° angle with the larger square. This produces a beautiful shape similar to the infinite rings that look like a psychedelic tunnel.

Nested rotated squares.
Nested Rotated Squares

To determine the side length of each square, we can use the Pythagorean theorem where b is the side length of the inner square, and a is the side length of the outer square.

Pythagorean theorem applied to inner and outer squares.

Thus we get an equation for b such that we can relate b as a function of a.

Thus our recurrence between side lengths of consecutively smaller squares is as follows.

Our ratio here is the square root of 2 over 2, thus forming a ratio of approximately 0.707. With our ratio in hand, the sum is simple to determine using a geometric series sum once again. Starting with the unit square as the largest square, we can find the perimeter of the total shape.

The code for this was a bit more complicated, with a new transformation matrix needing to be pushed on the stack. Then a rotation, done at 45°, then drawing the square at (0, 0) with a translation back to the right coordinates, a simple flag isRotate, is used to rotate every interval.


void setup() {
size(500, 500);
}

void drawNestedSquares(int x, int y, int s, boolean isRotate) {
if(s <= 1) {
return;
}
if(isRotate) {
pushMatrix();
translate(x, y);
rotate(radians(45));
square(0, 0, s);
popMatrix();
}
else {
square(x, y, s);
}
int s1 = (int) (sqrt(2)/2 * s);
drawNestedSquares(x, y, s1, !isRotate);
}

void draw() {
rectMode(CENTER);
drawNestedSquares(250, 250, 400, false);
save("/Users/nhradek/Desktop/NestedSquares.png");
}

Conclusion

We can find many interesting shapes that are generated by finding smaller shapes from the previous recursively. Unlike fractals, these have a whole number dimension, usually two, and the area and perimeter can be calculated using a convergent sum. These shapes are related to a geometric series with a summation using a ratio usually of a negative power such as 1/2 or 1/4. Some of these summations are related like that of a circle and squares, and thus, we can find similar sums.

In terms of applications, I don’t know other than maybe in design or structural engineering where such shapes might be of value. In mathematics, these shapes relate to other types of infinite shapes, like the Koch Curve, and are fascinating in their own right. In the end, I hope this has inspired you to look at other infinite shapes; there might be an infinite number of them, after all.

--

--