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 // ------------------------------------------------------------------------ //
13 % r0: column vector for the position (mu=1)
14 % v0: column vector for the velocity (mu=1)
15 % rtarget: distance to be reached
18 % t: time taken to reach a given distance
20 %Comments: everything works in non dimensional units
23 #include "time2distance.h"
26 double time2distance(const double *r0
, const double *v0
, double rtarget
)
30 double r0norm
= norm2(r0
);
31 double a
, e
, E0
, p
, ni
, Et
;
44 // If the solution is an ellipse
47 double ra
= a
* (1+e
);
50 else // we find the anomaly where the target distance is reached
52 ni
= acos((p
/rtarget
-1)/e
); //in 0-pi
53 Et
= 2*atan(sqrt((1-e
)/(1+e
))*tan(ni
/2)); // algebraic kepler's equation
56 return sqrt(pow(a
,3))*(Et
-e
*sin(Et
)-E0
+ e
*sin(E0
));
60 return sqrt(pow(a
,3))*(Et
-e
*sin(Et
)+E0
- e
*sin(E0
));
64 else // the solution is a hyperbolae
66 ni
= acos((p
/rtarget
-1)/e
); // in 0-pi
67 Et
= 2*atan(sqrt((e
-1)/(e
+1))*tan(ni
/2)); // algebraic equivalent of kepler's equation in terms of the Gudermannian
70 return sqrt(pow((-a
),3))*(e
*tan(Et
)-log(tan(Et
/2+M_PI
/4))-e
*tan(E0
)+log(tan(E0
/2+M_PI
/4)));
74 return sqrt(pow((-a
),3))*(e
*tan(Et
)-log(tan(Et
/2+M_PI
/4))+e
*tan(E0
)-log(tan(E0
/2+M_PI
/4)));