Listing 2

// This function converts true to eccentric anomaly
// or vice versa.

// Input: x -- true or eccen anomaly
//        i -- 1 means input is eccen anom
//             2 means input is true anom
// Output: the function returns eccen or true anom
//        * Inputs/outputs are in degrees *

double enu(double x, double e, int i)
{

  double cosy,y;
  if (i) {
    // Convert eccen to true anomaly
    cosy = (e - cos(x))/(e*cos(x) - 1);
  } else {
    // Convert true to eccen anomaly
    cosy = (e + cos(x))/(1+e*cos(x));
  }
  y = acos(cosy);  // y is 0 to pi
  if (x > PI)
    y = TWOPI - y;
  return(y);
}



Sample Input/Output

Run  1 inputs:                   output:
    x = 302.424192 (eccen anom) true anom = 302.420917
    e = 0.000068
    i = 1
Run  2 inputs:                   output:
    x = 302.420917 (true anom)  eccen anom = 302.424192
    e = 0.000068
    i = 0