pendulum.yml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. !!omap
  2. - name: pendulum
  3. - parts:
  4. - name: head
  5. shapes:
  6. libraries: ['from math import tan, radians, sin, cos', 'from pysketcher import *']
  7. - name: constants
  8. shapes:
  9. H: 7.0
  10. W: 6.0
  11. - name: frame
  12. shapes:
  13. setframe: # sketch setup
  14. action: drawing_tool.set_coordinate_system(xmin=0, xmax=W,
  15. ymin=0, ymax=H,
  16. axis=False)
  17. setblackline: # default frame values and actions
  18. action: drawing_tool.set_linecolor('blue')
  19. L: 5*H/7 # length
  20. P: (W/6, 0.85*H) # rotation point
  21. a: 40 # angle
  22. vertical:
  23. formula: Line(P, P-point(0,L))
  24. style:
  25. linecolor: black
  26. linewidth: 1
  27. path:
  28. formula: Arc(P, L, -90, a)
  29. style:
  30. linecolor: black
  31. linewidth: 1
  32. angle: Arc_wText(r'$\theta$', P, L/4, -90, a, text_spacing=1/30.)
  33. #rod: Line(P, P + L*point(sin(radians(a)), -L*cos(radians(a)))) is a less reliable alternative
  34. mass_pt: path.geometric_features()['end']
  35. rod: Line(P, mass_pt)
  36. mass:
  37. formula: Circle(center=mass_pt, radius=L/20.)
  38. style:
  39. filled_curves:
  40. color: 'blue'
  41. rod_vec: rod.geometric_features()['end'] - rod.geometric_features()['start']
  42. unit_rod_vec: unit_vec(rod_vec)
  43. mass_symbol: Text('$m$', mass_pt + L/10*unit_rod_vec)
  44. length:
  45. formula: Distance_wText(P, mass_pt, '$L$') # Displace length indication
  46. transform: translate(L/15*point(cos(radians(a)), sin(radians(a))))
  47. gravity: Gravity(start=P+point(0.8*L,0), length=L/3)
  48. pendulum: "Composition({'body': mass, 'rod': rod,'vertical': vertical, 'theta': angle, 'path': path,'g': gravity, 'L': length, 'm': mass_symbol})"