Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. import math
  2. import matplotlib.pyplot as plt
  3.  
  4.  
  5. g = 9.806
  6. a_x = 0
  7. a_y = g * (-1)
  8. angle = float(input("input the number of the angle degree: "))
  9. the_weight = float(input("input the number of the weight in (KG): "))
  10. time_step = float(input("input the number of the timestep in (sec): "))
  11. v0 = float(input("input the number of the v0 (m/s): "))
  12. considering_path = int(input("using the path? "))
  13. vx_0 = v0 * (math.cos(math.radians(angle)))
  14. vy_0 = v0 * (math.sin(math.radians(angle)))
  15. x0 = 0
  16. y0 = 0
  17.  
  18. vx = [vx_0]
  19. x_list = [0]
  20.  
  21. vy = [vy_0]
  22. y_list = [0 + (vy_0 * 0) - (0.5 * a_y * 0)]
  23.  
  24. time_array = [0]
  25. n = 0
  26.  
  27. if considering_path == 0:
  28.     while y_list[n] >= 0:
  29.         try:
  30.             vx.append(0)
  31.             x_list.append(0)
  32.             vy.append(0)
  33.             y_list.append(0)
  34.             time_array.append(0)
  35.             time_array[n + 1] = time_array[n] + time_step
  36.             vx[n + 1] = vx[n] + (a_x * time_step)
  37.             vy[n + 1] = vy[n] + (a_y * time_step)
  38.             x_list[n + 1] = x_list[n] + vx[n + 1] * time_step
  39.             y_list[n + 1] = y_list[n] + vy[n + 1] * time_step
  40.             n += 1
  41.         except:
  42.             print("failed")
  43.  
  44. elif considering_path == 1:
  45.     input_d = float(input("input the path: "))
  46.     v = math.sqrt((vx[n] ** 2) + (vy[n] ** 2))
  47.     a_x = (-1 * (input_d / the_weight)) * v * vx[n]
  48.     a_y = (g * -1) - (input_d / the_weight) * v * vy[n]
  49.     while y_list[n] >= 0:
  50.         try:
  51.             vx.append(0)
  52.             x_list.append(0)
  53.             vy.append(0)
  54.             y_list.append(0)
  55.             time_array.append(0)
  56.             time_array[n + 1] = time_array[n] + time_step
  57.             vx[n + 1] = vx[n] + (a_x * time_step)
  58.             vy[n + 1] = vy[n] + (a_y * time_step)
  59.             x_list[n + 1] = x_list[n] + vx[n + 1] * time_step
  60.             y_list[n + 1] = y_list[n] + vy[n + 1] * time_step
  61.             n += 1
  62.         except:
  63.             print("failed")
  64.  
  65. for i in range(len(y_list)):
  66.     print("time: ", time_array[i])
  67.     print("x position: ", x_list[i])
  68.     print("y position: ", y_list[i])
  69.     print("vx: ", vx[i])
  70.     print("vy: ", vy[i])
  71.     print("")
  72.     print("")
  73.  
  74. plt.plot(x_list, y_list)
  75. plt.xlabel('X position')
  76. plt.ylabel('Y position')
  77. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement