Advertisement
yen881215

dynamic

Dec 22nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. from sympy import *
  2. import sympy as sy
  3. import math
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6.  
  7. r1 = 80
  8. r2 = 50
  9. r3 = 40
  10. r4 = 8
  11. fi = math.pi/4
  12. theta45 = 2*math.pi/3
  13. theta23max = math.pi/36
  14. theta23min = -31*math.pi/36
  15. theta34max = -math.pi/9
  16. theta34min = -13*math.pi/18
  17. a = r2
  18. b = r3
  19. all2 = []
  20. all3 = []
  21. all4 = []
  22. all5 = []
  23. for theta4 in np.arange(0,2*math.pi,math.pi/180):
  24.     c = r1 - r4*sy.cos(theta4)
  25.     d = -r4*sy.sin(theta4)
  26.     theta2 = Symbol('theta2')
  27.     theta2 = solve(c*sy.cos(theta2)+d*sy.cos(theta2)-(a**2+c**2+d**2-b**2)/(2*a),theta2)
  28.     for i in range(0,len(theta2)):
  29.         try:
  30.             if theta2[i] < 2*math.pi:
  31.                 pass
  32.         except TypeError:
  33.             continue
  34.         if theta2[i] < 2*math.pi:
  35.             theta3_1 = Symbol('theta3_1')
  36.             theta3_2 = Symbol('theta3_2')
  37.             theta3_1 = solve(sy.cos(theta3_1)-((c-a*sy.cos(theta2[i]))/b),theta3_1)
  38.             theta3_2 = solve(sy.sin(theta3_2)-((d-a*sy.sin(theta2[i]))/b),theta3_2)
  39.             premin = 10000
  40.             for k in theta3_1:
  41.                 for j in theta3_2:
  42.                     value = abs(j-k)
  43.                     try:
  44.                         if value < premin:
  45.                             pass
  46.                     except TypeError:
  47.                         continue
  48.                     if value < premin:
  49.                         premin = value
  50.                         theta3 = (k + j)/2
  51.         else:
  52.             continue
  53.         theta5 = theta45 + theta4
  54.         if theta5 > 2*math.pi:
  55.             theta5 = theta5 - 2*math.pi
  56.         all5.append(theta5)
  57.         all2.append(theta2[i])
  58.         all3.append(theta3)
  59.         all4.append(theta4)
  60.  
  61. fig = plt.figure()
  62. ax1 = fig.add_subplot(111)
  63. ax1.set_title('θ3-θ5')
  64. plt.xlabel('θ5')
  65. plt.ylabel('θ3')
  66. ax1.scatter(all3,all5,c = 'r',marker = 'o')
  67. plt.legend('x1')
  68. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement