Enter Values:
v (velocity),
theta (launch angle),
Initialize Variables:
1=0 (time),
tstep = 0.1 (time step between calculations)
=32 (Gravitational constant in ft per sec2)
Find velocity components before loop:
theta = theta * PI/ 180.0;
vi=v*cos(theta)
v,~v*sin(theta)
Create a Loop (with everthing below inside of if)
t=t+ step
Create a trajectory function that does the following (call it inside this loop):
pass, vi, vy to the trajectory function
y=w*t-05*a*t? (Calculate height)
X=v tt (Calculate horizontal distance )
Print time, x distance and y height
11 also detect max height (max y value) then print when it happens
etum y
Loop Until y <= 0 (Until missile has hit the ground)
In order to detect max height and last values inside of the function define static values (for full credit) to
hold the previous values of x, y and t. Also notice that the last value of height is 0 and the co
esponding
distance and time values must be linearly interpolated for full credit.
le initial velocity Â£t/5>40
TEST)
83
ye
RT
RT
Co
ect data and function call inside of loop (80%)
Detect Max Height (10%)
Calculate Linear Interpolated last values10%)
Submit a screen shot and printout of your code
Calculation with distance of a target
Enter Values:
v (velocity),
theta (launch angle),
dist (target distance),
ange (e
or margin or acceptable radius for "hit" )
Initialize Variables:
t=0 (time),
tstep = 0.1 (time step between calculations)
a=32 (Gravitational constant in ft per sec2)
Find velocity components:
va=vÂ¥cos(theta)
Vy=vAsin(theta)
Loop through all combinations:
Repeat
t= t+ tstep (Increment time step)
=v, *1-05 *a* t* t (Calculate height)
X = vx * t (Calculate horizontal distance )
plot(x,y) (Plot position of projectile )
Until y <= 0 (Until missile has hit the ground)
Test for accuracy:
If Abs(x-dist) < range
then result = Hit
else result = Miss
Figure 2: Trajectories at 60 Degree Angle
140 ft/sec and 150 ft/sec