beam2.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from pysketcher import *
  2. L = 8.0
  3. a = 3*L/4
  4. b = L - a
  5. H = 1.0
  6. xpos = 0.0
  7. ypos = 3.0
  8. drawing_tool.set_coordinate_system(xmin=-3, xmax=xpos+1.5*L,
  9. ymin=0, ymax=ypos+5*H,
  10. axis=False)
  11. drawing_tool.set_linecolor('blue')
  12. #drawing_tool.set_grid(True)
  13. drawing_tool.set_fontsize(16)
  14. A = point(xpos,ypos)
  15. beam = Rectangle(A, L, H)
  16. h = L/16 # size of support, clamped wall etc
  17. clamped = Rectangle(A - point(h,0) - point(0,2*h), h,
  18. 6*h).set_filled_curves(pattern='/')
  19. load = ConstantBeamLoad(A + point(0,H), L, H)
  20. load.set_linewidth(1).set_linecolor('black')
  21. load_text = Text('$w$', load.geometric_features()['mid_top'] + point(0,h/2.))
  22. B = A + point(a, 0)
  23. C = B + point(b, 0)
  24. support = SimplySupportedBeam(B, h) # pt B is simply supported
  25. R1 = Force(A-point(0,2*H), A, '$R_1$', text_spacing=1./20)
  26. R1.set_linewidth(3).set_linecolor('black')
  27. R2 = Force(B-point(0,2*H), support.geometric_features()['mid_support'],
  28. '$R_2$', text_spacing=1./20)
  29. R2.set_linewidth(3).set_linecolor('black')
  30. M1 = Moment('$M_1$', center=A + point(-H, H/2), radius=H/2,
  31. left=True, text_spacing=1/30.)
  32. M1.set_linecolor('black')
  33. ab_level = point(0, 3*h)
  34. a_dim = Distance_wText(A - ab_level, B - ab_level, '$a$')
  35. b_dim = Distance_wText(B - ab_level, C - ab_level, '$b$')
  36. dims = Composition({'a': a_dim, 'b': b_dim})
  37. symbols = Composition({'R1': R1, 'R2': R2, 'M1': M1,
  38. 'w': load, 'w text': load_text,
  39. 'A': Text('$A$', A+point(0.7*h,-0.9*h)),
  40. 'B': Text('$B$', support.geometric_features()['mid_support']-point(h,0)),
  41. 'C': Text('$C$', C+point(h/2,-h/2))})
  42. x_axis = Axis(A + point(L+h, H/2), 2*H, '$x$',).set_linecolor('black')
  43. y_axis = Axis(A + point(0,H/2), 3.5*H, '$y$',
  44. label_alignment='left',
  45. rotation_angle=90).set_linecolor('black')
  46. axes = Composition({'x axis': x_axis, 'y axis': y_axis})
  47. annotations = Composition({'dims': dims, 'symbols': symbols,
  48. 'axes': axes})
  49. fig = Composition({'beam': beam, 'support': support,
  50. 'clamped end': clamped, 'load': load})
  51. def deflection(x, a, b, w):
  52. import numpy as np
  53. R1 = 5./8*w*a - 3*w*b**2/(4*a)
  54. R2 = 3./8*w*a + w*b + 3*w*b**2/(4*a)
  55. M1 = R1*a/3 - w*a**2/12
  56. y = -(M1/2.)*x**2 + 1./6*R1*x**3 - w/24.*x**4 + \
  57. 1./6*R2*np.where(x > a, 1, 0)*(x-a)**3
  58. return y
  59. x = linspace(0, L, 101)
  60. y = deflection(x, a, b, w=1.0)
  61. y /= abs(y.max() - y.min())
  62. y += ypos + H/2
  63. elastic_line = Curve(x, y).set_linecolor('red').set_linestyle('dashed').set_linewidth(3)
  64. fig.draw()
  65. drawing_tool.display()
  66. drawing_tool.savefig('tmp_beam2_1.png')
  67. import time
  68. time.sleep(1.5)
  69. annotations.draw()
  70. drawing_tool.display()
  71. drawing_tool.savefig('tmp_beam2_2.png')
  72. time.sleep(1.5)
  73. elastic_line.draw()
  74. drawing_tool.display()
  75. drawing_tool.savefig('tmp_beam2_3.png')
  76. #beam.draw_dimensions()
  77. #test_Dashpot(xpos+2*W)
  78. input()