Unit #5 Programming Assignment
Course Outline HW & Programming Assignments
5pa3
 

PROJECTILE MOTION

(....or click here if there is trouble with the Visual)

Write a C++ program which reads the initial speed and angle of attack of a projectile, prompts for and reads a specific time and then calls a function

float project ( float v0, float theta , float time) ,

which returns the distance of the projectile from the initial point at the given instant of time.

The projectile starts at the point 0 and moves towards the wall as shown below. The wall is 8 feet high and is located 15 feet way from the origin. Whenever the projectile hits the ground or the wall or the elevated platform, it stops. After impact the distance of the projectile remains fixed for all subsequent times



There are many ways one can design the algorithm. We use the following one:

The units used are ft/sec for v0, degrees for theta, seconds for time ( 1 mile/h = 1.46666 ft/sec ).

We calculate the components of the initial velocity using:

v0x = v0 * cos(theta)

v0y = v0 * sin(theta)

The equations of motion are:

y = v0y * t - 0.5 * g * t^2 ,

x = v0x * t ,

where g is the gravitational acceleration ( 32.2 ft/sec^2 ), x measures horizontal distance from 0 and y vertical distance.

We calculate the time needed for the projectile to reach the point of zero vertical velocity by

tymax = v0y / g

and we calculate the maximum distance of travel if there was no wall using:

xmax = v0x * 2 * tymax

If xmax < 15 then the time of impact is timpact = 2 * tymax and the distance is given by

distance = sqrt( x^2 + y^2 ) , for t < timpact

……….= xmax , fot t >= timpact

If xmax >= 15 then we calculate the time needed for the x to reach the value of 15 from

tx15 = 15 / v0x

and we calculate y at this time, i.e.

yx15 = v0y * tx15 - 0.5 * g * tx15^2

If 0 <= yx15 <= 8 then timpact = tx15 and we calculate the distance using

distance = sqrt( x^2 + y^2 ) , for t < timpact

……... = sqrt( 225 + yx15^2) , fot t >= timpact

If yx15 > 8 then

timpact = [ v0y + sqrt(v0y^2 - 16g)] / g

we calculate xy8 using xy8 = v0x * timpact and again we calculate the distance by

distance = sqrt( x^2 + y^2 ) , for t < timpact

……… = sqrt( xy8^2 + 64) , for t >= timpact


 
You must prepare a file with the name xxxx5pa.cpp .