I've been trying to write code that will calculate the required intercept angles of a projectile launch to hit a moving target, a person running around a game world. I have no issues programming things, but I need a bit of help with the mathematics.
The projectile's motion in a 3-dimensional Cartesian coordinate system is modeled as the solutions to the following initial value problems (taking advantage of the fact that motion along one axis is independent of the others). The coordinate system is rotated so that y points "upward" (against the direction of gravity), and x and z point "horizontally". It is still right-handed. Sorry about the ASCII equations; I don't have enough reputation to post images.
$x(0) = c_1$
$x'(0) = v \cos(θ)\cos(φ)$
$x''(t) = -0.01x'(t)$
$y(0) = c_3$
$y'(0) = v \sin(φ)$
$y''(t) = -0.03 + -0.01y'(t)$
$z(0) = c_2$
$z'(0) = v \sin(θ)\cos(φ)$
$z''(t) = -0.01x'(t)$
θ (horizontal angle), φ (elevation angle), and v are the launch parameters, but I can only control the two angles.
I have no problem solving these differential equations to derive the components of the projectile's velocity, but I have a moving target to contend with. Let's say X(t, θ, φ, v) is the projectile's position as a function of time with given launch parameters guaranteed to stay constant with respect to changing t. I also have Y(t) as the target's position as a function of time, which is differentiable. However, this function doesn't have a clean analytical solution because the moving person's acceleration is often not differentiable (as when trying to intercept someone jumping off a cliff -- his acceleration will be about -0.03 m/s^2 until he hits the ground, when it suddenly goes to 0). I know I can remove this discontinuity, but still I'm left with a piecewise function which is really hard to use. This made my second approach by modeling the relative positions, velocities, and accelerations with differential equations fail.
I've also tried simplifying the x and z coordinates into just one coordinate, and modeling the projectile as traveling an arc within a plane; this works well since there's no wind, and I can hit any static target in range accurately. But this only calculates based on the target's position and essentially calculates a function Z(φ) that is the altitude of the projectile when it is either directly above or below the target. I then calculate the roots of Z by using Newton's method, getting the angle (sometimes two).
I tried adapting the static method by calculating the time-of-flight of the projectile to the target's original position, using this to estimate the target's moved position, repeating for a few iterations, and then firing at the final moved position, but this method resulted in worse accuracy than simply spreading shots out around the static target. I think it diverged.
Now I'm stuck. I can't figure out a numerical method to find the required launch parameters given the target's position Y(t) as a function of time and a function X(t, θ, φ, v) and their derivatives. Is there anything that gives a reasonable degree of accuracy (10% or so) without anything a modern Intel processor can't do in about 50ms?
Edit I don't care when the time of impact happens; I just need the paths to intersect at a given time. I can calculate the target's position at any point in the near future (or in the past).