| Last change
 on this file since 1826 was             1719, checked in by cmv, 24 years ago | 
        
          | 
Adapted to version 3.5 xephem cmv 22/10/2001
 | 
        
          | File size:
            1.7 KB | 
      
      
| Rev | Line |  | 
|---|
| [1457] | 1 | /* improved by rclark@lpl.arizona.edu (Richard Clark) */ | 
|---|
|  | 2 |  | 
|---|
|  | 3 | #include <stdio.h> | 
|---|
|  | 4 | #include <math.h> | 
|---|
|  | 5 |  | 
|---|
|  | 6 | #include "P_.h" | 
|---|
|  | 7 | #include "astro.h" | 
|---|
|  | 8 |  | 
|---|
|  | 9 |  | 
|---|
|  | 10 | #define TWOPI           (2*PI) | 
|---|
|  | 11 | #define STOPERR         (1e-8) | 
|---|
|  | 12 |  | 
|---|
|  | 13 | /* given the mean anomaly, ma, and the eccentricity, s, of elliptical motion, | 
|---|
|  | 14 | * find the true anomaly, *nu, and the eccentric anomaly, *ea. | 
|---|
|  | 15 | * all angles in radians. | 
|---|
|  | 16 | */ | 
|---|
|  | 17 | void | 
|---|
|  | 18 | anomaly (ma, s, nu, ea) | 
|---|
|  | 19 | double ma, s; | 
|---|
|  | 20 | double *nu, *ea; | 
|---|
|  | 21 | { | 
|---|
|  | 22 | double m, fea, corr; | 
|---|
|  | 23 |  | 
|---|
|  | 24 | if (s < 1.0) { | 
|---|
|  | 25 | /* elliptical */ | 
|---|
|  | 26 | double dla; | 
|---|
|  | 27 |  | 
|---|
|  | 28 | m = ma-TWOPI*(long)(ma/TWOPI); | 
|---|
|  | 29 | if (m > PI) m -= TWOPI; | 
|---|
|  | 30 | if (m < -PI) m += TWOPI; | 
|---|
|  | 31 | fea = m; | 
|---|
|  | 32 |  | 
|---|
|  | 33 | for (;;) { | 
|---|
|  | 34 | dla = fea-(s*sin(fea))-m; | 
|---|
|  | 35 | if (fabs(dla)<STOPERR) | 
|---|
|  | 36 | break; | 
|---|
|  | 37 | /* avoid runnaway corrections for e>.97 and M near 0*/ | 
|---|
|  | 38 | corr = 1-(s*cos(fea)); | 
|---|
|  | 39 | if (corr < .1) corr = .1; | 
|---|
|  | 40 | dla /= corr; | 
|---|
|  | 41 | fea -= dla; | 
|---|
|  | 42 | } | 
|---|
|  | 43 | *nu = 2*atan(sqrt((1+s)/(1-s))*tan(fea/2)); | 
|---|
|  | 44 | } else { | 
|---|
|  | 45 | /* hyperbolic */ | 
|---|
|  | 46 | double fea1; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | m = fabs(ma); | 
|---|
|  | 49 | fea = m / (s-1.); | 
|---|
|  | 50 | fea1 = pow(6*m/(s*s),1./3.); | 
|---|
|  | 51 | /* whichever is smaller is the better initial guess */ | 
|---|
|  | 52 | if (fea1 < fea) fea = fea1; | 
|---|
|  | 53 |  | 
|---|
|  | 54 | corr = 1; | 
|---|
|  | 55 | while (fabs(corr) > STOPERR) { | 
|---|
|  | 56 | corr = (m - s * sinh(fea) + fea) / (s*cosh(fea) - 1); | 
|---|
|  | 57 | fea += corr; | 
|---|
|  | 58 | } | 
|---|
|  | 59 | if (ma < 0.) fea = -fea; | 
|---|
|  | 60 | *nu = 2*atan(sqrt((s+1)/(s-1))*tanh(fea/2)); | 
|---|
|  | 61 | } | 
|---|
|  | 62 | *ea = fea; | 
|---|
|  | 63 | } | 
|---|
|  | 64 |  | 
|---|
|  | 65 | /* For RCS Only -- Do Not Edit */ | 
|---|
| [1719] | 66 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: anomaly.c,v $ $Date: 2001-10-22 12:08:26 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"}; | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.