Calculate velocity vector in an orbit This is a very specific question for a video game that I am the principle developer of. Having calculated the parameters of an elliptical method, I know the following:
$G$ = gravitational constant
$m$ = mass of the planet
$r$ = distance from planet to spaceship
$a$ = semimajor axis
$P_1$ = position of the spaceship = $ (x_1,y_1) $
$P_2$ = position of planet = $ (x_2,y_2) $
$ r_p $ = periapsis distance
$ v_p $= velocity at periapsis
$v$ = velocity = $\sqrt{G m\left(\dfrac{2}{r} - \dfrac{1}{a}\right)} $
I am trying to solve where the spaceship will be one second from now; specifically, the direction angle of the velocity. Here is what I have so far:
$ \phi = \arccos\left(\dfrac{r_p v_p}{rv}\right) $
$x = v \cdot \cos \phi $
$y= v \cdot \sin \phi $
...And here I get stuck. I think I need to get the vector perpendicular to the radius vector, and then somehow rotate $\phi$ by that vector, but I do not know how. (I also suspect there is something wrong with the $x$ and $y$ calculations; should the eccentricity of the ellipse somehow factor in?) What are the last few steps?
 A: More of an alternative suggestion than an answer to your parameterized ellipse approach. I've recreationally programmed a few similar many-body simulations myself (e.g., click my profile, then my homepage, then click on that voronoi link -- the points are moving under a mutual force law). Just model the force (gravitational in your case) directly, and the ellipse will emerge all by itself. That's way easier to program than the parameterized ellipse, the only catch being its computational complexity will take more computer time.
Start with your initial conditions $(x_i,y_i),i=1,2$ and the ship's $v_x,v_y$ at $t=0$ (for more realism, you might want to add a $z$-component and display projections on an $x,y$-plane representing a window through which the observer is looking). Choose a small timestep, say $dt=0.01\mbox{secs}$, and calculate $x_2(t+dt) = x_2(t) + v_x(t)dt$, ditto for $y$, as usual.
Then update $v_x,v_y$ for the next timestep by calculating the (gravitational) force $F_x(t),F_y(t)$ on the ship (ignoring the planet which I guess you're assuming is stationary), and the corresponding acceleration $a_x(t),a_y(t)$ (whereby the ship's mass will cancel out). So $v_x(t+dt)=v_x(t)+a_x(t)dt$, ditto for $y$. And now you're ready for the next timestep.
As I think you can see, the calculation's easy and straightforward. Only problem is the computer may get "tired" calculating all those timesteps (although if your game's animated you'll need frame-by-frame $x,y$'s anyway). But if computer time's not a problem, I can pretty much guarantee you this is the better/easier/more_general way to design the code. For example, it's pretty trivially generalizable to a many-body situation for which there doesn't even exist a closed-form ellipse-like solution.
