The first electronic programmable computer, ENIAC, was created for performing ballistic calculations for the United States Army. ENIAC was the size of a school bus and weighed 30 tons. You can do the same calculations on your computer.
Create a directory assignment3 under assignments in your cs120 directory. All code for the assignment should be stored in this directory.
cd ~/cs120/assignments mkdir assignment3 cd assignment3
Create a function that draws the path of a projectile. The path of the projectile is determined by the initial position of the projectile, the initial velocity of the projectile, gravity, and wind. Each of these values should be parameters to the function. The program should also have a parameter for the number of line segments of the projectile's path to compute and draw.
The initial position of the projectile is the number of pixels from the origin in both the x and y directions. The initial velocity of the projectile is the change in the projectile's position in pixels per update in both the x and y directions. Gravity is the change in the projectile's velocity in update per update squared in the negative y direction. Wind is the change in the projectile's velocity in pixels per update squared in both the x and y directions.
The function should approximate the projectile's path with a series of line segments. Each line segment can be calculated by using the projectile's current velocity to calculate where it will be next, assuming it travels on a straight line. The new position can be calculated by adding the velocity to the old position. Every time the new position is calculated a new velocity should also be calculated. The new velocity can be calculated by subtracting the gravity from the y velocity and adding the wind to the x velocity. Gravity is a non-negative real number that controls how quickly the projectile falls. Wind is a constant force, like gravity, but it is only in the x direction.
Draw a target on the right side of the turtle window. You can simply
draw 3 concentric circles to represent a target. Your program should
read (from the command line) the starting X location and
starting projectile speed. Using a for loop, and your
function defined above, try all angles of the projectile (which you
can assume are from 90 to 0). You will have to use the trig
functions to decompose the specified speed into the X and
Y velocity components, based off the chosen angle. You should use the
turtle.write
function to label your projectile paths
with the angle you computed. Someone using your program should be
able to visually see which angles produced a path that traveled
through the target.
Your program should include the traditional header, use appropriate variable names, and nicely label all values printed to the terminal. Submission are to be done through cseval.roanoke.edu through the Assignment 3 link. You should submit a tar file for this assignment. You can do so by issuing the following commands:
cd ~/cs120/assignments tar czvf assignment3.tgz assignment3/
Both partners must submit through cseval!
Air Resistance: The code above assumes the projectiles are only operating in a vacuum. Add air resistance to the simulation. Air resistance is an acceleration that is always the opposite direction as the velocity. The x and y components of the air resistance must therefore be recalculated every time the velocity is updated.
The Monkey and the Hunter: The monkey and the hunter is a classic physics question. If a hunter aims a dart gun directly at a monkey hanging on a branch and the monkey lets go at the same instant the hunter fires, will the monkey be hit? Simulate this by creating two projectiles. One projectile, the monkey, with an initial velocity of 0 in both the x and y direction. The other projectile, the dart, with an initial velocity directly toward the initial location of the monkey.
Trigger Finger: It's usually a pain to work with turtle and read in information from the command line. Setup your program so the user clicks on where they want to fire from. For this portion, you can assume some pre-defined initial speed.
Easier Labels: Now that you know if
statements, you can make figuring out which shot landed in the
target easier. If you detect that one of the discrete points on the
path results in a target hit, change the color of the text used to
label the shot to Blue.