Sharedprojects / group_11 / Group 11's Project.ipynbOpen in CoCalc
Authors: Tavjot Dhanoa, Jordan Fu, Gareth Jones, Ciaran Robinson, Michael Xiong
Views : 19
In [1]:
#Pong Shot Velocity #Input an angle you'd like to shot at, and the program tells you how much velocity you need import numpy as np import matplotlib.pyplot as plt import math from math import sin, cos angle_deg = 30 angle = (angle_deg*np.pi)/180 #converts degrees to radians v0 = 0 time = 10 #max shot time t = np.linspace(0,time,400) #start, stop, num dt = t[1]-t[0] #time slice g=-9.8 m=1 #mass of object L = 1.83 #table length x = np.linspace(0,L,100) #array for x values of table H = .76 #table height h=np.zeros(100) h.fill(H)#array for y values of table T=0 y0 = 2 #height of ball release, typically eye height x0 = 0 vg = 0 y_release = y0-H y_list = [y0] x_list = [x0] v_list = [vg] a_list = [g] #solving for v0: v0 = sqrt((g*L**2)/(2*(-y_release-(np.tan(angle)*L))))/np.cos(angle) #solving for x and y components of v0 vx = v0*np.cos(angle) vy = v0*np.sin(np.pi-angle) for i in range(1, len(t)): vg += m*g*dt y0 += (vg + vy)* dt x0 += vx * dt T += dt #Keep track of duration of shot if y0 > H: y_list.append(y0) x_list.append(x0) v_list.append(vg) a_list.append(g) else: break plt.plot(x_list,y_list,linewidth=4, label = "Pong Ball Path", color = 'r') plt.plot(x,h,linewidth = 4, label = 'Table', color = 'k') plt.ylim(0, 5) #set ylim to floor (0m) to 5m plt.xlim(-.5, 3)# set the xlim to be from behind the table to infront of table plt.axes plt.show plt.legend() print('Duration of shot: ' + str(round(T,2)) +' seconds') print('If you shoot at ' + str(angle_deg) + ' degrees, shoot with a velocity of: ' + str(round(v0,3)) + ' m/s') if(angle_deg < 45): print('Snipe show!') if(angle_deg >= 45): print('Kobe!')
Duration of shot: 0.68 seconds If you shoot at 30 degrees, shoot with a velocity of: 3.087 m/s Snipe show!
In [ ]: