Skip to main content
3 of 10
corrected everything; added 86 characters in body
Chaosed0
  • 773
  • 5
  • 17

If I understand correctly, you have a planet's position & velocity, as well as a ship's position and speed. You want to get the ship's movement direction. I'm assuming the ship's and planet's speeds are constant.

Unfortunately, without latex, I can't format this answer very well, but we'll attempt to make do. Let:

  • s_p = the ship's initial position (s_p.x and s_p.y, in components)
  • s_s = the ship's speed (s_s.x, s_s.y, likewise)
  • s_a = the ship's bearing (angle of movement, what we want to calculate)
  • p_p = the planet's initial position, global coords
  • p_r = the planet's distance (radius) from the center of orbit, derivable from p_p
  • p_a = the planet's initial angle in radians, relative to the center of orbit
  • p_s = the planet's angular velocity (rad/sec)
  • t = the time to collision (this turns out to be something we must calculate as well)

Here's the equations for the position of the two bodies, broken down into components:

ship.x = s_s.x * t * cos(s_a) + s_p.x
ship.y = s_s.y * t * sin(s_a) + s_p.y

planet.x = p_r * t * cos(p_a + p_s) + p_p.x
planet.y = p_r * t * sin(p_a + p_s) + p_p.y

Since we want ship.x = planet.x and ship.y = planet.y at some instant t, we obtain this system of equations:

s_s.x * t * cos(s_a) + s_p.x = p_r * t * cos(p_a + p_s) + p_p.x
s_s.y * t * sin(s_a) + s_p.y = p_r * t * sin(p_a + p_s) + p_p.y

There are two equations and two variables (t and s_a) to solve for, so it appears to be solvable at first glance. I don't have time right now to solve it by hand, but I'm leaving this as a wiki if anyone wants to give it a shot.

Chaosed0
  • 773
  • 5
  • 17