Calculating Launch Angle Given Distance with Added Height (which itself depends on launch angle) In my physics class we have learned to calculate a desired launch angle to allow a projectile to hit a target given the target’s distance away and the initial velocity. 
Now in this case the initial velocity of the projectile occurs at the axis of rotation of the so called “cannon” that is launching the projectile. But what if the initial velocity occurs at the tip of the cannon? When the launch angle changes, so does the launch height and the distance to the target. 
With this added information I was NOT able to solve for the desired launch angle using the kinematic equations of motion. Is this problem possible to solve? 
Please see the attached pdf for a better visualization and the equations
As requested by a comment, here is the equation I couldn’t solve for $\theta$:
$$d - r \cos(\theta) = \frac{ v \cos(\theta) }{-g} \cdot  \left( -v \sin(\theta)\pm \sqrt{\bigl(v \sin(\theta)\bigr)^2 + 2g \bigl( h + r \sin(\theta) \bigr) \vphantom{\Big|}}\right)$$
This question has been asked before here but not answered.

In the simple case
$x(\theta, t) = v (\cos \theta) t\\
y(\theta, t) = v (\sin \theta)t - \frac 12 g t^2$
Where $v$ is your launch velocity.  $\theta$ is your launch angle, $t$ is time, and $g$ is your gravitational constant.
Based on the picture, you have the cannon at some initial altitude, $y_0$.
$x(\theta, t) = v (\cos \theta) t\\
y(\theta, t) = v (\sin \theta)t - \frac 12 g t^2+y_0$
Then end of your cannon is just one more translation.
$x(\theta, t) = v (\cos \theta) t + d\\
y(\theta, t) = v (\sin \theta)t - \frac 12 g t^2+y_0 + h$
But it might help if you see that $\frac {h}{d} = \tan \theta$ 
and the length of the barrel  $l = \sqrt {h^2+ d^2}$
$x(\theta, t) = v (\cos \theta) t + l\cos\theta\\
y(\theta, t) = v (\sin \theta)t - \frac 12 g t^2+y_0 + l\sin\theta$
