Projectile Motion With Python - Student Guide
Table of contents
In this module we will investigate projectile motion, with and without air resistance.
- There are questions asked of you throughout this assignment, labeled Question 1, Question 2, etc. Include the answers to these questions in your Presentation.
- At the end of each activity, save your code into your Presentation.
- If you are working with a partner, the two of you must reach a consensus about an answer before moving on to the next part. Feel free to ask the TA for help if a consensus cannot be reached.
- All quantities are in SI units; distance in meters (m), time in seconds (s), velocity in m/s, acceleration in m/s2, and mass in kg.
Activity A: Projectile Motion in a Vacuum
Question 1
A ball is launched with an initial speed v0, and an initial launch angle θ0. The acceleration due to gravity is g = 9.80 m/s2, downward. How far, horizontally, from the launch position will the ball be when it returns back to the same initial height? (This distance is called the horizontal range of the projectile.) [Neglect air resistance.]
Question 2
If you wish to hit a "home run" in baseball, assume your horizontal range must be at least 100 m. What is the minimum initial speed you need to hit a home run, and what is the best initial launch angle? [Neglect air resistance.]
Download the program projectilea.py and save it on your computer. You can open it with Spyder, which should be an icon on your desktop. Read the code carefully. Remember that any line which starts with # is just a comment for the reader, and is ignored by the computer when it runs the code. Note that this is different than real baseball. To make the physics simpler, we are assuming that in order to get a "home run", the range must be greater than 100 m. The range is defined as the horizontal distance traveled when the ball's final y-position returns to its initial y-position.
Question 3
There is a “bug” somewhere in this code. There is only one major bug on one line that is making the code crash with a syntax error. Debug the code so that it no longer crashes. Describe in your presentation what the old and new line were that you fixed.
Now that the code is running, give it a few tries. You have to input an initial speed, and it computes the maximum range and best range angle. If the range is longer than 100 m, it tells you that you got a “home run”. The code also outputs a comma-separated-value file “projectileA.csv” which you can read into Excel and make a chart of the best trajectory.
Question 4
Run the program with the speed you computed in question 2. Did you get a home run? Try modifying the angle-step size and the time-step for numerical integration. Note this numerical integration is rather crude, so you won't get exact results. You might have to adjust the initial speed a bit upward. Don't reduce the angle-step size and time-step too much or the code will take too long to run! Once you have a range you like, open up the output file with Excel, highlight the first two columns and insert a scatter plot. Take a screenshot of this graph and include it in your presentation along with the relevant parameters of the numerical integration.
Activity B: Projectile Motion of a Baseball in Air
When a real baseball flies through the air, there is air resistance. Air resistance is studied in fluid dynamics and its origins are complex, but for most normal speeds and ordinary-sized objects here on earth that are not rotating, air resistance can be modeled by the drag equation:
\(F_D = \frac{1}{2} \rho v^2 C_D A\)
Here FD is the magnitude of the drag force in Newtons. The direction of \(\vec{F}_D\) is opposite the direction of the ball’s velocity relative to the air, \(\vec{v}\). ρ is the density of the air, which we set to be ρ = 1.2 kg/m3. \(v^2 = {v_x}^2 + {v_y}^2\) is the square of the speed of the ball in m2/s2. A is the cross-sectional area of the ball in m2. CD is the drag coefficient - a dimensionless coefficient related to the object's geometry and taking into account both skin friction and form drag (http://en.wikipedia.org/wiki/Drag_equation). Note that for a baseball going between 20 and 50 m/s, the drag coefficient is approximately CD = 0.5.
So as the ball flies through the air, there are two forces acting: the drag force and gravity. The net force on the ball is the vector sum: \(\vec{F}_{\rm net} = \vec{F}_D + \vec{F}_G\).
Question 5
What are the x- and y-components of the net force on the ball as it travels through the air? Write equations for the force Fx and Fy components in terms of the following variables only:
- the instantaneous velocity components vx and vy
- the mass of the ball m
- the acceleration due to gravity g
- the radius of the ball r
- the density of air ρ
- the drag coefficient of the ball CD
Save a new copy of the .py file you used in Activity A, call it “projectileB.py”. Edit the code to include air resistance.
Question 6
If you wish to hit a "home run" in baseball, your horizontal range must be at least 100 m. What is the minimum initial speed you need to hit a home run, and what is the best initial launch angle? [Include air resistance!] Make sure your result doesn't depend much on the angle-step size and the time-step for numerical integration. Once you have a trajectory you like, open up the output file with Excel, highlight the first two columns and insert a scatter plot. Take a screenshot of this graph and include it in your presentation along with the relevant parameters of the numerical integration. Copy and paste your code into your presentation as well.
Some quirks about Python code which might be good to know:
- To raise something to a power, use **, not ^. (Ie, x2 is x**2)
- Python will not overwrite a file that is currently open in another program. So if you are viewing the output .csv file with Excel, you have to close Excel before you can re-run the python code.
Question 7
What if the baseball had all the same properties except its mass was half as much? What would be the required initial speed and best launch angle for a home run? Plot this trajectory.
[This Module was written by Jason Harlow November 2014. ]