Mental Math: Spiraling Squares — Part 1

An exercise involving squares, infinity concepts, and the Pythagorean Theorem

Scott Fountain
5 min readNov 11, 2023
A series of spiraling squares generated via https://processing.org/

This past week, I came across Keith McNulty’s article involving daily math exercises.

Keith’s article discusses a habit I take part in. On a weekly basis, I perform routine math exercises much like I perform routine physical exercises.

After some thought, instead of writing on a data engineering topic, I thought I would discuss a math exercise I perform every now and again.

No fancy understanding of advanced mathematics is required. As long as you understand how to measure an area of a square and how to measure the sides of a right triangle via the Pythagorean Theorem, you will be fine.

The Problem

Given a series of infinite squares, calculate the total area.

An approximate 71 degree rotation is applied to each square.

At this point, most people will be like, “Scott…since the total number of squares are infinite, the total area will be infinite.”

In all fairness, that is a reasonable assumption. However, the assumption is incorrect.

Before we start, understand there are many ways to construct spiraling squares.

The approach above has an inscribed square intersecting the preceding square’s side at the 1/4 point.

This is a very important point as it will play a role in our results.

To begin the problem, let’s calculate the area of the first four squares and see what we get.

Each inscribed square intersects the preceding square’s side at the 1/4 point.

Beginning with the first square (the yellow square labeled “1”), the square has a side length of S₁.

Determining the area of the first square is easy: A₁ = S₁²

The second square is where things get spicy.

One problem — we do not have explicit information on the second square.

However, if we take a closer look, perhaps we can derive information.

Reviewing the image above, we can leverage the right triangle to derive information about the second square.

In this case, the right triangle’s hypotenuse is the length of the second square’s side. With this information, we can calculate the second square’s side via the Pythagorean Theorem.

Incidentally, by using the Pythagorean Theorem, we can derive the area of the second square: A= S²

With the Pythagorean Theorem, all elements are squared: x² + y² = r²

By visual inspection, we can conclude the second square should be smaller.

The result confirms the visual assumption as the area of the second square is five-eighths the area of the first square (i.e. 62.5%).

Okay…we have not answered the bigger question: what is the total of sum of all squares?

Do not worry, we are getting there…

Moving forward, we should evaluate the area of the third square.

An inscribed square intersects the preceding square’s side at the 1/4 point.

Once again, we can use the “right triangle” approach with the third square.

Generalization

Let’s review what we know so far.

The area of the first three squares can be summarized as…

It’s almost as if with each subsequent calculation, we are applying a factor of five-eighths.

For the sake of it all, let’s calculate the fourth square.

The trend continues. The area of the 4th square has us applying another factor of five-eighths.

Summary Review

At this point, a pattern is emerging. Reviewing our summary results…

5/8 is raised to a number that is one less than the spiral square we are evaluating.

Let’s clean up the notation…

Remember, a number raised to the zeroth power equals one.

Final generalization…

For any given square within the spiral, the area of the square can be determined as follows.

Remember, this generalization only applies to this specific construction.

Applying a different rotation would change the ratio 5/8.

Generalized Summary: Where n is greater than or equal to 1

Partial Conclusion: Measuring the Area of Any Given Square within the Spiral

While we have not determined the total area of all squares within the spiral, we have generalized the area of any given square within the spiral.

In a following article, I will discuss how we can use the generalization to tackle the original problem.

Special Thanks

Paul’s article on math exercises…

Noah’s article covers infinite shapes, the use of Sketch sourced from process.org, and sample code. Noah’s article introduced me to Sketch.

Processing’s website. Processing provides a tool called Sketch that helped me build the spiral visual.

The visual was created with the code below & can be used with Sketch.

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

void drawNestedSquares(int x, int y, float s, boolean isRotate, int i, float r) {
if(s <= 1) {
return;
}

if(isRotate) {
pushMatrix();
translate(x, y);

rotate(radians(r*(i-1)));
square(0,0,s);
popMatrix();
}
else {
square(x, y, 400);
}

/* scale subsequent square sides by the square root of 5/8 */
int s1 = (int) (sqrt(0.625) * s);

int iterator = i + 1;

int iterator_mod = iterator % 4;

/* for each iteration, assign one of 4 colors to a square */
switch(iterator_mod){
case 0:
fill(255,204,204);
break;

case 1:
fill(255,255,204);
break;

case 2:
fill(204,255,255);
break;

case 3:
fill(204,255,204);
break;
}

drawNestedSquares(x, y, s1, true, iterator,r);
}

void draw() {

rectMode(CENTER);

/* 71.56 degrees represents the arctangent of 3 */
drawNestedSquares(250, 250, 400, false, 1, 71.56);
}

--

--