I'm trying to use main function in order to make the trajectory of the projectile with air resistance. The problem is, when I'm using main function, I got an error but not when I use function without main, what I did it wrong?
v=float(input("initial velocity: "))
theta=float(input("Angle from the horizontal of initial velocity: "))
B=float(input("normalised drag coefficient: "))
t=float(input("the step interval in seconds: " ))
vx = v * math.cos(theta*math.pi/180.0)
print(str(vx))
vy = v * math.sin(theta*math.pi/180.0)
sx = 0
sy = 0
t0 = 0
ax = 0
ay = 0
g= 9.81
def AX(ax):
ax= -B*v*vx
return ax
def AY(ay):
ay= -(B*v*vy)-g
return ay
def VX(vx):
vx=vx+ax*t
return vx
def VY(vy):
vy=vy+ay*t
return vy
def SX(sx):
sx= sx + vx*t
return sx
def SY(sy):
sy= sy + vy*t
return sy
Xdisplacement=[]
Ydisplacement=[]
def main():
while sy>=0 :
Xdisplacement.append(float(sx))
Ydisplacement.append(float(sy))
sx=SX(sx)
sy=SY(sy)
ax=AX(ax)
ay=AY(ay)
vx=VX(vx)
vy=VY(vy)
v= ((vx**2.0)+(vy**2.0))**(1.0/2.0)
plt.plot(Xdisplacement,Ydisplacement)
plt.title("trajectory")
plt.xlabel("x")
plt.ylabel("y")
plt.show()
main()