### Usha Joshi

# Projectile using class 

- **Maximum Height**
\begin{equation}
H=\frac{{u^2}{\sin^2\theta}}{2g}
\end{equation}

- **Horizontal Range**
\begin{equation}
R=\frac{{u^2}{\sin2\theta}}{g}
\end{equation}



- **Time of Flight**
\begin{equation}
T=\frac{{2u}{\sin\theta}}{g}
\end{equation}


```python
import numpy as np                     # from numpy import* not required to write np
import pandas as pd                    # from pandas import* 
import json as json
import matplotlib.pyplot as plt        # from matplotlib import*
%matplotlib inline
```


```python
### (a)
class projectile(object):
    
    def __init__(self, g, u, angle):
        self.pi = np.pi
        self.g = g    # acceleration due to gravity
        self.u = u    # projecting velocity
        self.angle = angle  # projecting angle
        
    def find_range(self):
        RA = self.u**2*(np.sin(2*self.pi*self.angle/180))/self.g     # horizontal range
        return RA
    
    def find_height(self):
        MH = self.u**2*(np.sin(self.pi*self.angle/180)**2)/(2*self.g)# maximum height
        return MH
    
    def find_time(self):
        TF = 2*self.u*np.sin(self.pi*self.angle/180)/self.g          # Time of flight
        return TF
```


```python
P1 =projectile(g=9.8, u=100, angle = 45)
```


```python
P1.g ,P1.u
```




    (9.8, 100)




```python
 P1.angle,P1.find_range(),P1.find_height(),P1.find_time()
```




    (45, 1020.408163265306, 255.10204081632656, 14.430750636460154)




```python
### (b)
class projectile(object):
    
    def __init__(self, g, u):
        self.pi = np.pi
        self.g = g    # acceleration due to gravity
        self.u = u    # projecting velocity
        #self.angle = angle  # projecting angle
        
    def find_range(self,angle):
        RA = self.u**2*(np.sin(2*self.pi*angle/180))/self.g     # horizontal range
        return RA
    
    def find_height(self,angle):
        MH = self.u**2*(np.sin(self.pi*angle/180)**2)/(2*self.g)# maximum height
        return MH
    
    def find_time(self,angle):
        TF = 2*self.u*np.sin(self.pi*angle/180)/self.g          # Time of flight
        return TF
```


```python
P2 =projectile(g=9.8, u=100)
```


```python
P2.g ,P2.u,P2.find_range(60),P2.find_height(60),P2.find_time(60)
```




    (9.8, 100, 883.699391616774, 382.6530612244897, 17.67398783233548)




```python
g=9.8        # m/s^2
u = 100
angle = []   # list of angle
RA = []      # list of  range
MH = []      # list of max height
TF = []      #list of time of flight
for i  in range(0,90+1,5):
    
    ra = P2.find_range(i)
    mh = P2.find_height(i)
    tf = P2.find_time(i)
    angle.append(i)
    RA.append(ra)   #add element in list RA
    MH.append(mh)    #add element in list MH
    TF.append(tf)    #add element in list TF
```


```python
#Multiplots/Subplots
plt.figure(figsize=[10,4])
plt.subplot(1,2,1)
plt.plot(angle,RA,'rs--' ,label='Range')
plt.plot(angle,MH ,'g-o', label='Max height')
plt.xlabel('Angle(deg)')
plt.ylabel('Distance(m)')
plt.title('Projectile Motion')
plt.legend()
plt.subplot(1,2,2)
plt.plot(angle,TF,'k^:' ,label='Time of flight')
plt.xlabel('Angle(deg)')
plt.ylabel('Time(sec)')
plt.title('Projectile Motion')
plt.legend()
plt.savefig('plot/projective.png')
#plt.savefig('projective.eps')
#plt.show()
```


```python
data={}    # to save data in dictionary
data.update({"Angle":angle,"Range":RA ,"Max.Height": MH,"Time of flight":TF})
#print(data)
```


```python
df = pd.DataFrame(data)
df.head()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Angle</th>
      <th>Range</th>
      <th>Max.Height</th>
      <th>Time of flight</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0</td>
      <td>0.000000</td>
      <td>0.000000</td>
      <td>0.000000</td>
    </tr>
    <tr>
      <th>1</th>
      <td>5</td>
      <td>177.192018</td>
      <td>3.875573</td>
      <td>1.778689</td>
    </tr>
    <tr>
      <th>2</th>
      <td>10</td>
      <td>349.000146</td>
      <td>15.384536</td>
      <td>3.543840</td>
    </tr>
    <tr>
      <th>3</th>
      <td>15</td>
      <td>510.204082</td>
      <td>34.177193</td>
      <td>5.282021</td>
    </tr>
    <tr>
      <th>4</th>
      <td>20</td>
      <td>655.905724</td>
      <td>59.682540</td>
      <td>6.980003</td>
    </tr>
  </tbody>
</table>
</div>




```python
with open("data/projectile.json", 'w')as f:   #to load data in json file
    json.dump(data,f)
```


```python
# to upload json file
with open("data/projectile.json", 'r')as f:
    uploaded_data = json.load(f)
```


```python
df.to_csv("data/projectile.csv")  #save data in csv format in excel
```


```python
uploaded_data = pd.read_csv("data/projectile.csv")
uploaded_data.head(3)
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Unnamed: 0</th>
      <th>Angle</th>
      <th>Range</th>
      <th>Max.Height</th>
      <th>Time of flight</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0</td>
      <td>0</td>
      <td>0.000000</td>
      <td>0.000000</td>
      <td>0.000000</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1</td>
      <td>5</td>
      <td>177.192018</td>
      <td>3.875573</td>
      <td>1.778689</td>
    </tr>
    <tr>
      <th>2</th>
      <td>2</td>
      <td>10</td>
      <td>349.000146</td>
      <td>15.384536</td>
      <td>3.543840</td>
    </tr>
  </tbody>
</table>
</div>




```python

```

dea9218596f4d00e8dc4abebb7f11091c44f3885
ipynb
Jupyter Notebook
projectile_class.ipynb
22Shailesh/Projectile
de2d39f766d49ab54b434c92aee1ae695b2b38d0
MIT
2020-08-15T02:12:39.000Z
2020-08-15T02:12:39.000Z
projectile_class.ipynb
22Shailesh/Projectile
de2d39f766d49ab54b434c92aee1ae695b2b38d0
MIT
projectile_class.ipynb
22Shailesh/Projectile
de2d39f766d49ab54b434c92aee1ae695b2b38d0
MIT
2020-08-14T15:01:23.000Z
2020-08-14T15:01:23.000Z
Qwen/Qwen-72B
1. YES
2. YES