I am modeling a projectile on a computer program, and need a formula to solve for the angle necessary for a projectile shot at a given velocity to hit a target a given distance away, but not over flat ground, ie the target is higher or lower than the initial position of the projectile. Solving for theta over flat ground is fairly trivial, but I cannot solve for theta over uneven ground. First, is there even a closed form solution? Secondly, here is what I have so far--

v= velocity of the projectile

\(\displaystyle

\theta \)= the angle it is being launched at

First the parametric equations-

\(\displaystyle

y = vtsin(\theta) - \frac{gt^2}{2}

\)

\(\displaystyle

x = vtcos(\theta)

\)

So \(\displaystyle t = \frac{x}{vcos(\theta)}\)

Substituting in t,

\(\displaystyle

y = \frac{vxsin(\theta)}{vcos(\theta)} - \frac{gx^2}{2v^2cos(\theta)^2}

\)

which simplifies to

\(\displaystyle

y = xtan(\theta) - \frac{gx^2}{2v^2cos(\theta)^2}

\)

Using normal trig methods, I could not solve this equation for theta. Asking a teacher, she suggested I use Euler's identities because sometimes those are easier to work with than trig identities. So I converted

\(\displaystyle sin(\theta) \) to \(\displaystyle \frac{e^{i\theta} - e^{-i\theta}}{2} \)

and \(\displaystyle cos(\theta) \) to \(\displaystyle \frac{e^{i\theta} + e^{-i\theta}}{2i} \) to see if I could work it that way...

After manipulation, it comes out to-

\(\displaystyle

e^{i\theta} = \frac{-igx \frac{+}{} \sqrt{4y^2v^4-g^2x^4-4x^2v^4}}{2v^2(y-ix)}

\)

\(\displaystyle

\theta = i ln(\frac{-igx \frac{+}{} \sqrt{4y^2v^4-g^2x^4-4x^2v^4}}{2v^2(y-ix)})

\)

Which has an imaginary part. When I plug in what the known values for x and y are for theta = \(\displaystyle \frac{\pi}{4} \) and v = 100, this formula returns theta as imaginary, which is obviously incorrect since I know it should return \(\displaystyle \frac{\pi}{4}\). Did I go wrong somewhere? This problem cannot be new- has anyone else solved this, or know of a way to solve it? Thanks for your help!