# Intercept path to object following an elliptical path

I have a game with planet objects traveling in elliptical orbits. I want to plot a path from an object in one orbit to an object in another orbit. I'm not concerned with gravity etc as this is mainly for effect, not perfect realism. I just want it to look like ships traveling between them are intercepting them, not following them around.

Edit: In short, I want a Ship (with a known x, y, and velocity) to leave immediately to intercept a Planet that traveling on a fixed elliptical path. It doesn't have to be the shortest distance or even the shortest time, so long as the ship doesn't have to turn mid-flight to adjust. I have all of the ellipse's data, it's x, y, width, height, and angle. I also have any information on the current location of the Ship and its target Planet. I seek the x and y coordinates of the intercept or the angle from the ship's starting place. I think I'm comfortable finding one from the other.

Unfortunately, because all of this data changes as the program runs, it would be difficult for me to replace variables with constants for the sake of finding a solution here. I basically need a formula assembled that my application can plug variables into.

This is how I determine the locations of the objects based on time.

• θ = angle of the ellipse
• t = time
• a = ellipse width
• b = ellipse height
• x = ellipse x
• y = ellipse y

xplanet(t) = a cos(t) cos(θ) - b sin(t) sin(θ) + x

yplanet(t) = a cos(t) cos(θ) + b sin(t) cos(θ) + y

I found something for intercepts of objects traveling on a linear path, but I'm having trouble converting it to my purposes:

(xplanet(t))2 + (yplanet(t))2 − x2ship0 − y2ship0 = (vshipt)2

-
You probably want a $y$ instead of the second $x$ in the last equation? And I think you need to say more about what it is you want to do. Do you want to intercept one of the objects at a particular time? At a particular place? With a particular velocity? From where? What's given, what's sought? –  joriki May 2 '12 at 4:39
I tried to address your questions in my Edits above. Let me know if I need to clarify anything else. –  bpscott May 2 '12 at 11:55
I'm guessing that when you say you know the ship's velocity, you mean its speed? Velocity is a directed quantity (see e.g. Wikipedia) -- if you knew the position and velocity of the ship (assuming constant velocity, since you haven't said anything about acceleration anywhere), there would be nothing left to calculate. So I'm guessing that what you actually want to do is find out in which direction a ship with known initial position and known constant speed has to travel uniformly in order to intercept a planet travelling on a known elliptical orbit? –  joriki May 2 '12 at 12:19
By the way, are you aware that the planetary motion you describe is rather unphysical? The planet should be fastest at the perihelion and slowest at the aphelion, whereas your planet has the same lowest speed at the perihelion and aphelion and is fastest in between. Is that what you want? I think it will look weird unless the orbits are close to circles. –  joriki May 2 '12 at 12:51
You're correct. I know the speed, not the velocity. Also, like you said, I am looking to "find out in which direction a ship with known initial position and known constant speed has to travel uniformly in order to intercept a planet traveling on a known elliptical orbit" (I didn't want to confuse the issue with an awkward paraphrase). –  bpscott May 2 '12 at 16:53

I doubt there's a solution in closed form; here are some ideas for finding a solution numerically.

I'm going to simplify things by writing everything for an ellipse centred at the origin with axes parallel to the coordinate axes; to solve the general case, you can apply an isometry (rotation and/or translation) to both the ship and the ellipse to bring the ellipse into that position, then solve for the direction of the velocity vector and rotate it back by the inverse rotation.

So you have the following equations:

\begin{align} x+(t-t_0)v\cos\alpha&=a\cos t\;,\\ y+(t-t_0)v\sin\alpha&=b\sin t\;, \end{align}

where $x,y$ are the known initial coordinates of the ship at time $t_0$, $t$ is the unknown time of collision, $v$ is the known speed of the ship, $\alpha$ is the unknown angle describing the direction of the ship's velocity, and $a,b$ are the known semi-axes of the ellipse. (You didn't have a phase or an angular velocity in your formulation; I'm assuming that you're shifting and scaling time such that you don't need them.)

There are two unknowns, $\alpha$ and $t$. We can either eliminate $t$ to get an equation for $\alpha$, or eliminate $\alpha$, solve for $t$ and substitute it into one of the equations to obtain $\alpha$.

To eliminate $t$, multiply the first equation by $b$ and the second by $a$, then square and add them to obtain

$$(bx)^2+(ay)^2+2\delta(bx\cos\alpha+ay\sin\alpha)+\delta^2(b^2\cos^2\alpha+a^2\sin^2\alpha)=1$$

with $\delta=(t-t_0)v$. This can be solved for $\delta$, and thus for $t$, and substituting the result into one of the two original equations yields an equation for $\alpha$ that you could solve numerically. However, this looks rather unpleasant; the easier route might be to eliminate $\alpha$ instead, then solve for $t$ numerically and then substitute $t$ into the original equations to get $\alpha$.

To do this, write the equations as

\begin{align} \delta\cos\alpha&=a\cos t - x\;, \\ \delta\sin\alpha&=b\sin t - y \end{align}

and then square and add them to obtain

$$(t-t_0)^2v^2=(a\cos t-x)^2+(b\sin t-y)^2\;.$$

Solve this numerically for $t$, and then obtain $\alpha$ e.g. from

$$\alpha = \operatorname{atan2}(b\sin t-y,a\cos t-x)\;,$$

where $\operatorname{atan2}(y,x)$ is the two-argument arctangent function available in most programming environments. (Watch out, sometimes the arguments are the other way around.)

-
This should work nicely. If I need any more clarification, I'll post it on here. I appreciate all of your help. –  bpscott May 5 '12 at 2:08