I am trying to derive an expression for theta (in a projectile motion context). From https://en.wikipedia.org/wiki/Projectile_motion#Angle_required_to_hit_coordinate_.28x.2Cy.29, ;
$$\theta=\arctan\Bigg(\frac{v^2\pm\sqrt{v^4-g(gx^2+2yv^2)}}{gx}\Bigg)$$
Now, I tried to do the derivation myself;
$$vt\cos(\theta)=x$$ $$0=y + vt\sin(\theta)+\frac{1}{2}at^2$$ $$t=\frac{x}{\cos(\theta)}$$ $$0=y+\frac{xv\sin(\theta)}{v\cos(\theta)}+\frac{1}{2}\frac{ax^2}{v^2\cos^2(\theta)}$$ $$0=y+x\tan(\theta)+\frac{1}{2}\frac{ax^2}{v^2\cos^2(\theta)}$$ Take $T = \tan(\theta)$ $$0=y+xT+\frac{ax^2}{2v^2}(1+T^2)$$ $$\frac{ax^2}{2v^2}T^2+xT+\bigg(\frac{ax^2}{2v^2}+y\bigg)=0$$ The quadratic formula can now be applied. $$\theta=\arctan\Bigg(\frac{-x\pm\sqrt{x^2-\frac{2ax^2}{v^2}\bigg(\frac{ax^2}{2v^2}+y\bigg)}}{\frac{ax^2}{v^2}}\Bigg)$$
Equations (1) and (2) both work, but only if $y=0$. If I set the target at (x,5), then I get different results for theta. However, if I reverse the sign on the second equation, (I.e. '-5') then the angles found will match.
Where did I miss/how do I include this in the equation?