Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.animation import FuncAnimation
  4.  
  5.  
  6. fig, ax = plt.subplots()
  7. xdata = []
  8. ydata = []
  9. x2data = []
  10. y2data = []
  11. R1 = 4
  12. r2 = 2
  13. ln, = plt.plot([], [], lw=1)
  14. ln2, = plt.plot([], [], lw=1)
  15. ln3, = plt.plot([], [], 'k-')
  16.  
  17.  
  18. def init():
  19. ax.set_xlim(-4*np.pi, 4*np.pi)
  20. ax.set_ylim(-10, 10)
  21. return ln,
  22.  
  23.  
  24. def update(t):
  25. rx = (R1+r2)*np.cos(t)-r2*np.cos((R1+r2)*(t/r2)) # punkt cyklo
  26. ry = (R1+r2)*np.sin(t)-r2*np.sin((R1+r2)*(t/r2))
  27. xdata.append(rx)
  28. ydata.append(ry)
  29. smx = (R1+r2)*np.cos(t)
  30. smy = (R1+r2)*np.sin(t) # środek małego
  31.  
  32. t2 = np.linspace(0, 3*np.pi, 100)
  33. x = smx + r2*np.cos(t2) # caly maly
  34. y = smy + r2*np.sin(t2)
  35.  
  36. rx = (R1+r2)*np.cos(t)-r2*np.cos((R1+r2)*(t/r2))
  37. ry = (R1+r2)*np.sin(t)-r2*np.sin((R1+r2)*(t/r2))
  38.  
  39. ln.set_data(xdata, ydata) # cyklo
  40. ln2.set_data(x, y) # maly
  41. Xl = [rx, smx]
  42. Yl = [ry, smy]
  43. ln3.set_data(Xl, Yl) # punkt
  44.  
  45. return ln, ln2, ln3
  46.  
  47.  
  48. # R1 = int(input("Podaj R: "))
  49. # r2 = int(input("Podaj r: "))
  50. ani = FuncAnimation(fig, update, frames=np.linspace(0, 3*np.pi, 100),
  51. init_func=init, blit=True, repeat=False)
  52. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement