from math import sin,cos,e,radians,atan2,sqrt,pi
α = 30 #Angle of elevation (degrees)
V = 25 #Muzzle velocity (m/s)
M = 0.0027 #Projectile mass (kg)
R = 2 #Projectile radius (cm)
cd = 0.42 #Drag coefficient (0.42 for spheres)
y = 0 #Elevation (m)
x = 0
Vx = V*cos(radians(α))
Vy = V*sin(radians(α))
A = 0.0001*pi*R**2
def FD():
ρ = 2.831/(1 + 1.3262*e**(0.1516*y/1000)) #Density of the air
return 1/2*V**2*ρ*cd*A #Calculate drag force
for t in range(300000):
x += Vx*0.001 #Move the projectile
y += Vy*0.001
Fd = FD()
Fx = Fd*cos(atan2(Vy,Vx))
Fy = Fd*sin(atan2(Vy,Vx))
Vy -= (0.00982 + Fy/(1000*M)) #Velocity changes
Vx -= Fx/(1000*M)
V = sqrt(Vy**2+Vx**2) #Speed
if round(t/100,1) == t/100: #Print position every 100 ms
print(x,y,Vy)
pass
if y <= 0 and Vy < 0: #Print position when landed
print(x,y)
break
|