<a href="https://colab.research.google.com/github/vaammpyy/Physics/blob/main/Projectile%20motion/Without%20Drag/code.ipynb" target="_parent"></a>


```python
import matplotlib.pyplot as plt
import numpy as np
from ipywidgets import interactive
import sympy as sp
import math
import sys
```


```python
def plotter(x,f,xlim,ytop,x_1,y_1,t,h,r):
  plt.figure(figsize=(10,10),facecolor='white')
  plt.plot(x,f,'k',x_1,y_1,'ro')
  plt.grid()
  plt.legend(["Trajectory","Max height"])
  plt.ylabel("Height [m]")
  plt.xlabel("Range [m]")
  plt.ylim(top=ytop,bottom=0)
  plt.xlim(0,xlim)
  plt.title("Time of flight={}s, Range={}m, Maximum height={}m".format(t,r,h))
  plt.xticks(np.arange(0,xlim,step=1.0))
  plt.yticks(np.arange(0,ytop,step=1.0))
  plt.show()
```


```python
def trajectory(theta,velo,height,acceleration):
  
  
  theta=theta*np.pi/180
  u=velo
  h=height
  accel=acceleration
  
  
  d= sp.Symbol('d')
  k=d*np.tan(theta)-accel*d**2/(2*u**2*(np.cos(theta))**2)+h
  m=sp.solve(k)
  m[0]=float(m[0])
  m[1]=float(m[1])
  
  xlim=0
  if len(m)==2:
    if m[1]>1:
       xlim=np.ceil(m[1])
    else:
       y=round(m[1],3)
       xlim=y+0.01*y
  else:
    xlim=np.ceil(m[0])
  
  x=np.linspace(0,1.1*xlim,100)
 
  f=lambda theta,u,h,accel:x*np.tan(theta)-accel*x**2/(2*u**2*(np.cos(theta))**2)+h
  t=(u*np.sin(theta)+np.sqrt((u*np.sin(theta))**2+2*accel*h))/accel
 
  x_1=np.tan(theta)*(2*u**2*(np.cos(theta))**2)/(2*accel)
  
  if x_1<0:
    x_1=0
  
  if theta>=0:
      h_max=(u*np.sin(theta))**2/(2*accel)+h
  else:
      h_max=h+0.0
  y_1=h_max
  
  time=round(t,3)
  
  if len(m)==2:
     range=round(m[1],3)
  else:
     range=round(m[0],3)
  height=round(h_max,3)
  ylim=h_max+0.1*h_max
  plotter(x,f(theta,u,h,accel),xlim,ylim,x_1,y_1,time,height,range)
```


```python
iplot=interactive(trajectory,
                    theta=(-90,90,1),
                    velo=(1,25,1),
                    height=(0,50,1),
                    acceleration=(1,25,1))
iplot
```

517abe6541e39a112b626ffa5120807bb74b6749
ipynb
Jupyter Notebook
Projectile motion/Without Drag/code.ipynb
vaammpyy/Physics_with_python
069494af1e65d4bba4c9492a993cf94649f941a0
MIT
2021-07-18T21:58:14.000Z
2021-09-29T05:36:10.000Z
Projectile motion/Without Drag/code.ipynb
vaammpyy/Physics_with_python
069494af1e65d4bba4c9492a993cf94649f941a0
MIT
Projectile motion/Without Drag/code.ipynb
vaammpyy/Physics_with_python
069494af1e65d4bba4c9492a993cf94649f941a0
MIT
Qwen/Qwen-72B
1. YES
2. YES