In [ ]:
import numpy as np
from math import sqrt
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt

Welcome to your projectile motion challenge problem! Here you'll write code that will plot the trajectory of a projectile in ideal conditions, with the standard assumptions of no air resistance and constant gravitational acceleration. You'll use the path-length function you created earlier to compare the total distance traveled in the air by the projectile for different launch angles and launch velocities.

We'll track the projectile's position using an $xy$ coordinate system. It is launched from position (0,0) with launch angle $\theta$ above the positive $x$ axis, launch speed $v_0$, and gravitational acceleration $g$ in the $-y$ direction. We'll use a time coordinate $t$ to specify the time since launch.

First, in the cell below, write functions that return x position and y position when passed values of $t$, $v_0$, $\theta$, and $g$. Assume the angle is passed in units of radians.

Hint: You can treat the x and y directions separately. For example, the equation of motion for the x-coordinate is

$$x = v_{0x} t$$

where $v_{0x}$ is the x-component of initial velocity vector. How do you compute $v_{0x}$ given $v_0$ and $\theta$?


In [ ]:
# your code here

Now write a function that returns the total time the projectile will stay in the air (which means return to $y = 0$), in units of seconds, given $v_0$ (with units m /s), $\theta$ (in radians) , and $g$ (with units m / s$^2$).

Hint: the equation of motion along y-direction is

$$y = v_{0y}t - \frac{1}{2}gt^2$$

When $y = 0$, $t$ either equals $0$, or

$$t = t_f = \frac{2v_y}{g}$$

where $t_f$ represents the time the projectile will stay in the air.


In [ ]:
# your code here

In the cell below, make a plot of a projectile trajectory when $g$ = 9.8 m/$s^2$ in the -y direction, $v_0$ is 100 m/s, and $\theta$ is 45 degrees ($\pi$/4 radians).

To do this, you might find the following steps helpful:

First, create an array of time values linearly spaced between 0 and $t_f$. You get to choose the number of time values. A reasonable choice might be 128, but you can see what happens if you use more or less than that.

You'll be recording the $x$ and $y$ positions of the particle at each time, so you'll need arrays for those, too.

Loop through the time values and determine the value of $x$ and $y$ at each time.

Then plot $y$ vs $x$.

$\textit{Recall}:$ $\theta_{radians} = \frac{\theta_{degree}\pi}{180}$


In [ ]:
plt.close() # leave this here. it makes sure that if you run this cell again, the plot appears below

# parameters    

# calculate the trajectory
    
# plot-don't forget to label your axes!

Next, let's see what happens when we change the launch angle. Make the same plot as above, but for several different values of the launch angle $\theta$, all displayed together in a single plot. For example, you could use 9 angles linearly spaced between 5 and 85 degrees. Plot all the trajectories on the same graph in the cell below.

Once you've done that, save the trajectory information for later. In the same loop that you're using to make the plot, save the $x$ and $y$ values for each value of theta, using np.save(). Give them descriptive names that include the value of theta so that you can retrieve them later.


In [ ]:
plt.close() # keep this here

# your code here

Now we want to estimate the total distance traveled by the projectile in the air. You've already written a path-length function. Rewrite the path-length function (and any helper functions) into the cell below.


In [ ]:
# your code here

Loop through the launch angles again, load the trajectories, and determine the total distance traveled in the air for each angle. Plot these distances versus launch angle.


In [ ]:
plt.close()

# your code here

What is determining the shape of that curve you just made? How do you think this will change if you used different launch speeds or gravitational accelerations? Experiment! What other interesting relations can you find?