Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- R = 3
- def circle(a, b, r):
- T = 100
- x, y = [0]*T, [0]*T
- for i,theta in enumerate(np.linspace(0,2*np.pi,T)):
- x[i] = a + r*np.cos(theta)
- y[i] = b + r*np.sin(theta)
- return x, y
- def gen():
- for theta in np.linspace(0, 20*np.pi, 150):
- yield R*(theta-np.sin(theta)), R*(1-np.cos(theta)), R*theta
- fig = plt.figure(figsize=(6, 3))
- ax = fig.add_subplot(111)
- ax.set_ylim(0, 20)
- ax.set_xlim(0, 70)
- ax.set_xlabel('x')
- ax.set_ylabel('y')
- ax.set_aspect('equal')
- #ax.grid()
- #time_text = ax.text(0.05, 0.8, '', transform=ax.transAxes)
- cycloid, = ax.plot([], [], 'r-', lw=2)
- line, = ax.plot([], [], 'y-', lw=2)
- circle_line, = ax.plot([], [], 'g', lw=2)
- point, = ax.plot([], [], 'bo', ms=4)
- xx, yy = [], []
- def func(data):
- x, y, Rt = data
- #time_text.set_text(r'$\theta$ = %.2f $\pi$' % (Rt / np.pi))
- xx.append(x)
- yy.append(y)
- cx, cy = circle(Rt, R, R)
- cycloid.set_data(xx, yy)
- line.set_data((x, Rt), (y, R))
- circle_line.set_data(cx, cy)
- point.set_data(x, y)
- ani = animation.FuncAnimation(fig, func, gen, blit=False, interval=50)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement