30 double improve_mean_to_eccentric_annomaly_guess(
const double e,
const double M,
const double x)
44 dx = -f/(fp+dx*fpp/2.);
45 dx = -f/(fp+dx*fpp/2.+dx*dx*fppp/6.);
52 const int ORBEL_EHIE_NMAX = 3;
54 int nper =
static_cast<int>(M/(2.*M_PI));
56 if(M<0.) M = M + 2.*M_PI;
61 double x = pow(6.*M,1./3.);
62 for(
int i=1;i<=ORBEL_EHIE_NMAX;++i)
63 x = improve_mean_to_eccentric_annomaly_guess(e,M,x);
69 double x = pow(6.*M,1./3.);
70 for(
int i=1;i<=ORBEL_EHIE_NMAX;++i)
71 x = improve_mean_to_eccentric_annomaly_guess(e,M,x);
76 void calc_cartesian_for_ellipse(
double&
x,
double& y,
double & z,
double &vx,
double &vy,
double &vz,
const double a,
const double e,
const double i,
const double O,
const double w,
const double M,
const double GM)
80 sincos(cape,&scap,&ccap);
81 double sqe = sqrt(1.-e*e);
82 double sqgma = sqrt(GM*a);
83 double xfac1 = a*(ccap-e);
84 double xfac2 = a*sqe*scap;
85 double ri = 1./(a*(1.-e*ccap));
86 double vfac1 = -ri*sqgma * scap;
87 double vfac2 = ri*sqgma*sqe*ccap;
89 double sw, cw, so, co, si, ci;
93 double d1[] = { cw*co-sw*so*ci, cw*so+sw*co*ci, sw*si};
94 double d2[] = {-sw*co-cw*so*ci,-sw*so+cw*co*ci, cw*si};
95 x = d1[0]*xfac1+d2[0]*xfac2;
96 y = d1[1]*xfac1+d2[1]*xfac2;
97 z = d1[2]*xfac1+d2[2]*xfac2;
98 vx = d1[0]*vfac1+d2[0]*vfac2;
99 vy = d1[1]*vfac1+d2[1]*vfac2;
100 vz = d1[2]*vfac1+d2[2]*vfac2;
102 void calc_keplerian_for_cartesian(
double& a,
double& e,
double& i,
double& O,
double& w,
double& M,
const double x,
const double y,
const double z,
const double vx,
const double vy,
const double vz,
const double GM)
104 const double TINY = 1.e-8;
106 double h[] = {y*vz-z*vy, z*vx-x*vz, x*vy-y*vx};
107 double h2 = h[0]*h[0]+h[1]*h[1]+h[2]*h[2];
108 double hh = sqrt(h2);
110 double fac = sqrt(h[0]*h[0]+h[1]*h[1])/hh;
116 if(fabs(i-M_PI)<10.*TINY) u = -u;
120 O = atan2(h[0],-h[1]);
121 u = atan2(z/sin(i),x*cos(O)+y*sin(O));
123 if(O<0.) O += 2.*M_PI;
124 if(u<0.) u += 2.*M_PI;
125 double r = sqrt(x*x+y*y+z*z);
126 double energy = (vx*vx+vy*vy+vz*vz)*0.5-GM/r;
128 if(fabs(energy*r/GM)<sqrt(TINY))
132 double ww = acos(2.*a/r-1.);
133 if(vx*x+vy*y+vz*z<0.) w = 2.*M_PI-w;
134 double tmpf = tan(0.5*w);
135 M = tmpf*(1.+tmpf*tmpf/3.);
137 if(w<0.) w+= 2.*M_PI;
138 w -= round(w/(2.*M_PI))*2.*M_PI;
148 double face = (a-r)/(a*e);
149 if(face>1.) cape = 0.;
150 else if (face>-1.) cape = acos(face);
153 if(vx*x+vy*y+vz*z<0.) cape = 2.*M_PI-cape;
154 double cw = (cos(cape)-e)/(1.-e*cos(cape));
155 double sw = sqrt(1.-e*e)*sin(cape)/(1.-e*cos(cape));
157 if(ww<0.) ww += 2.*M_PI;
165 M = cape - e*sin(cape);
167 if(w<0.) w += 2.*M_PI;
168 w -= round(w/(2.*M_PI))*2.*M_PI;
178 double tmpf = (a+r)/(a*e);
179 capf = log(tmpf+sqrt(tmpf*tmpf-1.));
180 if(vx*x+vy*y+vz*z<0.) capf = -capf;
181 double cw = (e-cosh(capf))/(e*cosh(capf)-1.);
182 double sw = sqrt(e*e-1.)*sinh(capf)/(e*cosh(capf)-1.);
184 if(ww<0.) ww += 2.*M_PI;
189 double tmpf = 0.5*h2/GM;
190 ww = acos(2.*tmpf/r-1.);
191 if(vx*x+vy*y+vz*z<0.) ww = 2.*M_PI-ww;
193 capf = log(tmpf+sqrt(tmpf*tmpf-1.));
195 M = e*sinh(capf)-capf;
198 w -= round(w/(2.*M_PI))*2.*M_PI;