# Solve equation in order to get theta value.

I'm programming a game where I need projectiles to hit moving targets. I was able to make my projectile hit accurately a stationary target using a formula I found on Wikipedia about projectile trajectories.

Now, I couldn't figure out how to hit a moving target. So I stumbled upon his question: Trajectory of a projectile meets a moving object (2D)

I would be very happy to understand how could I solve this equation in order to get the theta value. I was never good at mathematics, and unfortunely, learning math by myself has been very hard. So, could anybody explain me the required steps to end with something like $θ = (...)$. The equation of the matter is the following: $$gx^2+2(v\cosθ+u\cosϕ)(vy\cosθ+uy\cosϕ−vx\sinθ+ux\sinϕ)=0$$

Thanks in advance. (if anything is not correct, please inform me, first post :))

## 1 Answer

Introducting intermediate constants, your equation has the form

$$(a\cos\theta+b)(c\cos\theta+d\sin\theta+e)+f=A\cos^2\theta+B\sin\theta\cos\theta+C\cos\theta+D\sin\theta+E=0,$$ not very "solution friendly".

We can rationalize it by means of the transform

$$\cos\theta=\frac{u^2-1}{u^2+1},\sin\theta=\frac{2u}{u^2+1}$$ and this yields a quartic

$$A(u^2-1)^2+2Bu(u^2-1)+C(u^4-1)+2Du(u^2+1)+E(u^2+1)^2=0.$$

There are closed formulas, but they can be painful to use, probably better to use a numerical solver.

• Although I believe this is a simplification, my skills doesn't allow me to solve yet. I'll try to give this to some friends way more talented than me, and I'll say something then. – jorgenoro Sep 21 '16 at 12:23
• @jorgenoro: in a way this post is to show that there is no easy solution. – Yves Daoust Sep 21 '16 at 12:33