3
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ I've just specified the question. How did the author get such definitions for dtheta and theta? $\endgroup$ – Vasyl Aug 13 '16 at 7:24
  • $\begingroup$ 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. $\endgroup$ – florence Aug 13 '16 at 7:32
  • $\begingroup$ I got your calculations, however I need to understand one more thing. You said: 'If theta were incremented by a constant value, then the lines drawn would arbitrarily long as theta increases, which would not be aesthetically pleasing.' Can you explain me, why? And the other thing: 'Evidently, the writer wanted to keep the length of the line segments more or less constant.' But each step has the same length, specified in function. Can you clarify, what you mean by segment? $\endgroup$ – Vasyl Aug 13 '16 at 8:04
  • $\begingroup$ 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. $\endgroup$ – florence Aug 13 '16 at 8:13
  • $\begingroup$ Try running the program yourself with constant dtheta and see how it affects the output. $\endgroup$ – florence Aug 13 '16 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.