# Simulation of Kepler orbits

1. Jan 3, 2016

### 450AHX

Hi.

I'm writing a simulation of (an approximation of) the solar system. So far I've been able to translate the Wikipedia article on Kepler's laws to a function that uses a description of an elliptical orbit (eccentricity, periapsis, known position in time) to return a position when passed an arbitrary time. My issue is with generating the ellipse when given only a position and a velocity; my analytical geometry-fu is too weak for conics. I can't find much info on this, beyond references to offloading the calculation to software suites (e.g. HORIZONS and SPICE), which is of no use to me.
Can anyone give me a nudge in the right direction?

Thanks.

2. Jan 3, 2016

### rootone

I think you could have a problem in that 'many body' systems can be really hard to get right.
Especially when many of the bodies making up the whole system are either not well known, or not known at all.
You could probably use Keplers laws to give a reasonable prediction for the solar system using just the Sun and major planets for maybe a few thousands of years.
I think that beyond that extent it could not be reliable due to chaos caused by the minor planets (and other things that are not included in the 'perfect' model)

3. Jan 3, 2016

### 450AHX

Sorry, I forgot to mention that this is just an approximation for a game; I'm not trying to predict the real future locations of objects. Heavy objects will be put on Kepler rails, and only negligible mass objects will use n-body dynamics. I need to be able to find an ellipse from position and velocity because I want to be able to detect stable orbits of negligible mass satellites to avoid computing the n-body dynamics when not necessary.

4. Jan 4, 2016

### Janus

Staff Emeritus
If you are starting with position and velocity you can work out the orbit in the following way:

From the formula
$$v^2 = GM\left ( \frac{2}{r}- \frac{1}{a} \right )$$
(where r is the length of the radial line and v is the magnitude of the velocity. )

you can solve for a, the semi-major axis. From which, you can get the period of the orbit.

Then from:
$$\pi a^2 \frac{\sqrt{1-e^2}}{P} = \frac{rv \cos \theta }{2}$$

Where theta is the angle between a line perpendicular to the radial line and the velocity vector ( i.e., for a perfectly circular orbit theta would always be 0), and P is the period of the orbit found above, you can solve for e, the eccentricity of the orbit.(each side of the equation gives the Areal velocity)

Then you can use $$r= \frac{a(1-e^2)}{1+ e \cos \phi}$$

to solve for phi, which gives you the angular distance from the present position to periapis.

This should give you the shape of and the orientation for the line of apsides for your orbit.

5. Jan 4, 2016

### 450AHX

Thanks. That's what I was looking for.