Here is a piece of python 3 code that draws archimedean spiral using Turtle. Equation of the spiral in polar coordinates
$$r = a + b\theta$$
def draw_spiral(t, n, length=3, a=0.1, b=0.0002):
"""Draws an Archimedian spiral starting at the origin.
Args:
n: how many line segments to draw
length: how long each segment is
a: how loose the initial spiral starts out (larger is looser)
b: how loosly coiled the spiral is (larger is looser)
http://en.wikipedia.org/wiki/Spiral
"""
theta = 0.0
for i in range(n):
t.fd(length)
dtheta = 1 / (a + b * theta)
t.lt(dtheta)
theta += dtheta
Why do we define dtheta and theta like this? I mean, I don't see why such definition should draw the spiral. So, I want to know how author got these dtheta and theta.
If theta were incremented by a constant value, then the lines drawn would arbitrarily long as theta increases, which would not be aesthetically pleasing. Evidently, the writer wanted to keep the length of the line segments more or less constant. For large $t$, the arc length we get from this incrementation is $$\int_{t}^{t+(a+bt)^{-1}}\sqrt{(a+b\theta)^2+b^2}d\theta \approx \frac{\sqrt{(a+bt)^2+b^2}}{a+bt}\approx1$$ The value for dtheta doesn't really affect whether the program will draw a spiral (unless dtheta is too big, then the resolution will be too poor), it just determines what/how many values of $\theta$ will be plotted.