home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_05 / 9n05102b < prev    next >
Text File  |  1991-03-20  |  956b  |  38 lines

  1.  
  2. // This function converts true to eccentric anomaly
  3. //   or vice versa.
  4.  
  5. // Input: x -- true or eccen anomaly
  6. //        i -- 1 means input is eccen anom
  7. //             2 means input is true anom
  8. // Output: the function returns eccen or true anom
  9. //        * Inputs/outputs are in degrees *
  10.  
  11. double enu(double x, double e, int i)
  12. {
  13.  
  14.   double cosy,y;
  15.   if (i) {
  16.     // Convert eccen to true anomaly
  17.     cosy = (e - cos(x))/(e*cos(x) - 1);
  18.   } else {
  19.     // Convert true to eccen anomaly
  20.     cosy = (e + cos(x))/(1+e*cos(x));
  21.   }
  22.   y = acos(cosy);     // y is 0 to pi
  23.   if (x > PI)
  24.     y = TWOPI - y;
  25.   return(y);
  26. }
  27.  
  28.                 SAMPLE INPUT/OUTPUT (very circular orbit)
  29.  
  30. Run 1 inputs:                   output:  
  31.     x = 302.424192 (eccen anom) true anom  = 302.420917
  32.     e = 0.000068
  33.     i = 1
  34. Run 2 inputs:                   output:
  35.     x = 302.420917 (true anom)  eccen anom = 302.424192
  36.     e = 0.000068
  37.     i = 0
  38.