Let’s see if we can find out the optimal angle at which to launch a ball, in order to have it
travel the furthest. Write a function find_best_angle that takes as arguments an initial
elevation and an initial velocity, and which finds the best angle at which to hit the ball to
optimize distance traveled. You will probably want to write a recursive function that
tries different angles between 0 and pi/2 radians, sampled between 0 and 90 degrees, sampled every 1 degree.
int find_best_angle(float velocity, float elevation)
{
// Your code here
}
For the in vacuum case (no air resistance) the path followed by the ball is a parabola.
In this case there will be an optimum angle (I think its 45 degrees but can't be bothered to check)
When there is air resistance then the optimum angle will depend on other factors such as the launch speed, and air drag on
the ball. This is also a much more difficult problem, you have to integrate.
The pdf at the link gives a crude approximating method (Euler's method) but there are also more accurate integrators.