Solving for theta of a projectile over uneven ground

Hello- I put this question in this forum because I didn't really think it fell under "trigonometry", and this was the only category that seems to somewhat fit.

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

= the angle it is being launched at

First the parametric equations-

So

Substituting in t,

which simplifies to

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

to

and to to see if I could work it that way...

After manipulation, it comes out to-

Which has an imaginary part. When I plug in what the known values for x and y are for theta = and v = 100, this formula returns theta as imaginary, which is obviously incorrect since I know it should return . 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!