1 // ------------------------------------------------------------------------ //
2 // This source file is part of the 'ESA Advanced Concepts Team's //
3 // Space Mechanics Toolbox' software. //
5 // The source files are for research use only, //
6 // and are distributed WITHOUT ANY WARRANTY. Use them on your own risk. //
8 // Copyright (c) 2004-2007 European Space Agency //
9 // ------------------------------------------------------------------------ //
14 #include "Astro_Functions.h"
15 #include "ZeroFinder.h"
19 class CZF
: public ZeroFinder::Function1D
22 double operator()(const double &x
) const
24 return (p1
*tan(x
) - log(tan(0.5*x
+ M_PI_4
)) - p2
);
28 double Mean2Eccentric (const double &M
, const double &e
)
31 static const double tolerance
= 1e-13;
32 int n_of_it
= 0; // Number of iterations
33 double Eccentric
,Ecc_New
;
39 Eccentric
= M
+ e
* cos(M
); // Initial guess
40 while ( (err
> tolerance
) && (n_of_it
< 100))
42 Ecc_New
= Eccentric
- (Eccentric
- e
* sin(Eccentric
) -M
)/(1.0 - e
* cos(Eccentric
));
43 err
= fabs(Eccentric
- Ecc_New
);
48 CZF FF
; // function to find its zero point
49 ZeroFinder::FZero
fz(-M_PI_2
+ 1e-8, M_PI_2
- 1e-8);
50 FF
.SetParameters(e
, M
);
51 Ecc_New
= fz
.FindZero(FF
);
59 void Conversion (const double *E
,
64 double a
,e
,i
,omg
,omp
,theta
;
66 double X_per
[3],X_dotper
[3];
76 b
= a
* sqrt (1 - e
*e
);
77 n
= sqrt (mu
/pow(a
,3));
79 const double sin_theta
= sin(theta
);
80 const double cos_theta
= cos(theta
);
82 X_per
[0] = a
* (cos_theta
- e
);
83 X_per
[1] = b
* sin_theta
;
85 X_dotper
[0] = -(a
* n
* sin_theta
)/(1 - e
* cos_theta
);
86 X_dotper
[1] = (b
* n
* cos_theta
)/(1 - e
* cos_theta
);
88 const double cosomg
= cos(omg
);
89 const double cosomp
= cos(omp
);
90 const double sinomg
= sin(omg
);
91 const double sinomp
= sin(omp
);
92 const double cosi
= cos(i
);
93 const double sini
= sin(i
);
95 R
[0][0] = cosomg
*cosomp
-sinomg
*sinomp
*cosi
;
96 R
[0][1] = -cosomg
*sinomp
-sinomg
*cosomp
*cosi
;
98 R
[1][0] = sinomg
*cosomp
+cosomg
*sinomp
*cosi
;
99 R
[1][1] = -sinomg
*sinomp
+cosomg
*cosomp
*cosi
;
101 R
[2][0] = sinomp
*sini
;
102 R
[2][1] = cosomp
*sini
;
104 // evaluate position and velocity
105 for (int i
= 0;i
< 3;i
++)
109 for (int j
= 0;j
< 2;j
++)
111 pos
[i
] += R
[i
][j
] * X_per
[j
];
112 vel
[i
] += R
[i
][j
] * X_dotper
[j
];
119 double norm(const double *vet1
, const double *vet2
)
122 for (int i
= 0; i
< 3; i
++)
124 Vin
+= (vet1
[i
] - vet2
[i
])*(vet1
[i
] - vet2
[i
]);
130 double norm2(const double *vet1
)
133 for (int i
= 0; i
< 3; i
++) {
134 temp
+= vet1
[i
] * vet1
[i
];
140 //subfunction that evaluates vector product
141 void vett(const double *vet1
, const double *vet2
, double *prod
)
143 prod
[0]=(vet1
[1]*vet2
[2]-vet1
[2]*vet2
[1]);
144 prod
[1]=(vet1
[2]*vet2
[0]-vet1
[0]*vet2
[2]);
145 prod
[2]=(vet1
[0]*vet2
[1]-vet1
[1]*vet2
[0]);
148 double x2tof(const double &x
,const double &s
,const double &c
,const int &lw
)
150 double am
,a
,alfa
,beta
;
156 beta
= 2 * asin (sqrt((s
- c
)/(2*a
)));
157 if (lw
) beta
= -beta
;
163 beta
= 2 * asinh(sqrt ((s
- c
)/(-2 * a
)));
164 if (lw
) beta
= -beta
;
169 return (a
* sqrt (a
)* ( (alfa
- sin(alfa
)) - (beta
- sin(beta
)) ));
173 return (-a
* sqrt(-a
)*( (sinh(alfa
) - alfa
) - ( sinh(beta
) - beta
)) );
179 // Subfunction that evaluates the time of flight as a function of x
180 double tofabn(const double &sigma
,const double &alfa
,const double &beta
)
184 return (sigma
* sqrt (sigma
)* ( (alfa
- sin(alfa
)) - (beta
- sin(beta
)) ));
188 return (-sigma
* sqrt(-sigma
)*( (sinh(alfa
) - alfa
) - ( sinh(beta
) - beta
)) );
192 // subfunction that evaluates unit vectors
193 void vers(const double *V_in
, double *Ver_out
)
198 for (i
= 0;i
< 3;i
++)
200 v_mod
+= V_in
[i
]*V_in
[i
];
203 double sqrtv_mod
= sqrt(v_mod
);
205 for (i
= 0;i
< 3;i
++)
207 Ver_out
[i
] = V_in
[i
]/sqrtv_mod
;