26 #include <boost/math/special_functions/acosh.hpp>
27 #include <boost/math/special_functions/asinh.hpp>
29 #include "Astro_Functions.h"
30 #include "ZeroFinder.h"
34 class CZF :
public ZeroFinder::Function1D
37 CZF(
const double &a,
const double &b):Function1D(a,b) {}
38 double operator()(
const double &x)
const
40 return (p1*tan(x) - log(tan(0.5*x + M_PI_4)) - p2);
44 double Mean2Eccentric (
const double &M,
const double &e)
47 static const double tolerance = 1e-13;
49 double Eccentric,Ecc_New;
55 Eccentric = M + e* cos(M);
56 while ( (err > tolerance) && (n_of_it < 100))
58 Ecc_New = Eccentric - (Eccentric - e* sin(Eccentric) -M )/(1.0 - e * cos(Eccentric));
59 err = fabs(Eccentric - Ecc_New);
65 ZeroFinder::FZero fz(-M_PI_2 + 1e-8, M_PI_2 - 1e-8);
66 Ecc_New = fz.FindZero(FF);
74 void Conversion (
const double *E,
79 double a,e,i,omg,omp,theta;
81 double X_per[3],X_dotper[3];
91 b = a * sqrt (1 - e*e);
92 n = sqrt (mu/pow(a,3));
94 const double sin_theta = sin(theta);
95 const double cos_theta = cos(theta);
97 X_per[0] = a * (cos_theta - e);
98 X_per[1] = b * sin_theta;
100 X_dotper[0] = -(a * n * sin_theta)/(1 - e * cos_theta);
101 X_dotper[1] = (b * n * cos_theta)/(1 - e * cos_theta);
103 const double cosomg = cos(omg);
104 const double cosomp = cos(omp);
105 const double sinomg = sin(omg);
106 const double sinomp = sin(omp);
107 const double cosi = cos(i);
108 const double sini = sin(i);
110 R[0][0] = cosomg*cosomp-sinomg*sinomp*cosi;
111 R[0][1] = -cosomg*sinomp-sinomg*cosomp*cosi;
113 R[1][0] = sinomg*cosomp+cosomg*sinomp*cosi;
114 R[1][1] = -sinomg*sinomp+cosomg*cosomp*cosi;
116 R[2][0] = sinomp*sini;
117 R[2][1] = cosomp*sini;
120 for (
int i = 0;i < 3;i++)
124 for (
int j = 0;j < 2;j++)
126 pos[i] += R[i][j] * X_per[j];
127 vel[i] += R[i][j] * X_dotper[j];
134 double norm(
const double *vet1,
const double *vet2)
137 for (
int i = 0; i < 3; i++)
139 Vin += (vet1[i] - vet2[i])*(vet1[i] - vet2[i]);
145 double norm2(
const double *vet1)
148 for (
int i = 0; i < 3; i++) {
149 temp += vet1[i] * vet1[i];
156 void vett(
const double *vet1,
const double *vet2,
double *prod )
158 prod[0]=(vet1[1]*vet2[2]-vet1[2]*vet2[1]);
159 prod[1]=(vet1[2]*vet2[0]-vet1[0]*vet2[2]);
160 prod[2]=(vet1[0]*vet2[1]-vet1[1]*vet2[0]);
163 double x2tof(
const double &x,
const double &s,
const double &c,
const int &lw)
165 double am,a,alfa,beta;
171 beta = 2 * asin (sqrt((s - c)/(2*a)));
172 if (lw) beta = -beta;
177 alfa = 2 * boost::math::acosh(x);
178 beta = 2 * boost::math::asinh(sqrt ((s - c)/(-2 * a)));
179 if (lw) beta = -beta;
184 return (a * sqrt (a)* ( (alfa - sin(alfa)) - (beta - sin(beta)) ));
188 return (-a * sqrt(-a)*( (sinh(alfa) - alfa) - ( sinh(beta) - beta)) );
195 double tofabn(
const double &sigma,
const double &alfa,
const double &beta)
199 return (sigma * sqrt (sigma)* ( (alfa - sin(alfa)) - (beta - sin(beta)) ));
203 return (-sigma * sqrt(-sigma)*( (sinh(alfa) - alfa) - ( sinh(beta) - beta)) );
208 void vers(
const double *V_in,
double *Ver_out)
213 for (i = 0;i < 3;i++)
215 v_mod += V_in[i]*V_in[i];
218 double sqrtv_mod = sqrt(v_mod);
220 for (i = 0;i < 3;i++)
222 Ver_out[i] = V_in[i]/sqrtv_mod;