#### Assignment 2: Moving rockets

This assignment is due on Wednesday, 8/29 at 11:59 PM. Submit it using the handin server as assignment a2. Your submission is only accepted if the message "Handin successful" appears.

Let’s use what we’ve learned to animate a rocket launch.

We’ll solve this problem in two parts, horizontal and vertical, then combine them. The examples we animated in class and in the textbook prologue can guide us to solve both parts of the problem. This divide-and-conquer approach is possible because force applied along one axis to a moving body only affects motion along that axis and not any other axis. So the horizontal motion of a rocket is decoupled from its vertical motion, and we can write down two completely independent equations. Only the equation governing vertical motion involves gravity.

First make sure that you require the 2htdp/image and 2htdp/universe libraries.

Exercise 1 Your program will animate a rocket fired with an initial speed init-speed and initial angle to the horizontal init-angle.

Define init-speed and init-angle as program variables. Use an initial speed of 1 and an initial angle of pi/4 to start. Once your program is running, you should try using different values to see how your animation behaves. Note here that we are using an angle specified in radians.

init-x-vel = init-speed * cos(init-angle)

init-y-vel = init-speed * sin(init-angle)

height = init-y-vel * t - 1/2 * 0.002 * t * t

Design a function y-pos which calculates the vertical position (height) as a function of time t. Test your new function to make sure that (y-pos 0) produces 0.

horizontal position = init-x-vel * t

Design a function x-pos that calculates the horizontal position as a function of time t. Test your new function to make sure that (x-pos 0) produces 0.

image-y = scene-height - h

Test your new function to make sure that (draw-sprite 0 0) produces an image that places the rocket in the lower-left corner. Also test that (draw-sprite 20 50) produces an image that places the rocket above the lower-left corner and a little bit to the right.

Exercise 6 Finally, combine all of these functions together into a single function launch that draws an image at the correct horizontal and vertical positions, as a function of time t.

Your definition of launch should not mention multiplication (*) or subtraction (-) directly anywhere. Test it to make sure that (launch 0) produces an image that places the rocket in the lower-left corner.

Use your launch function with the animate we discussed in class to produce an animation of a rocket launching with an initial angle to the horizontal and an initial speed.

You should see your rocket starting off at the lower left. It should then move up and right, and eventually, it should fall, but continue moving right, and eventually move off your scene.