4
$\begingroup$

I was generating artistic depictions of mathematical concepts by programming for fun, I made some pictures of Pythagorean Spiral, and I noticed this pattern if I only show perfect squares:

Pythagorean Spiral depicting perfect squares up to 256:

enter image description here

Perfect squares up to 512:

enter image description here

Perfect squares up to 1024:

enter image description here

Perfect squares up to 2048:

enter image description here

I used the following function to calculate the spiral:

def pythogorean_spiral(iterations, mode='rim', num_colors=12, condition=None):
    assert mode in ('rim', 'radial', 'triangles')
    if condition:
        assert condition in filters
        filtered = condition(iterations)
    step = 1530/num_colors
    color_values = ['#'+spectrum_position(round(step*i), 1) for i in range(num_colors)]
    colors = ['#ff0000']
    collection = []
    if not condition or 0 in filtered:
        if mode == 'rim':
            collection.append([(1, 0), (1, 1)])
            
        if mode == 'radial':
            collection.append([(0, 0), (1, 0)])
        
        elif mode == 'triangles':
            collection.append([(0, 0), (1, 0), (1, 1)])
    
    cur_x, cur_y = 1, 1
    for i in range(1, iterations):
        radius = (cur_x ** 2 + cur_y ** 2) ** .5
        new_radius = radius + 1
        angle = atan2(cur_x, cur_y)
        new_x, new_y = new_radius*cos(angle), new_radius*sin(angle)
        new_x, new_y = rotate((new_x, new_y), 90, (cur_x, cur_y))
        color = color_values[i % num_colors]
        colors.append(color)
        if not condition or i in filtered:
            if mode  == 'rim':
                collection.append([(cur_x, cur_y), (new_x, new_y)])
                
            if mode == 'radial':
                collection.append([(0, 0), (cur_x, cur_y)])
            
            elif mode == 'triangles':
                collection.append([(0, 0), (cur_x, cur_y), (new_x, new_y)])
        
        cur_x, cur_y = new_x, new_y
    
    result = {'colors': colors}
    if mode  == 'rim':
        result['rim'] = collection
    
    if mode == 'radial':
        result['radial'] = collection
    
    elif mode == 'triangles':
        result['triangles'] = collection
    
    return result

Full script

Why am I seeing the triple spiral pattern?


Here is the data depicted in the image, in Python dictionary format, the key is the number, and the value is its position.

In [176]: find_squares(2048)
Out[176]:
{0: (1, 0),
 1: (1, 1),
 4: (-1.6308097207961918, 1.5298560894922917),
 9: (-1.497112501918127, -2.7854360801498306),
 16: (4.074022642113989, -0.6343023817884941),
 25: (-1.1072688801027475, 4.977344234343855),
 36: (-4.98458532826389, -3.4862457035120658),
 49: (5.996732853004965, -3.7468913901647802),
 64: (1.2030383665443862, 7.971994649309683),
 81: (-8.74302530802115, -2.3578609932100782),
 100: (6.317606591629188, -7.815871477538745),
 121: (5.025225140018225, 9.83601099491705),
 144: (-12.02537661686118, 0.6247537295991847),
 169: (4.7131951151331055, -12.156717970187723),
 196: (9.852134360350037, 9.996771906251038),
 225: (-14.09884120422741, 5.217535500404312),
 256: (1.119993543058584, -15.992048476149222),
 289: (14.986552417661628, 8.08722737609624),
 324: (-14.34564731859593, 10.917985299974568),
 361: (-4.240153608700732, -18.547805729374634),
 400: (19.62024563990485, 4.005741008826664),
 441: (-12.349124780077803, 17.014673583882512),
 484: (-10.871585332769126, -19.152248754449722),
 529: (22.929824939835186, -2.055025116273555),
 576: (-7.958753928923706, 22.66402956005053),
 625: (-18.049465629543615, -17.326765147826205),
 676: (24.17841787504091, -9.612705605598585),
 729: (-1.3269058233345064, 26.985909674050397),
 784: (-24.89305639538484, -12.858294727381011),
 841: (22.812021983982696, -17.93353431430349),
 900: (7.087529794682105, 29.16790910246232),
 961: (-30.460426219812412, -5.844863942588621),
 1024: (18.5398249709077, -26.101243074767932),
 1089: (16.550145885300477, 28.56733573813433),
 1156: (-33.85505726799531, 3.2916709101562596),
 1225: (11.389197702942742, -33.11021255871532),
 1296: (26.114611762933436, 24.799738959740765),
 1369: (-34.33332875841694, 13.828323700524258),
 1444: (1.7284388687767098, -37.97383966728841),
 1521: (34.713383531937104, 17.80396033933651),
 1600: (-31.401435769992876, 24.798182021733684),
 1681: (-9.746528349261542, -39.83723365316765),
 1764: (41.26708260884942, 7.875778879224264),
 1849: (-24.891018197164836, 35.07758847338917),
 1936: (-22.06172637665742, -38.08254494229001),
 2025: (44.80188956600656, -4.334823100820575)}

I don't feel like explaining things, so here is the Wikipedia article.

