InitHeight = 1.5;
GravAcc = 9.8;
InitVel = 4;
InitAngle = pi/4;

t = 0:0.001:(1-0.001);
x = InitVel*cos(InitAngle)*t;
y = InitHeight + InitVel*sin(InitAngle)*t - 0.5*GravAcc*t.^2;
Traj = InitHeight + tan(InitAngle)*x - 0.5*GravAcc*(x.^2/(InitVel^2*cos(InitAngle)^2));
plot(x,Traj,x,zeros(1,1000),'k--');
xlabel('Distance [m]');
ylabel('Height [m]');
title('Ballthrow');
legend('Trajectory','Ground');

[r,c] = find(y>0);
disp(['The ball flies ',num2str(x(c(end)+1)),' meters']);
