Assignment 10

Due date: 4/2 @ 9:50 am


Problem 1:

A trajectory of a shot fired from a cannon depends on the angle of the gun. It is given by the function f(angle, t) = velocity * (t * tan(angle) - g * t * t) where g is the gravity constant, tan is the trigonometry tangent function, and velocity is some constant value.

Your job now is to help the gunner to shoot down the given target. The target is given by its position - it is a black circle of radius 10.

Part 1

Design the function that computes the position of the shot at the given time, provided it was fired at the given angle and at the given velocity.

Part 2

Design the function that will tabulate the values of the trajectory function at times 0, 1, 2, ... , n for a given angle and velocity.

Part 3

We now want to see the location of the shot at the times 0, 1, 2, ... , 40 shown on a scene of size 200 by 200. For the x-coordinate, use the time multiplied by 5.

The y-coordinate is determined by the function value. Use the floor function to convert the inexact number into an integer.

Show the location of shots as red circles of radius 3.

Part 4

Design the function that determines whether the shot hit the target by checking whether the shot location at each time interval is within the bounds of the target. Do not worry about the position of the shot in between the time intervals.

Part 5

Design the function that determines whether the shot had gone above the target.

Adjust the constant speed and the gravity constant so that you can actually see the trajectory display. Do not worry whether the trajectory hits the ground while still within the bounds of the display, ... the trajectory of the shot once it is submerged under the water is no longer visible.


Exra Credit:

Design the function that will determine for a constant velocity the angle needed to hit the given target at the end of the scene at the height 0 to 100. Assume that the velocity is sufficiently large so that this is always possible. Use successive approximations -- if above, shoot a bit lower, if below, shoot a bit higher, etc.

Last modified: Mon Mar 26 16:42:34 EDT 2007