Assuming gravity acting downwards, we can separate the horizontal and vertical motion; horizontally, it moves at a constant speed. Vertically, it is accelerating at $-g$.
Since we have the initial speed $s$, we know that for some angle $\theta$ between the $x$-axis and the initial velocity, the horizontal component of that velocity will be $v \cos(\theta)$. So the time of flight will be:
$\tau = (x_1 - x_0) / (v \cos(\theta) )$
We also know that vertically the projectile is accelerated by gravity, giving us a quadratic equation for the motion, so it will pass the elevation both on the way up and the way down (unless it coincides with the peak). This time the component of the velocity is $v \sin(\theta)$, so using $s = s_0 + ut + \frac{1}{2}a t^2$
$y_1 = y_0 + v \sin(\theta) \tau + \frac{1}{2}(-g)\tau^2$
We want $\theta$ in terms of everything else, and $\tau$ is unknown. So we want to substitute the first equation into the second. But let's reduce the number of terms for now by looking at deltas: $\alpha = x_1 - x_0$, $\beta = y_1 - y_0$ (i.e. change origin):
$\tau = \alpha / (v \cos(\theta) )$
$\beta = v \sin(\theta) \tau - \frac{1}{2}g \tau^2$
Substitute for $\tau$:
$\beta = v \sin(\theta) \alpha / (v \cos(\theta) ) - \frac{1}{2}g \alpha^2 / (v^2 \cos^2(\theta) )$
$\beta = \sin(\theta) \alpha / \cos(\theta) - \frac{1}{2}g \alpha^2 / (v^2 \cos^2(\theta) )$
$\beta v^2 \cos^2(\theta) = v^2 \cos(\theta) \sin(\theta) \alpha - \frac{1}{2}g \alpha^2 $
Well, that looks fun. Untangling trig is not my preferred way to spend the afternoon. Let's play SOH CAH TOA. Imagine a right-angled triangle with angle $\theta$, base (adjacent) $\alpha$ (to pick a known quantity) and height (opposite) $\gamma$ (our new unknown). Hypotenuse $h$ then satisfies $h^2 = \alpha^2 + \gamma^2$. We get:
$\sin(\theta) = \gamma / h$
$\cos(\theta) = \alpha / h$
$\cos^2(\theta) = \alpha^2 / h^2$
$\cos(\theta) sin(\theta) = \alpha \gamma / h^2$
Substituting:
$\beta v^2 \alpha^2 / h^2 = v^2 \alpha^2 \gamma / h^2 - \frac{1}{2}g \alpha^2$
$\beta v^2 = v^2 \gamma - \frac{1}{2} g h^2 \quad$
(don't worry, the $\alpha$ dependence is still there in $h$)
Substitute for $h^2$ now that it is only there once:
$\beta v^2 = v^2 \gamma - \frac{1}{2} g (\alpha^2 + \gamma^2)$
Get in terms of $\gamma$, as that is our link to $\theta$:
$(\frac{1}{2} g) \gamma^2 - v^2 \gamma + \frac{1}{2} g \alpha^2 + \beta v^2 = 0$
$\gamma^2 - (2 v^2 / g) \gamma + (\alpha^2 + 2 \beta v^2 / g) = 0$
One quadratic equation (eventually). Calling the common factor $f = 2 v^2 / g$, we get:
$\gamma^2 - f \gamma + (\alpha^2 + \beta f) = 0$
In the best tradition:
$\gamma = \frac{1}{2}(f \pm \sqrt{f(f - 2\beta) - 2(\alpha^2) })$
From $\gamma$, we will want $\theta$, so to avoid square terms go for $\tan$:
$\tan(\theta) = \gamma / \alpha \quad$ (SOH CAH TOA)
$f$ can be calculated separately, so in code I would do this (pseudocode):
g = 9.81; // ish
alpha = x_one - x_zero;
beta = y_one - y_zero;
eff = 2 * v * v / g;
rootterm = eff*(eff - 2*beta) - 2*alpha*alpha;
// test for imaginary roots
if(rootterm < 0) {
... cannot hit target with this velocity ...
} else {
gamma_first = (f + sqrt(rootterm))/2;
gamma_second = (f - sqrt(rootterm))/2;
theta_first = arctan(gamma_first / alpha);
theta_second = arctan(gamma_second / alpha);
}
You are then free to choose which solution you prefer. In the case that $f(f - 2\beta) = 2 \alpha^2$, they will be the same value.
I'm sure there's a shorter route to the end there, perhaps by looking at the right-angled triangle to begin with; it represents the trajectory of the projectile without gravity.