wheel_on_inclined_plane.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. from shapes import *
  2. def inclined_plane():
  3. theta = 30.
  4. L = 10.
  5. a = 1.
  6. xmin = 0
  7. ymin = -3
  8. drawing_tool.set_coordinate_system(xmin=xmin, xmax=xmin+1.5*L,
  9. ymin=ymin, ymax=ymin+L,
  10. #axis=True,
  11. )
  12. #drawing_tool.set_grid(True)
  13. fontsize = 18
  14. from math import tan, radians
  15. B = point(a+L, 0)
  16. A = point(a, tan(radians(theta))*L)
  17. wall = Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25)
  18. angle = Arc_wText(r'$\theta$', center=B, radius=3,
  19. start_angle=180-theta, arc_angle=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 = Composition({'outer': outer_wheel, 'inner': hole})
  40. drawing_tool.set_linecolor('black')
  41. N = Force(contact - 2*r*normal_vec, contact, r'$N$', text_pos='start')
  42. #text_alignment='left')
  43. mg = Gravity(c, 3*r, text='$Mg$')
  44. x_const = Line(contact, contact + point(0,4))
  45. x_const.set_linestyle('dotted')
  46. x_const.rotate(-theta, contact)
  47. # or x_const = Line(contact-2*r*normal_vec, contact+4*r*normal_vec).set_linestyle('dotted')
  48. x_axis = Axis(start=contact+ 3*r*normal_vec, length=4*r,
  49. label='$x$', rotation_angle=-theta)
  50. body = Composition({'wheel': wheel, 'N': N, 'mg': mg})
  51. fixed = Composition({'angle': angle, 'inclined wall': wall,
  52. 'wheel': wheel, 'ground': ground,
  53. 'x start': x_const, 'x axis': x_axis})
  54. fig = Composition({'body': body, 'fixed elements': fixed})
  55. fig.draw()
  56. drawing_tool.savefig('tmp.png')
  57. drawing_tool.display()
  58. import time
  59. time.sleep(1)
  60. tangent_vec = point(normal_vec[1], -normal_vec[0])
  61. import numpy
  62. time_points = numpy.linspace(0, 1, 31)
  63. def position(t):
  64. """Position of center point of wheel."""
  65. return c + 7*t**2*tangent_vec
  66. def move(t, fig, dt=None):
  67. x = position(t)
  68. x0 = position(t-dt)
  69. displacement = x - x0
  70. fig['body'].translate(displacement)
  71. animate(fig, time_points, move, pause_per_frame=0,
  72. dt=time_points[1]-time_points[0])
  73. print str(fig)
  74. print repr(fig)
  75. inclined_plane()
  76. raw_input()