wheel_on_inclined_plane.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from shapes import *
  2. print dir()
  3. print 'drawin_tool' in dir()
  4. def inclined_plane():
  5. drawing_tool.set_coordinate_system(xmin=0, xmax=15,
  6. ymin=-1, ymax=10,
  7. #axis=True,
  8. )
  9. #drawing_tool.set_grid(True)
  10. fontsize = 18
  11. from math import tan, radians
  12. theta = 30.
  13. L = 10.
  14. a = 1.
  15. B = point(a+L, 0)
  16. A = point(a, tan(radians(theta))*L)
  17. wall = CurveWall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25)
  18. angle = ArcSymbol(r'$\theta$', center=B, radius=3,
  19. start_degrees=180-theta, opening_degrees=theta,
  20. fontsize=fontsize)
  21. angle.set_linecolor('black')
  22. angle.set_linewidth(1)
  23. ground = Line((B[0]-L/10., 0), (B[0]-L/2.,0))
  24. ground.set_linecolor('black')
  25. ground.set_linestyle('dashed')
  26. ground.set_linewidth(1)
  27. r = 1 # radius of wheel
  28. help_line = Line(A, B)
  29. x = a + 3*L/10.; y = help_line(x=x)
  30. contact = point(x, y)
  31. normal_vec = point(sin(radians(theta)), cos(radians(theta)))
  32. c = contact + r*normal_vec
  33. outer_wheel = Circle(c, r)
  34. outer_wheel.set_linecolor('blue')
  35. outer_wheel.set_filled_curves('blue')
  36. hole = Circle(c, r/2.)
  37. hole.set_linecolor('blue')
  38. hole.set_filled_curves('white')
  39. wheel = Compose({'outer': outer_wheel, 'inner': hole})
  40. drawing_tool.set_linecolor('black')
  41. N_arr = Arrow3((4,2), 2)
  42. N_arr.rotate(-theta, (4,4))
  43. N_text = Text('$N$', (3.7,2.6), fontsize=fontsize)
  44. N_force = Compose({'arrow': N_arr, 'symbol': N_text})
  45. g = Gravity(c, 2.5)
  46. x_const = Line(contact, contact + point(0,4))
  47. x_const.set_linestyle('dotted')
  48. x_const.rotate(-theta, contact)
  49. x_axis_start = point(5.5, x_const(x=5.5))
  50. x_axis = Axis(x_axis_start, 2*L/5, '$x$', rotation_angle=-theta)
  51. body = Compose({'wheel': wheel, 'N force': N_force, 'g': g})
  52. fixed = Compose({'angle': angle, 'inclined wall': wall,
  53. 'wheel': wheel, 'ground': ground,
  54. 'x start': x_const, 'x axis': x_axis})
  55. fig = Compose({'body': body, 'fixed elements': fixed})
  56. #import copy
  57. #body2 = copy.deepcopy(body)
  58. #body2.translate(3, 0)
  59. #body2.draw()
  60. fig.draw()
  61. drawing_tool.savefig('tmp.png')
  62. drawing_tool.display()
  63. import time
  64. time.sleep(1)
  65. tangent_vec = point(normal_vec[1], -normal_vec[0])
  66. print 'loop'
  67. for t in range(7):
  68. drawing_tool.erase()
  69. body.translate(0.2*t*tangent_vec)
  70. time.sleep(0.5)
  71. fig.draw()
  72. drawing_tool.display()
  73. print str(fig)
  74. print repr(fig)
  75. inclined_plane()
  76. raw_input()