home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / astrnomy / ephem421.zip / ANOMALY.C < prev    next >
C/C++ Source or Header  |  1990-09-13  |  586b  |  30 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "astro.h"
  4.  
  5. #define    TWOPI    (2*PI)
  6.  
  7. /* given the mean anomaly, ma, and the eccentricity, s, of elliptical motion,
  8.  * find the true anomaly, *nu, and the eccentric anomaly, *ea.
  9.  * all angles in radians.
  10.  */
  11. anomaly (ma, s, nu, ea)
  12. double ma, s;
  13. double *nu, *ea;
  14. {
  15.     double m, dla, fea;
  16.  
  17.     m = ma-TWOPI*(long)(ma/TWOPI);
  18.     fea = m;
  19.     while (1) {
  20.         dla = fea-(s*sin(fea))-m;
  21.         if (fabs(dla)<1e-6)
  22.         break;
  23.         dla /= 1-(s*cos(fea));
  24.         fea -= dla;
  25.     }
  26.  
  27.     *nu = 2*atan(sqrt((1+s)/(1-s))*tan(fea/2));
  28.     *ea = fea;
  29. }
  30.