import numpy as np
from numpy.fft import fft,ifft
import pylab as plt

t = np.linspace(0.01,2*np.pi,100)
dt = t[1] - t[0]
a = 1
b = 4
w = 1 + np.pi/(2*t)
x = a * np.sin(w*t)
y = b * np.sin(t)
#x = a * np.sin(t + np.pi/2)
#y = b * np.sin(t)
#plt.plot(x,y)
#plt.axis('equal')
#plt.show()

#w*t = t + np.pi/2
#w = 1 + np.pi/(2t)


#resonans
h = 0
while True:
    dx = -a * np.sin(t)
    dy = b * np.cos(t)
    dl = np.sqrt(dx**2 + dy**2)
    L = (dl*dt).sum()

    x = a * np.cos(t)
    y = a * np.sin(t)
    d = 2 * a * np.pi
    d += 4 * (b-a) - h
    err = L - d
    h -= 0.01 * err
    print(np.sum(err**2))
    
err = 1 - ((x/a)**2 + (y/b)**2)
c = abs(fft(x))


