Templatized a function and removed its duplicate, plus minor optimization.
[PaGMO.git] / AstroToolbox / misc4Tandem.cpp
blobd9012fff8925be0db9aabf2bf896944bf9b79ece
1 // ------------------------------------------------------------------------ //
2 // This source file is part of the 'ESA Advanced Concepts Team's //
3 // Space Mechanics Toolbox' software. //
4 // //
5 // The source files are for research use only, //
6 // and are distributed WITHOUT ANY WARRANTY. Use them on your own risk. //
7 // //
8 // Copyright (c) 2004-2007 European Space Agency //
9 // ------------------------------------------------------------------------ //
12 #include "misc4Tandem.h"
13 #include "math.h"
14 #include <vector>
16 int xant(const double(&X)[5], const double &x) {
17 int i;
18 for(i=0; i<4; i++) {
19 if (X[i]>x) break;
21 return i-1;
24 int yant(const double(&Y)[15], const double &y) {
25 int i;
26 for(i=0; i<14; i++) {
27 if (Y[i]>y) break;
29 return i-1;
32 int xantA5(const double(&X)[9] , const double &x) {
33 int i;
34 for(i=0; i<8; i++) {
35 if (X[i]>x) break;
37 return i-1;
40 int yantA5(const double(&Y)[13] , const double &y) {
41 int i;
42 for(i=0; i<12; i++) {
43 if (Y[i]>y) break;
45 return i-1;
50 double interp2SF(const double (&X)[5], const double(&Y)[15] , const double &VINF, const double &declination) {
52 static const double SF[15][5] = {
53 {0.00000,0.00000,0.00000,0.00000,0.00000},
54 {100.00000,100.00000,100.00000,100.00000,100.00000},
55 {1830.50000,1815.90000,1737.70000,1588.00000,1344.30000},
56 {1910.80000,1901.90000,1819.00000,1636.40000,1369.30000},
57 {2001.80000,1995.30000,1891.30000,1673.90000,1391.90000},
58 {2108.80000,2088.60000,1947.90000,1708.00000,1409.50000},
59 {2204.00000,2167.30000,1995.50000,1734.50000,1419.60000},
60 {2270.80000,2205.80000,2013.60000,1745.10000,1435.20000},
61 {2204.70000,2133.60000,1965.40000,1712.80000,1413.60000},
62 {2087.90000,2060.60000,1917.70000,1681.10000,1392.50000},
63 {1979.17000,1975.40000,1866.50000,1649.00000,1371.70000},
64 {1886.90000,1882.20000,1801.00000,1614.60000,1350.50000},
65 {1805.90000,1796.00000,1722.70000,1571.60000,1327.60000},
66 {100.00000,100.00000,100.00000,100.00000,100.00000},
67 {0.00000,0.00000,0.00000,0.00000,0.00000}
70 int tempx=xant(X,VINF);
71 int tempy=yant(Y,declination);
73 if (fabs(declination)>=90) return 0;
74 if ((VINF<1)||(VINF>5)) return 0;
75 if (X[tempx]==VINF) return SF[tempy][tempx] /(Y[tempy+1]-Y[tempy])*(Y[tempy+1]-declination)
76 + SF[tempy+1][tempx] /(Y[tempy+1]-Y[tempy])*(declination-Y[tempy]) *(X[tempx+1]-VINF);
77 else return SF[tempy][tempx] /(Y[tempy+1]-Y[tempy])*(Y[tempy+1]-declination) *(X[tempx+1]-VINF)
78 + SF[tempy+1][tempx] /(Y[tempy+1]-Y[tempy])*(declination-Y[tempy]) *(X[tempx+1]-VINF)
79 + SF[tempy][tempx+1] /(Y[tempy+1]-Y[tempy])*(Y[tempy+1]-declination) *(VINF-X[tempx])
80 + SF[tempy+1][tempx+1]/(Y[tempy+1]-Y[tempy])*(declination-Y[tempy]) *(VINF-X[tempx])
85 double interp2A5(const double (&X)[9], const double(&Y)[13], const double &VINF, const double &declination) {
87 static const double SF[13][9] = {
88 {0,0,0,0,0,0,0,0,0},
89 {0,0,0,0,0,0,0,0,0},
90 {1160,1100,1010,930,830,740,630,590,550},
91 {2335.0 ,2195.0,2035.0,1865.0,1675.0,1480.0,1275.0,1175.0,1075.0},
92 {2335.0 ,2195.0,2035.0,1865.0,1675.0,1480.0,1275.0,1175.0,1075.0},
93 {2335.0 ,2195.0,2035.0,1865.0,1675.0,1480.0,1275.0,1175.0,1075.0},
94 {2335.0 ,2195.0,2035.0,1865.0,1675.0,1480.0,1275.0,1175.0,1075.0},
95 {2335.0 ,2195.0,2035.0,1865.0,1675.0,1480.0,1275.0,1175.0,1075.0},
96 {2335.0 ,2195.0,2035.0,1865.0,1675.0,1480.0,1275.0,1175.0,1075.0},
97 {2335.0 ,2195.0,2035.0,1865.0,1675.0,1480.0,1275.0,1175.0,1075.0},
98 {1160,1100,1010,930,830,740,630,590,550},
99 {0,0,0,0,0,0,0,0,0},
100 {0,0,0,0,0,0,0,0,0}
103 int tempx=xantA5(X,VINF);
104 int tempy=yantA5(Y,declination);
106 if (fabs(declination)>=30) return 0;
107 if ((VINF<2.51)||(VINF>5.98)) return 0;
108 if (X[tempx]==VINF) return SF[tempy][tempx] /0.5/(Y[tempy+1]-Y[tempy])*(Y[tempy+1]-declination)
109 + SF[tempy+1][tempx] /0.5/(Y[tempy+1]-Y[tempy])*(declination-Y[tempy]) *(X[tempx+1]-VINF);
110 else return SF[tempy][tempx] /0.5/(Y[tempy+1]-Y[tempy])*(Y[tempy+1]-declination) *(X[tempx+1]-VINF)
111 + SF[tempy+1][tempx] /0.5/(Y[tempy+1]-Y[tempy])*(declination-Y[tempy]) *(X[tempx+1]-VINF)
112 + SF[tempy][tempx+1] /0.5/(Y[tempy+1]-Y[tempy])*(Y[tempy+1]-declination) *(VINF-X[tempx])
113 + SF[tempy+1][tempx+1]/0.5/(Y[tempy+1]-Y[tempy])*(declination-Y[tempy]) *(VINF-X[tempx])
118 double SoyuzFregat (const double &VINF, const double &declination) {
119 //This function returns the mass that a Soyuz-Fregat launcher can inject
120 //into a given escape velocity and asymptote declination. The data here
121 //refer to ESOC WP-521 and consider an elaborated five impulse strategy to
122 //exploit the launcher performances as much as possible.
125 static const double X[5] = {1,2,3,4,5};
126 static const double Y[15] = {-90, -65, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 65, 90};
127 return interp2SF(X,Y,VINF,declination);
131 double Atlas501 (const double &VINF, const double &declination) {
132 //This function returns the mass that a Soyuz-Fregat launcher can inject
133 //into a given escape velocity and asymptote declination. The data here
134 //refer to ESOC WP-521 and consider an elaborated five impulse strategy to
135 //exploit the launcher performances as much as possible.
137 static const double X[9] = {2.5,3,3.5,4,4.5,5,5.5,5.75,6};
138 static const double Y[13] = {-40, -30,-29,-28.5, -20, -10, 0, 10, 20,28.5,29,30, 40};
139 return interp2A5(X,Y,VINF,declination);
141 void ecl2equ (double (&ecl)[3],double (&equ)[3]){
142 static const double incl=0.409072975;
143 double temp[3];
144 temp[0]=ecl[0];
145 temp[1]=ecl[1];
146 temp[2]=ecl[2];
147 equ[0]=temp[0];
148 equ[1]=temp[1]*cos(incl)-temp[2]*sin(incl);
149 equ[2]=temp[1]*sin(incl)+temp[2]*cos(incl);