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