Planetary Orbits
----------------
We will derive some of the basic formulas for planetary orbits from
first principles.  Let r be the distance of the satellite from the
primary and @ measure the angle relative to the primary.  Assume that
the satellite has negligible mass compared to the primary.

Derivatives in Polar Coordinates
--------------------------------
Let us start out with the formula for x in polar coordinates and take
a couple of derivatives with respect to time:

x   = r cos(@)

x'  = r' cos(@) - r sin(@) @'
                                               2
x'' = r'' cos(@) - 2 r' sin(@) @' - r cos(@) @' - r sin(@) @''

if @ = 0, that is, the coordinates are rotated so that the y component
of the position is 0, then x'' represents the radial acceleration of the
satellite:

    -GM             2
    --- = r'' - r @'                                         [1]
    r^2

if @ = pi/2, that is, the system is rotated so that the x component of
the position is 0, then x'' is the acceleration perpindicular to the
radius:

    0 = 2 r' @' + r @''                                      [2]

Kepler's Second Law (Equal Area in Equal Time)
----------------------------------------------
Multiply the right hand side of [2] by r/2 and you have the derivative
of 1/2 r^2 @', which is the area swept out by the satellite per unit
time. Equation [2] says that 1/2 r^2 @' is a constant

    1  2
    - r @' = k                                               [3]
    2         1

Equation [3] is precisely Kepler's Second Law of Planetary Motion; a
planet sweeps out equal areas in equal times.

Conservation of Energy
----------------------
Let us look at the square of the velocity, which is proportional to the
kinetic energy of the satellite

     2     2    2  2
    v  = r'  + r @'                                          [4]

Take half the time derivative of [4], then apply [2] and then [1]:

                           2    2
    v v' = r' r'' + r r' @'  + r @' @''

                           2
         = r' r'' - r r' @'

              -GM
         = r' ---                                            [5]
              r^2

If we integrate [5] and rearrange, we get

    1  2   GM
    - v  - -- = k                                            [6]
    2       r    2

When [6] is multiplied by the mass of the satellite, it becomes the law
of conservation of energy.  1/2 mv^2 is the kinetic energy and -GMm/r is
the potential energy of the satellite.

If k_2 is positive, the satellite has enough kinetic energy to escape
the primary's gravity.  If k_2 is negative, the satellite will stay in
orbit around the primary.

Using Initial Information
-------------------------
So now we have two constants.  Both can be computed from the initial
position, p, and velocity, v, of the satellite relative to the primary:

         1
    k  = - |p x v|                                           [3a]
     1   2

         1    2  GM
    k  = - |v| - ---                                         [6a]
     2   2       |p|

Kepler's First Law (Elliptical Orbits)
--------------------------------------
Dividing [4] by @'^2 and rearranging, then using [3] and [6] to supply
@' and v in terms of r, gives:

      r' 2     v  2    2
    ( - )  = ( - )  - r
      @'       @'

                   GM    2 k_1  2    2
           = 2(k + --)/( ----- )  - r
                2   r     r^2

               k_2    4    GM     3    2
           = ------- r + ------- r  - r                      [7]
             2 k_1^2     2 k_1^2

If we divide [7] by r^4 and change variables to s = 1/r, we get

      s' 2     2     GM          k_2
    ( - )  = -s  + ------- s + -------
      @'           2 k_1^2     2 k_1^2

                GM    2          GM    2    k_2
           = (-------)  - (s - -------)  + -------
              4 k_1^2          4 k_1^2     2 k_1^2

              2        2
           = c  - (s-b)                                      [8]

where b = GM/(4 k_1^2) and c^2 = b^2 + k_2/(2 k_1^2).  Thus, rearranging
the terms in [8] and taking square roots, we get

               (s-b)'
    @' = -------------------
         sqrt(c^2 - (s-b)^2)

              u'
       = -----------                                         [9]
         sqrt(1-u^2)

where u = (s-b)/c.  The right hand side of [9] is the derivative of
acos(u).  Thus, if we integrate [9] and solve for r, we get

               1
    r = ----------------                                    [10]
        b + c cos(@-k_3)

Equation [10] is the polar equation for an ellipse with a focus at the
origin.  k_3 is the angle of periapsis, usually taken to be 0.  Since
we know that the minimum distance is a(1-e) and the maximum is a(1+e),
we get that

          a(1-e^2)
    r = ------------                                       [10a]
        1 + e cos(@)

where a(1-e^2) = 1/b and e = c/b.  Equation [10a] is Kepler's First Law
of Planetary Motion; the orbit of a planet is an ellipse with the Sun at
one focus.

In terms of the basic orbital constants from [3a] and [6a],

           GM
    a = - -----                                            [10b]
          2 k_2

and

                          k_1  2
    e = sqrt( 1 + 8 k_2 ( --- )  )                         [10c]
                          GM

Solving for @ yields

             1   4 k_1^2
    cos(@) = - ( ------- - 1 )                             [10d]
             e     GM r

Vis-Viva Equation
-----------------
Equation [4] says that when r' = 0, v = r @'.  Equation [3] says that
r @' = 2 k_1/r.  Thus, when r' = 0,

          k_1
    v = 2 ---                                               [11]
           r

Combining [11] with [6], we get that when r' = 0,

      k_1^2   GM
    2 ----- - -- = k                                        [12]
       r^2     r    2

multiplying [12] by r^2 and rearranging, we get that when r is maximum
or minimum,

       2            2
    k r  + GMr - 2 k  = 0                                   [13]
     2              1

The sum of the roots of [13] is -GM/k_2.  Thus, the semimajor axis, the
average of the minimum and maximum distance of an elliptical orbit, is
a = -GM/(2k_2).  Therefore, we get

           GM
    k  = - --                                               [14]
     2     2a

Using [14] in [6], we get the Vis-Viva equation

     2        2   1
    v  = GM ( - - - )                                       [15]
              r   a

Kepler's Third Law (Period-Distance Relation)
---------------------------------------------
The product of the roots of [13] is -2k_1^2/k_2 while the product of the
minimum and maximum distance of an elliptical orbit is a^2(1-e^2).  With
[14] we get that

     2     k_2  2    2     GM  2    2    GMa     2
    k  = - --- a (1-e ) =  -- a (1-e ) = --- (1-e )         [16]
     1      2              4a             4

We also know that k_1 is the constant rate that area is swept out along
the elliptical orbit.  Over one whole period P, the area swept out is
pi a^2 sqrt(1-e^2), thus

              2        2
    k P = pi a sqrt(1-e )                                   [17]
     1

Thus, squaring [17], using [16], and cancelling, we get

        2       2 3
    GM P  = 4 pi a                                          [18]

Equation [18] verifies Kepler's Third Law of Planetary Motion; the
square of the period of a planet is proportional to the cube of the
semimajor axis of its orbit.

Time Dependence
---------------
Combining [10d] and [18] and using the results from Kepler's Equation,
we can compute the position in orbit at any time.

Rob Johnson