[SOLVED] drracketC211 Assignment 2

$25

File Name: drracketC211_Assignment_2.zip
File Size: 235.5 KB

5/5 - (1 vote)

Assignment 2: Moving rockets

This assignment is due on Wednesday, 1/17 at 11:59 PM. Submit it using the handin server as assignment a2.

Lets use what weve learned to animate a rocket launch.

Well 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.

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

Exercise 1Define init-speedand init-angleas 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.

Since only the initial speed will be specified, you will need to calculate the xand ycomponents of the initial velocity. These may be calculated via

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

Exercise 2Define the initial vertical velocity init-x-veland the initial horizontal velocity init-y-velusing the initial speed init-speedand the initial angle init-angle. We define the initial speed and velocity components (horizontal and vertical) as numbers rather than functions because they do not change over time.

The rocket experiences a gravitational acceleration in the vertical direction. Therefore, the vertical position of the rocket is this function of the time t:

vertical position = init-y-vel * t 1/2 * 0.002 * t * t

where init-y-velis the initial velocity in the vertical direction, and 0.002is the gravitational acceleration, which is a constant.

Exercise 3Design a function y-poswhich calculates the vertical position as a function of time t.

The rocket does not experience any acceleration in the horizontal direction. Therefore, it has constant horizontal velocity, and the horizontal position is a simpler function of the time t:

horizontal position = init-x-vel * t

Exercise 4Design a function x-posthat calculates the horizontal position as a function of time t.

Exercise 5Design a function draw-spritethat draws a sprite on the screen. This function should be called draw-spriteand take two inputs, the horizontal position and the height. The term sprite is commonly used in computer graphics to refer to an image that moves around the screen. You may use any small image of your choice, such as a small circle, or even the rocket image. Remember, the Racket system specifies the Y position from the top down, and the vertical position you calculated above specifies the vertical position starting at the bottom, so you will need to convert your calculated height into a Y position that the Racket place-image function can understand. This conversion can be performed as follows:
y = scene-height h
where scene-heightis the height of your scene, and his the height, or vertical position from the bottom of the object you wish to draw. You should use the place-image to place an image on a scene that you create using empty-scene . A scene size of 500 wide by 200 tall should work well for the numbers provided here. It may be useful to test out your sprite drawing function using the interaction window.

Exercise 6Finally, combine all of these functions together into a single function launchthat draws an image at the correct horizontal and vertical positions, as a function of time t. Use this 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.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] drracketC211 Assignment 2
$25