import numpy as np import matplotlib.pyplot as plt radius = 2 angularSpeed = .1 angle_ini = np.pi/6 angle_max = 2.3 * 2*np.pi N_images = 300 T = np.linspace(0, angle_max/angularSpeed, N_images) # vector: time for each image L = angle_max*radius ## figure and axes fig = plt.figure(figsize=(14, 6)) axis = fig.add_subplot(111, aspect='equal', frameon=False) axis.set_xticks([]) axis.set_yticks([]) # axis.set_xlim(-1, 10), axis.set_ylim(-.3, 2*1.1*radius) ## line (along which the movement takes place) axis.plot([1.2*radius, -L - 1.2*radius], [0, 0], color='k') ## initial circle Theta = np.linspace(0, 2*np.pi, 300) x_circle = radius*np.cos(Theta) y_circle = radius + radius*np.sin(Theta) circle = axis.plot(x_circle, y_circle, linewidth=.5, color='b')[-1] ## curve (cycloid) X = radius*np.cos(angle_ini + angularSpeed*T) - angularSpeed*T*radius Y = radius + radius*np.sin(angle_ini + angularSpeed*T) axis.plot(X, Y, linewidth=.5, color='r') ## initial point point = axis.plot(X[0], Y[0], marker='o', ms='3', color=(.6, 0, 0))[-1] ## animation for n in range(N_images): t = T[n] # the circle is modified circle.set_xdata(x_circle - angularSpeed*t*radius) circle.set_ydata(y_circle) # the point is modified point.set_xdata(X[n]) point.set_ydata(Y[n]) # pause in the execution of for (to see the image) plt.pause(0.05) plt.show()