# Drawing arhimedean spiral

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.
• Based on my integral for the arc length, one can see that if we increment by $\Delta \theta$ each step, then the length of the line segment (for large $\theta$) will be approximately ${\sqrt{(a+b\theta)^2+b^2}}\Delta \theta$. For large $\theta$ the $b^2$ can be neglected, and so we see that $\Delta \theta=(a+b\theta)^{-1}$ is the value which keeps the expression approximately constant. – florence Aug 13 '16 at 7:32
• The arc length of the spiral between $\theta$ and $\theta+\Delta \theta$ will be about $r*\Delta \theta$ (this is simply the length of an arc on a circle with radius $r$ and angle $\Delta \theta$) $\approx (a+b\theta)\Delta \theta$; if $\Delta \theta$ is constant, you can see that this expression will go to infinity at $\theta$ grows. If $\Delta \theta$ were constant, then each step would have the same change in $\theta$, but the line segment (that is, each piece of the spiral) drawn by the program would get longer and longer. – florence Aug 13 '16 at 8:13