import math import matplotlib.pyplot as plt # import modules above g=9.8 omega=4000*math.pi/60 vd=35 v_wind=3 Delta=5 S0m=0.00041 # B2m=0.00004 # y_zero=10000 # a=0.0065 # T0=300 # alpha=2.5 # set constants above class baseball: "the simplest model with no air drag, no air density variance, no probability distribution" # initialize variables def __init__(self,v0,theta,yFinal=0): self.x0=0 self.y0=1.8 self.yFinal=yFinal self.v0=v0 self.Theta=theta self.theta=theta*math.pi/180 self.vx0=self.v0*math.cos(self.theta) self.vy0=self.v0*math.sin(self.theta) self.dt=0.01 return None # external force other than gravity, no force in simplest case def B2m(self,v): return 0.0039+0.0058/(1+math.exp(v-vd/Delta)) def F(self,vx,vy): vxy=math.sqrt(vx**2+vy**2) Fx=-self.B2m(vxy)*math.sqrt((vx-v_wind)**2+vy**2)*(vx-v_wind)-S0m*omega*vy Fy=-self.B2m(vxy)*math.sqrt((vx-v_wind)**2+vy**2)*vy+S0m*omega*vx return Fx,Fy # calculate the flying trajactory def fly(self): self.X=[self.x0] self.Y=[self.y0] self.Vx=[self.vx0] self.Vy=[self.vy0] self.T=[0] while not (self.Y[-1]