Guest User

Untitled

a guest
Dec 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import matplotlib.animation as animation
  4. from IPython.display import HTML
  5.  
  6. fig, ax = plt.subplots()
  7.  
  8. def update(num):
  9. if len(round_circles) > 0:
  10. round_circles.pop().remove()
  11. epicycloids.pop().remove()
  12. points.pop().remove()
  13.  
  14. round_circle, = plt.plot(x_move[num]+xm, y_move[num]+ym, 'b-', lw=2)
  15. epicycloid, = plt.plot(x[:num+1] ,y[:num+1], 'g-', lw=2)
  16. point, = plt.plot(x[num], y[num], 'ko', markersize=4)
  17.  
  18. round_circles.append(round_circle)
  19. epicycloids.append(epicycloid)
  20. points.append(point)
  21.  
  22. theta_str = r'$\theta=$'
  23. ax.set_title(theta_str + str(theta[num]/np.pi)[:4] + str(r' $\pi$'))
  24.  
  25. ax.grid()
  26. ax.set_xlabel('x')
  27. ax.set_ylabel('y')
  28. ax.set_aspect('equal')
  29.  
  30. #plot data
  31.  
  32. theta = np.linspace(0, 4*np.pi,200)
  33. phi= np.linspace(0,2*np.pi,100)
  34.  
  35. rc=5
  36. rm=2
  37.  
  38. x = (rc+rm)*np.cos(theta)-rm*np.cos(theta*((rc+rm)/rm))
  39. y = (rc+rm)*np.sin(theta)-rm*np.sin(theta*((rc+rm)/rm))
  40. epicycloids=[]
  41. points=[]
  42.  
  43. xm = rm*np.cos(phi)
  44. ym = rm*np.sin(phi)
  45. round_circles =[]
  46.  
  47. xc = rc*np.cos(phi)
  48. yc = rc*np.sin(phi)
  49. plt.plot(xc, yc, 'k-', lw=2)#center_circle
  50.  
  51. x_move = (rc+rm)*np.cos(theta)
  52. y_move = (rc+rm)*np.sin(theta)
  53.  
  54. ani = animation.FuncAnimation(fig, update, 200, interval=100)
  55. HTML(ani.to_html5_video())
  56. #dpi=100
  57. #ani.save('episaikuroid.mp4', writer="ffmpeg",dpi=dpi)
Add Comment
Please, Sign In to add comment