TITLE: Intersection with object on ellipsoid path
QUESTION [5 upvotes]: In my game I need to calculate the time when a ship arrives at the planet. What is known is ship's starting position and velocity (which is constant), and planet’s position at a given time (it follows an elliptic path). To be more specific:
Regarding the ship:
$x_0, y_0$ - ship's initial position
$v$ - ship's constant speed
Regarding the planet:
The planet’s position is given by $$\begin{align}x(t)&=a\cos{\omega_0t}\\y(t)&=b\sin{\omega_0t}\end{align}$$ with $a\ge b\gt0$ and $\omega_0\gt0$. I.e., the planet’s path follows an ellipse in standard position with a phase of $0$.  
Now, what I need to know, is at what point does the two positions intersect (ship's position and planet's position). So I am either looking for the intersection time $t_i$, or an intersection point $p_i$, or angle $\alpha$ at which the ships should be fired, or distance $d_i$ of intersection point from starting point $x_0, y_0$. Any of these 4 things should do (figuring one from the other is trivial, of course). I am looking for the closest such intersection point of course (the smallest such $d_i$ or $t_i$ of all possible ones).
In other words, I need to know at what angle should I send the ship from $x_0, y_0$ so that it will arrive at the planet in smallest possible time.
UPDATE 29.12.2016
I am pausing my work on this problem, since I've already spent 5 days on it and am really tired of it. I've tried all kinds of approaches, but the code is buggy and this problem is much more complex than I first thought. I will finish it at some point in the future, but right now there are other aspects of the game I have to implement. So I'd like to help everyone who's contributed, I'll upvote/accept your answers once I get to finish the implementation (I'll present my final algorithm at that point and post it for anyone to use it). Thanks again to everybody for now!
(P.S., if interested, this is how the thing works when it works:
https://youtu.be/KjQCOkWVIvg)

REPLY [2 votes]: I think that finding $t_i$ may be the simplest way to approach this
problem, although no approach is really simple.
The distance from your spaceship's starting position
to the position of the planet at time $t$ is
$$
\sqrt{(a\cos(\omega_0 t) - x_0)^2 + (b\sin(\omega_0 t) - y_0)^2}.
$$
Assuming the spaceship starts at time $t_0,$
the distance from the the spaceship's starting position to the
spaceship's position at time $t$ is
$v(t - t_0).$
(I introduced the parameter $t_0$ because it was not clear that
you wanted the spaceship to start at the instant when the planet
passed the point $(a,0).$ If you did want the spaceship to start
at that exact instant, just set $t_0=0$ in all the equations;
it will simplify them a bit.)
In order for the spaceship to intercept the planet at time $t_i,$
the spaceship and the planet must be at the same distance from the
spaceship's starting point at that instant. that is,
$$
\sqrt{(a\cos(\omega_0 t_i) - x_0)^2 + (b\sin(\omega_0 t_i) - y_0)^2} = 
v(t_i - t_0).
$$
So if we define a function $f$ by
$$
f(t) = 
\sqrt{(a\cos(\omega_0 t_i) - x_0)^2 + (b\sin(\omega_0 t_i) - y_0)^2}
 - v(t_i - t_0),
$$
one way to find a time when the spaceship can intercept the planet
is to solve for $t$ in the equation $f(t)= 0.$
Unfortunately, I'm fairly sure there is no closed-form solution
for this equation, at least not using the functions you would have
available in a typical programming environment. So the only way to solve
the equation is by numeric methods--basically, making guesses and
refining the guesses until you get "close enough" to the exact solution.
The distance of the planet from from the spaceship's initial position, $(x_0,y_0),$ periodically increases and decreases.
The rate of increase has some maximum value $u_\max$.
If $v$ is greater than or equal to $u_\max$
then there is exactly one solution to the equation $f(t)= 0.$
The planet can never increase its distance from $(x_0,y_0)$
faster than it is traveling, and it never travels faster than
the speed $a\omega_0,$ so if $v \geq a\omega_0$ the problem is
slightly simpler than it might be.
If $v < a\omega_0$ then you either have to figure out the value
of $u_\max$ so that you can determine whether $v \geq u_\max$,
or you can decide to solve the problem without
making the assumption that the solution to $f(t) = 0$ is unique.
Let's consider first what happens when we know the solution is unique.
We know that $f(t)>0$ when $t=t_0$;
now find a time $t_1$ such that $f(t_1)< 0.$
Setting $r_0=\max\{a,b\},$
every part of the ellipse is inside the circle of radius $r$
around $(0,0),$ so no part of the ellipse can be further than
$r_0 + \sqrt{x_0^2+y_0^2}$ from the starting position of the
spaceship. So any value of $t_1$ such that
$$
t_1 > t_0 + \frac{r_0 + \sqrt{x_0^2+y_0^2}}{v}
$$
will be sufficient.
Now we can use one of several ways to find an approximate value of $t_i,$
but the simplest may be the "bisection" method:
find the midpoint of your interval of time, compute $f(t)$ at the midpoint,
and then change your interval to the interval bounded by the midpoint and one
of the two previous endpoints of the interval so that
$f(t)$ changes sign between the new endpoints.
In other words, split your interval of time in half and replace the
old interval with the half-interval in which $f(t)$ changes from
positive to negative.
Repeat until the interval is so small that it no longer makes a difference
where in the interval the solution is
(that is, no matter which time you choose, the spaceship will get close
enough to the planet at that time that you consider it a "hit").
If a separation of $\delta$ units of distance is "close enough" in space,
then a time difference of $\delta/v$ will be "close enough"
(possibly even better than "close enough") in time.
In the simple case (unique solution), at this point you're done.
The rest of this answer concerns the more complicated "possibly
non-unique solution" version of the problem.
If you do not know that the solution is unique, you can still use the
bisection method, but if you use it as described above it may not
find the earliest solution.
It is possible that $f(t)$ has a local minimum that is less than zero,
but that $f(t)$ is positive at some time after that.
There would then be three (or five or seven or more) solutions
before $f(t)$ goes negative for the last time.
To be sure that you don't miss the first solution of $f(t)=0,$
you have to find out at what times the local minimums occur.
To find when the local minimums occur, take the derivative of
$f(t)$ with respect to $t$ (or have Wolfram Alpha do it for you), and solve for $t$ in the equation in which that function is zero.
You only need to find one solution $t=t_2,$ it doesn't matter whether
it is the "earliest", and then all other solutions are just $t_2$
plus or minus some multiple of $2\pi/\omega.$
Find the earliest local minimum; 
if $f(t)<0$ at that time then the solution is
between $t_0$ and that time; otherwise try the next local minimum,
and the next, and so forth until you find two local minimums such that
$f(t)>0$ at the first one and $f(t)<0$ at the second, and then
look for a solution between those two times; it will be the earliest solution.
(Of course if $f(t)=0$ at any of the local minimums then that's your
solution. You could even accept the local minimum as a solution
if $-\delta < f(t) < \delta$ where $\delta$ is a distance that you
consider "close enough" to count as an interception.)