<a href="https://colab.research.google.com/github/vaammpyy/Physics/blob/Animation/Projectile%20motion/Without%20Drag/code_animated.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
from matplotlib.animation import FuncAnimation
from IPython import display
```


```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


  fig2=plt.figure(figsize=(10,10),facecolor='white')
  plt.plot(x,f(theta,u,h,accel),'k--')
  plt.grid()
  plt.ylabel("Height [m]")
  plt.xlabel("Range [m]")
  plt.axis('scaled')
  plt.ylim(top=int(ylim),bottom=0)
  plt.xlim(0,int(xlim))
  #plt.xticks(np.arange(0,int(xlim),step=1.0))
  #plt.yticks(np.arange(0,int(ylim),step=1.0))
  
  points=plt.plot([],'ro')
  point=points[0]
  time_text=plt.title('',fontsize=18,loc='left')
  
  def marker(b):
    return(b*np.tan(theta)-accel*b**2/(2*u**2*(np.cos(theta))**2)+h)
  
  def animate(frame):
    if frame<int(np.ceil((t)*50)):
      time=frame*20/1000 
      time_text.set_text("Time[s] ={}".format(time)) 
      g=u*np.cos(theta)*time
      #print("frame {}".format(frame))
      point.set_data((g,marker(g)))

  print("Number of frames {}".format(int(np.ceil((t+1)*50))))
  k_y=input("Type 'yes' to animate (for frames>1000 it can take anywhere from several minutes to hours for animation to render): ")
  if k_y=="yes":
    anim =FuncAnimation(fig2,animate,frames=int(np.ceil((t+1)*50)),interval=20)
    video=anim.to_html5_video()
    html=display.HTML(video)
    display.display(html)
    
    plt.close()
```


```python
v_2=float(input("Enter angle of projection in degrees:"))
v_3=float(input("Enter projection velocity in m/s:"))
v_4=float(input("Enter initial elevation in m:"))
v_5=float(input("Enter downward acceleration in m/s^2:"))
trajectory(v_2,v_3,v_4,v_5)
```

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