Here is the full picture of the spiral with 256 triangles:

enter image description here

Picture of triangles in the spiral corresponding to perfect squares up to 256:

enter image description here


I made another image which is more descriptive, and the data it displays does indeed corroborate the accepted answer's theory:

enter image description here

$\endgroup$
5
  • 4
    $\begingroup$ I'm not sure I understand exactly what each of the lines represents. Is it that the length represents the value and the colour represents something else? And how is the position chosen exactly? $\endgroup$
    – user905694
    Commented May 29, 2022 at 12:25
  • $\begingroup$ How does the small orange triangle in your final figure ("Picture of triangles in the spiral corresponding to perfect squares up to 256") correspond to a perfect square? Its radial leg has length $\sqrt{2}$ and its hypotenuse has length $\sqrt{3}$. Likewise, the small yellow triangle has radial leg $\sqrt{5}$ and hypotenuse $\sqrt{6}$. $\endgroup$
    – Blue
    Commented May 29, 2022 at 12:53
  • $\begingroup$ @Blue He starts from $0$ perhaps having a radial leg of length $\sqrt{1}$, so the orange triangle would correspond to $1$ which is a perfect square, and the yellow triangle would correspond to $4$. $\endgroup$
    – user905694
    Commented May 29, 2022 at 13:03
  • $\begingroup$ @CarefreeXplorer: Ah! The indices are perfect squares. I mistakenly thought the triangles' geometry mattered. Fair enough. $\endgroup$
    – Blue
    Commented May 29, 2022 at 13:09
  • $\begingroup$ I don't understand. It looks as if your 5th picture's spiral arises only from the way you've drawn it, not because of any underlying phenomenon. In the other 5 of your first 6 pictures I see rays of various lengths and directions but no spiral. $\endgroup$
    – Rosie F
    Commented May 31, 2022 at 7:28

2 Answers 2

3
$\begingroup$

The angle of the $n$th triangle $\varphi_n$ satisfies $\tan \varphi_n = 1/\sqrt{n}$. The total angle spanned by the first $N$ triangles can be shown to be $$ A(N) =\sum_{n \leq N} \varphi_n = \sum_{n \leq N} \arctan(1/\sqrt{n}) = 2 \sqrt{N} + e(N), $$ where $e(N)$ is an error term with $$ \lim_{N \to \infty} e(N) = \widetilde{e} = -2.1577\ldots$$

Consider large squares $$ a^2, (a+1)^2, (a+2)^2, (a + 3)^2, \ldots$$ In your plotting system, the line plotted for these squares would be $$ \begin{align} A(a^2) &\approx 2a + \widetilde{e}\\ A((a+1)^2) &\approx 2a + 2 + \widetilde{e}\\ A((a+2)^2) &\approx 2a + 4 + \widetilde{e}\\ A((a + 3)^2) &\approx 2a + 6 + \widetilde{e}. \end{align}$$ The reason why the squares $a^2$ and $(a+3)^2$ seem to belong to one spiral arm is because $$2a + 6 + \widetilde{e} \approx 2a + 2\pi + \widetilde{e},$$ and thus the angles of squares of integers differing by $3$ are almost the same. And as $6 < 2 \pi$, the spirals will seem to slowly spiral "backwards" (i.e. clockwise, as the spiral is build counterclockwise).

$\endgroup$
3
$\begingroup$

As far as I can tell, the impression of $3$ distinct spirals is caused by the varying lengths of the lines.

We can visualise the lines to be in a $3$-dimensional space where each time the spiral completes a revolution around the origin, it begins in a new layer on top of the previous layer. It happens to be that it takes $3$ lines to complete one revolution. Each layer hence has $3$ lines of varying length. If you now consider the aerial view of this $3$-dimensional space, we will see $3$ distinct regions with the lines in each region to be of increasing length.

Let $T_n$ be a sequence such that the $n$th term of the sequence is the total number of triangles upto the $n$th revolution of the spiral. We now need to prove that there are $3$ perfect squares between $T_{n + 1}$ and $T_{n}$.

Since the growth rate of $T_n$ is approximately $18n$, we can model $T_n$ by the equation $T_n = 9n(n + 1)$. Mathematically, we hence need to prove

$$\left\lfloor \sqrt{T_{n + 1}} \right\rfloor - \left\lfloor \sqrt{T_{n}} \right\rfloor = 3$$ $$\left\lfloor \sqrt{9(n + 1)(n + 2)} \right\rfloor - \left\lfloor \sqrt{9n(n + 1)} \right\rfloor = \left\lfloor 3\sqrt{(n + 1)(n + 2)} \right\rfloor - \left\lfloor 3\sqrt{n(n + 1)} \right\rfloor$$ $$\sqrt{n(n + 1)} + 1 \approx \sqrt{(n+1)(n + 2)}$$ $$\left\lfloor 3\sqrt{(n + 1)(n + 2)} \right\rfloor - \left\lfloor 3\sqrt{n(n + 1)} \right\rfloor \approx \left\lfloor 3x + 3 \right\rfloor - \left\lfloor 3x \right\rfloor = 3$$

$\blacksquare$

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .