wheel_on_inclined_plane.py 2.7 KB

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