Lissajous figures

Import the required libraies


In [0]:
import numpy as np
import pylab as pl

We will need to calculate the LCM of the time periods for the two oscillators. Hence we define the LCM of two integers.


In [0]:
def gcd(a,b):
  if a<b:
    a,b = b,a
  while b>0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

The parameters of the oscillators. You need not change anything starting from the time periods.

If the graph is not smooth enough, smoothen it.


In [0]:
# amplitudes
A = np.array([1,1])

# frequencies
f = np.array([3,5])

# phased difference
delta = 0*np.pi/4

# time periods
T = 1/f

# the time grid
tmin, tmax = 0, lcm(f[0], f[1])
dt=(tmax-tmin)/2000
t=np.arange(tmin, tmax+dt, dt)

In [88]:
# the oscillations - mutually perpendicular
x = A[0]*np.cos(2*np.pi*f[0]*t )
y = A[1]*np.sin(2*np.pi*f[1]*t+delta)

fig = pl.figure(1, figsize=(7,7))
ax = fig.add_subplot(111)
pl.plot(x,y)
pl.grid('on')
d=1.1*max(A)
pl.xlim((-d, d))
pl.ylim((-d, d))
ax.set_aspect(1)



In [0]: