You may have seen the spiral of Theodorus. It sticks a sequence of right triangles together to make a sort of spiral. Each triangle has a short side of length 1, and the hypotenuse of each triangle becomes the long leg of the next triangle as shown below.
How would you plot this spiral? At each step, you need to draw a segment of length 1, perpendicular to the hypotenuse of the previous triangle. There are two perpendicular directions, and you want to choose the one that moves counterclockwise.
If we step outside the xy plane, we can compute the cross product of the unit vector in the z direction with the vector (x, y). The cross product will be perpendicular to both, and by the right-hand rule, it will point in the counterclockwise direction.
The cross product of (0, 0, 1) and (x, y, 0) is (−y, x, 0), so the direction we want to go in the xy plane is (−y, x). We divide this vector by its length to get a vector of length 1, then add it to our previous point. [1]
Here’s Python code to draw the spiral.
import matplotlib.pyplot as plt def next_vertex(x, y): h = (x**2 + y**2)**0.5 return (x - y/h, y + x/h) plt.axes().set_aspect(1) plt.axis('off') # base of the first triangle plt.plot([0, 1], [0, 0]) N = 17 x_old, y_old = 1, 0 for n in range(1, N): x_new, y_new = next_vertex(x_old, y_old) # draw short side plt.plot([x_old, x_new], [y_old, y_new]) # draw hypotenuse plt.plot([0, x_new], [0, y_new]) x_old, y_old = x_new, y_new plt.savefig("theodorus.png")
If you’re not familiar with the plot
function above, you might expect the two arguments to plot
to be points. But the first argument is a list of x coordinates and the second a list of y coordinates.
Update: See the next post for how the hypotenuse angles fill in a circle.
More spiral posts
[1] Here’s an alternative derivation using complex numbers.
Label the current vertex in the complex plane zn. Then zn/|zn| has length 1 and points in the same direction from the origin. Multiplying this point by i rotates it a quarter turn counterclockwise, so
zn+1 = zn + i zn/|zn|.