Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import matplotlib.pyplot as plt
- g = 9.806
- a_x = 0
- a_y = g * (-1)
- angle = float(input("input the number of the angle degree: "))
- the_weight = float(input("input the number of the weight in (KG): "))
- time_step = float(input("input the number of the timestep in (sec): "))
- v0 = float(input("input the number of the v0 (m/s): "))
- considering_path = int(input("using the path? "))
- vx_0 = v0 * (math.cos(math.radians(angle)))
- vy_0 = v0 * (math.sin(math.radians(angle)))
- x0 = 0
- y0 = 0
- vx = [vx_0]
- x_list = [0]
- vy = [vy_0]
- y_list = [0 + (vy_0 * 0) - (0.5 * a_y * 0)]
- time_array = [0]
- n = 0
- if considering_path == 0:
- while y_list[n] >= 0:
- try:
- vx.append(0)
- x_list.append(0)
- vy.append(0)
- y_list.append(0)
- time_array.append(0)
- time_array[n + 1] = time_array[n] + time_step
- vx[n + 1] = vx[n] + (a_x * time_step)
- vy[n + 1] = vy[n] + (a_y * time_step)
- x_list[n + 1] = x_list[n] + vx[n + 1] * time_step
- y_list[n + 1] = y_list[n] + vy[n + 1] * time_step
- n += 1
- except:
- print("failed")
- elif considering_path == 1:
- input_d = float(input("input the path: "))
- v = math.sqrt((vx[n] ** 2) + (vy[n] ** 2))
- a_x = (-1 * (input_d / the_weight)) * v * vx[n]
- a_y = (g * -1) - (input_d / the_weight) * v * vy[n]
- while y_list[n] >= 0:
- try:
- vx.append(0)
- x_list.append(0)
- vy.append(0)
- y_list.append(0)
- time_array.append(0)
- time_array[n + 1] = time_array[n] + time_step
- vx[n + 1] = vx[n] + (a_x * time_step)
- vy[n + 1] = vy[n] + (a_y * time_step)
- x_list[n + 1] = x_list[n] + vx[n + 1] * time_step
- y_list[n + 1] = y_list[n] + vy[n + 1] * time_step
- n += 1
- except:
- print("failed")
- for i in range(len(y_list)):
- print("time: ", time_array[i])
- print("x position: ", x_list[i])
- print("y position: ", y_list[i])
- print("vx: ", vx[i])
- print("vy: ", vy[i])
- print("")
- print("")
- plt.plot(x_list, y_list)
- plt.xlabel('X position')
- plt.ylabel('Y position')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement