beam2.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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=True)
  11. drawing_tool.set_linecolor('blue')
  12. drawing_tool.set_grid(True)
  13. fontsize=16
  14. A = point(xpos,ypos)
  15. main = 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, 6*h).set_filled_curves(pattern='/')
  18. load = ConstantBeamLoad(A + point(0,H), L, H)
  19. load.set_linewidth(1).set_linecolor('black')
  20. load_text = Text('$w$', load.mid_top + point(0,h/2.), fontsize=fontsize)
  21. B = A + point(a, 0)
  22. C = B + point(b, 0)
  23. support = SimplySupportedBeam(B, h)
  24. R1 = Force(A-point(0,2*H), A, '$R_1$',
  25. fontsize=fontsize, symbol_spacing=1./20)
  26. R1.set_linewidth(3).set_linecolor('black')
  27. R2 = Force(B-point(0,2*H), support.mid_support,
  28. '$R_2$', fontsize=fontsize, symbol_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, fontsize=fontsize,
  32. symbol_spacing=1/30.)
  33. M1.set_linecolor('black')
  34. ab_level = point(0, 3*h)
  35. a_dim = Distance_wText(A - ab_level, B - ab_level, '$a$',
  36. fontsize=fontsize)
  37. b_dim = Distance_wText(B - ab_level, C - ab_level, '$b$',
  38. fontsize=fontsize)
  39. dims = Compose({'a': a_dim, 'b': b_dim})
  40. symbols = Compose({'R1': R1, 'R2': R2, 'M1': M1,
  41. 'w': load, 'w text': load_text,
  42. 'A': Text('$A$', A+point(h/2,-h/2)),
  43. 'B': Text('$B$', support.mid_support-point(h,0)),
  44. 'C': Text('$C$', C+point(h/2,-h/2))})
  45. x_axis = Axis(A + point(L+h, H/2), 2*H, '$x$',
  46. fontsize=fontsize).set_linecolor('black')
  47. y_axis = Axis(A + point(0,H/2), 3.5*H, '$y$',
  48. below=False, rotation_angle=90,
  49. fontsize=fontsize).set_linecolor('black')
  50. axes = Compose({'x axis': x_axis, 'y axis': y_axis})
  51. annotations = Compose({'dims': dims, 'symbols': symbols,
  52. 'axes': axes})
  53. beam = Compose({'main': main, 'support': support,
  54. 'clamped end': clamped, 'load': load})
  55. def deflection(x, a, b, w):
  56. import numpy as np
  57. R1 = 5./8*w*a - 3*w*b**2/(4*a)
  58. R2 = 3./8*w*a + w*b + 3*w*b**2/(4*a)
  59. M1 = R1*a/3 - w*a**2/12
  60. y = -(M1/2.)*x**2 + 1./6*R1*x**3 - w/24.*x**4 + \
  61. 1./6*R2*np.where(x > a, 1, 0)*(x-a)**3
  62. return y
  63. x = linspace(0, L, 101)
  64. y = deflection(x, a, b, w=1.0)
  65. y /= abs(y.max() - y.min())
  66. y += ypos + H/2
  67. elastic_line = Curve(x, y).set_linecolor('red').set_linestyle('dashed').set_linewidth(3)
  68. beam.draw()
  69. drawing_tool.display()
  70. drawing_tool.savefig('tmp_beam2_1.png')
  71. import time
  72. time.sleep(1.5)
  73. annotations.draw()
  74. drawing_tool.display()
  75. drawing_tool.savefig('tmp_beam2_1.png')
  76. time.sleep(1.5)
  77. elastic_line.draw()
  78. drawing_tool.display()
  79. drawing_tool.savefig('tmp_beam2_3.png')
  80. #beam.draw_dimensions()
  81. #test_Dashpot(xpos+2*W)
  82. raw_input()