Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from matplotlib.animation import FuncAnimation
- fig, ax = plt.subplots()
- xdata = []
- ydata = []
- x2data = []
- y2data = []
- R1 = 4
- r2 = 2
- ln, = plt.plot([], [], lw=1)
- ln2, = plt.plot([], [], lw=1)
- ln3, = plt.plot([], [], 'k-')
- def init():
- ax.set_xlim(-4*np.pi, 4*np.pi)
- ax.set_ylim(-10, 10)
- return ln,
- def update(t):
- rx = (R1+r2)*np.cos(t)-r2*np.cos((R1+r2)*(t/r2)) # punkt cyklo
- ry = (R1+r2)*np.sin(t)-r2*np.sin((R1+r2)*(t/r2))
- xdata.append(rx)
- ydata.append(ry)
- smx = (R1+r2)*np.cos(t)
- smy = (R1+r2)*np.sin(t) # środek małego
- t2 = np.linspace(0, 3*np.pi, 100)
- x = smx + r2*np.cos(t2) # caly maly
- y = smy + r2*np.sin(t2)
- rx = (R1+r2)*np.cos(t)-r2*np.cos((R1+r2)*(t/r2))
- ry = (R1+r2)*np.sin(t)-r2*np.sin((R1+r2)*(t/r2))
- ln.set_data(xdata, ydata) # cyklo
- ln2.set_data(x, y) # maly
- Xl = [rx, smx]
- Yl = [ry, smy]
- ln3.set_data(Xl, Yl) # punkt
- return ln, ln2, ln3
- # R1 = int(input("Podaj R: "))
- # r2 = int(input("Podaj r: "))
- ani = FuncAnimation(fig, update, frames=np.linspace(0, 3*np.pi, 100),
- init_func=init, blit=True, repeat=False)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement