Generating Spirals

maths
Author

Ishaan Mukherjee

Published

January 15, 2022

Generating Spirals

Using polar co-ordinates to better understand circles and spirals

Code
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation, rc

%matplotlib inline 

rc('animation', html='html5')

Circle

If a line is rotated about a point, any fixed point on the line traces out a circle. This is illustrated in the animation below where a green point and a red point on the blue stick are seen to trace out their circles when the stick completes a full rotation.

Code
a1 = 5
a2 = 10

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
ax.set_aspect('equal')

line1, = ax.plot([0, 0],[0,a2], 'b', lw=2)
line2, = ax.plot([],[], 'g.', lw=1)
line3, = ax.plot([],[], 'r.', lw=1)

rs2 = []
rs3 = []
thetas = []
ax.set_ylim(0, a2*1.10)

def animate(theta):
    line1.set_data([theta, theta],[0,a2])
    rs2.append(a1)
    rs3.append(a2)
    thetas.append(theta)
    line2.set_data(thetas, rs2)
    line3.set_data(thetas, rs3)
    return line1,line2,line3

# create animation using the animate() function
frames = np.linspace(0,2*np.pi,60)
anim = animation.FuncAnimation(fig, animate, frames=frames, \
                                      interval=50, blit=True, repeat=False)

plt.close() # Important: Gives an additional figure if omitted

anim

Spirals

But if a point is allowed to be moved outwards along the stick while the stick is being rotated, it traces out a spiral.

If the outward movement is directly proportional to the angle of rotation, we get a Linear spiral or Archimedean spiral (blue). In other words, the point’s linear velocity along the stick is constant just like the angular velocity of the stick’s rotation. In polar co-ordinates \[r = a\theta\]

If the linear velocity along the stick increases exponentially with the angle of rotation, we get a Logarithmic spiral (red). In polar co-ordinates \[ r = ae^{b\theta} \]

Code
fig = plt.figure()

ax = fig.add_subplot(111, projection='polar')
ax.set_aspect('equal')


line1, = ax.plot([],[],'b.', lw=1)
line2, = ax.plot([],[],'r.', lw=1)

# Params
# Note N = 6, a = 1.00, b = 0.20, ax.set_ylim(0,50) works well for illustration
N = 6
a = 1.00
b = 0.20
R_MIN = 0
R_MAX = 50


N_PI = N * np.pi
rs1 = []
rs2 = []
thetas = []
ax.set_ylim(R_MIN,R_MAX)


def animate(theta):
    rs1.append(a*theta)
    rs2.append(a*np.exp(b*theta))
    thetas.append(theta)
    line1.set_data(thetas, rs1)
    line2.set_data(thetas, rs2)
    return line1,line2

# create animation using the animate() function
anim_rt_spirals = animation.FuncAnimation(fig, animate, frames=np.arange(0.0, N_PI, 0.1), \
                                      interval=20, blit=True, repeat=True)

plt.close()

anim_rt_spirals