CPSC120A
Fundamentals of Computer Science I

Scientific Assignment 3

Use Python for ballistics simulation.

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. A lot has changed over the years, to the point where pocket sized computers (Cell Phones) now have more computational power than the ENIAC. For this assignment, you will use your modern day computer and the turtle module to perform similar calculations.


Details

Create a function called draw_arc(initial_x, initial_y, velocity_x, velocity_y, gravity, wind). You can assume all parameters to this function will be floating point values. initial_x and initial_y are the initial locations of some projectile, and are relative to the origin on the turtle window. velocity_x and velocity_y are the x and y components of the initial velocity of the projectile. gravity is the force that is pulling down upon the projectile and only affects the vertical speed of the projectile. wind is the force that affecting the horizontal speed of the projectile.

This function should draw some fixed number of line segments that will approximate the ballistic trajectory of the projectile launched from the specified starting location with the specified starting velocity. Each line segment can be calculated by using the projectile's current velocity to compute the new location of the projectile (assuming the projectile is traveling in a straight line). Once you compute the new position, you then need to compute the new velocities in the x and y directions. You do this by subtracting gravity from the y velocity, and adding wind to the x velocity.

Write a function to draw a target on the right side of the turtle window. This is simply 3 concentric circles. Your program will then use an input statement to get the starting X location and the projectile's speed. Using a for loop and the function defined above, try all of the possible angles (from 90° to 0°, using increments of 5°). You will have to use the trigonometric functions to convert the input speed and chosen angle into x and y velocity components for your draw_projectile function.

You should use the turtle.write function to label your projectile paths with the angle that drew the line. Someone using your program should be able to visually see which angles produced a path that traveled through the target.


"Hacker" Prompt

Each week, additional exercises related to the assignment will be provided at the end. These exercises are typically more challenging than the regular assignment. Bonus points will be provided to students who complete any of the "Hacker" level assignments.

  1. Air Resistance: The code above assumes the projectiles are fired in a vacuum. While space combat seems fun, it's not very useful for Earth based projectiles. Add air resistance to the simulation. Air resistance is an acceleration that is always opposite the direction of the velocity. Thus the x and y components of the air resistance must be recalculated every time velocity is updated.

  2. The Monkey and the Hunter: The monkey and the unter 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.

  3. 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 some easy to notice color.

Submission

Your code should conform to the course’s code conventions and will be graded according the the course’s programming assignment rubric. Submit your program as a .py file on the course Inquire page before class on Friday October 3rd.