Programming Assignment 3 (Version 1.1)
CS-150, Fall ’02, Dr. C. S. Tritt

Due Thursday, 10/24

In this problem , you continue to find yourself trapped in 1000 B.C.E. with the local population continuing to attack. You find that the program written in assignment 2 was useful, but too limited in scope. Dr. Viets (who was transported back in time with your group and has taken charge of the situation) asks you to write a more sophisticated program for calculating trajectories.

He asks to write a program to generate simple artillery tables for your trebuchet. Artillery tables are simply tabulations of impact points as a function of operating conditions. The only operational parameters of interest in this problem are elevation difference, launch angle and initial velocity. When run, your program should prompt the user for an elevation difference, a minimum launch angle, maximum launch angle, angle increment, a minimum initial velocity, maximum initial velocity and velocity increment. It should then display a table of impact distances. The table should be organized such that the column headings are angles and row heading are velocities.

In an effort to assure you continue to learn even in the unfortunate situation in which you find yourselves, Dr. Viets insists that you use a function in your program. Specifically, your function must accept an elevation difference (in m), an initial velocity (in m/s2) and launch angle (in degrees) and return the distance (in meters) to the point of impact. In addition to returning the distance to the point of impact, your function should also return a type bool error flag (hint this quantity should be a parameter passed by reference rather than value). In response to this flag being true, your main program should display a “***” in place of a distance in the table.

You no longer have to worry about the projectile hitting the wall in that the trebuchet has been moved to a platform as shown in the attached drawing.

Dialog and Sample Output

Enter elevation difference (in m): -10.

Enter angle min., max. and incr. (in deg.): 30. 50. 5.

Enter initial velocity min., max. and incr. (in m/s): -5. 45. 10.

Impact points for Yt = -10.

		30.0	35.0	40.0	45.0	50.0
-5.0		***	***	***	***	***
5.0		#.#…
15.0		etc.
25.0
35.0
45.0

This exact format of the table is not critical, but should be similar to that shown. In the table above #.# and etc. represents numerical values that should fill the table.

Kinematics Analysis for Program 3

Schematic:

Make the launch point as the origin of a Cartesian coordinate system. Assume negligible air resistance, so vx = Vx,0 = V0cosθ and the acceleration in the y‑direction is –g. The initial velocity in the y direction, Vy,0, is V0sinθ.

Since the x-direction velocity is constant, the x-displacement as a function of time is x(t) = Vx,0t (Eq. 1). Since the acceleration in the y-direction is constant, the y-velocity as a function of time is vy = Vy,0 + ayt = Vy,0 – gt. Integrating the velocity with respect to time gives the displacement, so y(t) = ∫vy(t)dt = – gt2/2 + Vy,0t + C. Using the initial condition y = 0 at t = 0 gives C = 0, so y(t) = – gt2/2 + Vy,0t (Eq. 2).

The solution to this problem is much easier if y as a function of x is known, so solve Equation 1 for t and substitute into Equation 2 to give y(x) = – gx2/(2Vx,02) + Vy,0x/Vx,0 (Eq. 3).

In general, the point of impact with be the value of x where y = Yt. So, Yt = – gx2/(2Vx,02) + Vy,0x/Vx,0 or – gx2/(2Vx,02) + Vy,0x/Vx,0 – Yt = 0 (Eq. 5). So finding the point of impact becomes a matter of finding the roots of Equation 5.

Applying the quadratic equation to Equation 5 gives:

where a = –g/(2Vx,02), b = Vy,0/Vx,0 and c = –Yt.

In this case, it is possible for some elevations to result in no solutions. In addition, only the larger of the two roots of this equation needs to be considered.