% xfinal = ftarget(thetas, opt)
% Compute impact points as a function of angles for the ballistics
% ODE with parameters given in opt. In addition to the basic ODE
% parameters, opt.s should be set to the launch speed.
%
function xfinal = ftarget(thetas, opt)

xfinal = 0*thetas;
for j = 1:length(thetas)
theta = thetas(j);
v0 = (opt.s)*[cos(theta); sin(theta)];
y0 = [0; 0; v0];
tfinal = 2*v0(2)/opt.g;
if tfinal == 0
xfinal(j) = 0;
else
odeopt = odeset('Events', @hitground);
[tout,yout] = ode45(@(t,y) fball(t,y,opt), [0 tfinal], y0, odeopt);
xfinal(j) = yout(end,1);
end
end