1
$\begingroup$

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

  • 0
    In terms of the physicality of the problem, I am aware. I am interested in learning how to make solar system with more accurate simulated physics, but I think it's an unnecessary level of complexity for this particular game. My partner has debated with me the necessity of the intercept path, but I really didn't want the fleet to look like it was chasing the planet. If it would be interesting to you, I can show you what the game looks like down the road, and it might make more sense that we were willing to fudge the physics.2012-05-02

1 Answers 1

1

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.)

  • 0
    This should work nicely. If I need any more clarification, I'll post it on here. I appreciate all of your help.2012-05-05