How to do the Math behind Two Body Problem Ok So, I recently checked out Lazy Foo Tutorials for SDL 1.2, and I read the tutorials. I want to program a 2 body problem onto the screen. So where the user enters the data for both body, velocity, mass etc, the distance b/w the bodies and such. After that the bodies start to move on the screen. What I wanted to know was what math would I need to know to program it. I looked into Wikipedia and other sites pertaining to the 2 Body Motion, does the math really need to be as complex as the math that is given on the sites? http://en.wikipedia.org/wiki/Two-body_problem Or could I opt to do a simple Formula of Universal Gravitation http://www.regentsprep.org/regents/physics/phys01/unigrav/Image25.gif and then just after every frame just update the two dots on the screen according to the points given by the formula?
 A: Let $M=m_1+m_2$.
In a suitable (inertial) frame of reference the motion is planar (the plane can be supposed the $xy$ one) and the position vectors  of the bodies are $$\frac {m_2}M \mathbf r$$ and $$-\frac {m_1}M \mathbf r$$ where $\mathbf r$ satisfies$$\ddot {\mathbf r} =-\frac {GM}{r^3} \mathbf r $$The latter can be solved using the Euler-Cromer method.
If $\,\mathbf r(0)=(x_0,y_0)$ and $\,\dot{\mathbf r}(0)=(v_{x,0},v_{y,0})$, then
for $i=0,1,2,\dots$$$\begin{align}  r_i &=\sqrt{x_i^2+y_i^2} \\ \\ v_{x,i+1} &=v_{x,i}-\frac {GMx_i}{r_i^3}\Delta t \\ \\v_{y,i+1} &=v_{y,i}-\frac {GMy_i}{r_i^3}\Delta t \\ \\x_{i+1} &=x_i+v_{x,i+1}\Delta t \\ \\y_{i+1} &=y_i+v_{y,i+1}\Delta t \\ \\\end{align}$$
A: The math of solving the two body problem is fairly difficult (differential equations), but implementing the solution is algebra.  You can look up how to calculate the energy, angular momentum, major/minor axis, etc and use those in your program.  That will allow you to display the orbit nicely as long as there are no perturbations.  Your last thought on time-stepping the gravitational attraction will be much more flexible and not to tough to program.  Just evaluate the forces on each body, calculate the acceleration (which can be gravity, rocket thrust, etc.) update the velocity, update the position, loop.
