Debian Codegraph @

07p/plaut04/src/r3b/createLibPoint.c++

raw
1 #include <algorithm>
2 #include <math.h>
3 #include <Inventor/So.h>
4 #include <Inventor/nodes/SoTexture2.h>
5 #include "r3bplaut04.h"
6
7 #define CR3BP 0
8 #define INERTIAL_B 1
9 #define INERTIAL_S 2
10 #define INERTIAL_E 3
11
12 static void
13 lagpoint (double mu, double LP [7][2], double eps)
14 {
15 /**************************************************************************************
16 * Eusebius Doedel & Volodymyr Romanov July 3, 2003 *
17 ***************************************************************************************
18 * Calculation of Lagrange points L1, L2, L3, L4, L5 for two-body system with the *
19 * mass ratio mu=m2/(m1+m2). *
20 * *
21 * Input parameters: *
22 * mu - mass ratio; *
23 * eps - precision. *
24 * *
25 * Output parameters: *
26 * LP [5],[2] - array, containing coordinates of *
27 * Lagrange points as: *
28 * LP[0][0] - x coordinate of the bigger planet (-mu) *
29 * LP[0][1] - y coordinate of the bigger planet (0) *
30 * LP[1][0] - x coordinate of the smaller planet (1-mu) *
31 * LP[1][1] - y coordinate of the smaller planet (0) *
32 * LP[2][0] - x coordinate of L1 *
33 * LP[2][1] - y coordinate of L1 (0) *
34 * LP[3][0] - x coordinate of L2 *
35 * LP[3][1] - y coordinate of L3 (0) *
36 * .......... *
37 * LP[6][0] - x coordinate of L5 *
38 * LP[6][1] - y coordinate of L5 (!=0) *
39 ***************************************************************************************
40 */
41 double x0, x1, y0;
42 double r1, r2;
43 double f, d;
44 double eps1;
45
46 if (mu < 0)
47 {
48 printf ("Function lagpoint error: Your mass ratio mu could not be negative\n");
49 return;
50 }
51
52 if (mu > 0.5)
53 {
54 printf ("Function lagpoint error: Your mass ratio mu must be less or equal than 0.5\n");
55 return;
56 }
57
58 eps1 = mu;
59 if ((eps > eps1) && (mu > 0))
60 {
61 printf ("Function lagpoint message: Your accuracy is insufficient\n");
62 printf ("Automatic correction of the accuracy was made: eps =%E\n", eps1);
63 eps = eps1;
64 }
65 /*Calculation of coordinates of the planet --------------------------------*/
66 x0 = -mu;
67 y0 = 0;
68 LP[0][0] = x0;
69 LP[0][1] = y0;
70 x0 = 1 - mu;
71 y0 = 0;
72 LP[1][0] = x0;
73 LP[1][1] = y0;
74
75 /*L4 and L5 calculation ---------------------------------------------------*/
76 x0 = 0.5 - mu;
77 y0 = sqrt(3.0)/2.0;
78 LP[5][0] = x0;
79 LP[5][1] = y0;
80 LP[6][0] = x0;
81 LP[6][1] = - y0;
82
83 /*L3 calculation ----------------------------------------------------------*/
84 x0 = - 1-mu;
85 y0 = 0;
86 do
87 {
88 x1 = x0;
89 r1 = (x0 + mu);
90 r2 = (x0 - 1 + mu);
91 f = (x0*r1*r1 + (1 - mu))*r2*r2 + mu*r1*r1;
92 d = (r1 + 2*x0)*r1*r2*r2 + 2*x0*r1*r1*r2 + 2*(1 - mu)*r2 + 2*mu*r1;
93 x0 = x0 - f/d;
94 }
95 while (fabs(x0-x1) > eps);
96 LP[4][0] = x0;
97 LP[4][1] = y0;
98
99 /*L2 calculation ----------------------------------------------------------*/
100 if (mu >= eps)
101 {
102 x0 = 1 + mu;
103 y0 = 0;
104 do
105 {
106 x1 = x0;
107 r1 = (x0 + mu);
108 r2 = (x0 - 1 + mu);
109 f = (x0*r1*r1 - (1 - mu))*r2*r2 - mu*r1*r1;
110 d = (r1 + 2*x0)*r1*r2*r2 + 2*x0*r1*r1*r2 - 2*(1 - mu)*r2 - 2*mu*r1;
111 x0 = x0 - f/d;
112 }
113 while (fabs(x0-x1) > eps);
114 }
115 else
116 {
117 x0 = 1;
118 y0 = 0;
119 }
120 LP[3][0] = x0;
121 LP[3][1] = y0;
122
123 /*L1 calculation -----------------------------------------------------------*/
124 if (mu >= eps)
125 {
126 x0 = 1 - mu;
127 y0 = 0;
128 do
129 {
130 x1 = x0;
131 r1 = (x0 + mu);
132 r2 = (x0 - 1 + mu);
133 f = (x0*r1*r1 - (1 - mu))*r2*r2 + mu*r1*r1;
134 d = (r1 + 2*x0)*r1*r2*r2 + 2*x0*r1*r1*r2 - 2*(1 - mu)*r2 + 2*mu*r1;
135 x0 = x0 - f/d;
136 }
137 while (fabs(x0-x1) > eps);
138 }
139 else
140 {
141 x0 = 1;
142 y0 = 0;
143 }
144 LP[2][0] = x0;
145 LP[2][1] = y0;
146 return;
147 }
148
149
150 ///////////////////////////////////////////////////////////////////////////
151 //
152 // By Chenghai Zhang
153 //
154 SoSeparator *
155 createLibrationPoint(float mu, float dis, float scale, int whichCoordSystem)
156 //
157 ///////////////////////////////////////////////////////////////////////////
158 {
159
160 // create a root
161 SoSeparator *libSep = new SoSeparator;
162
163 // create the lib object
164 SoGroup * libGrp = new SoGroup;
165
166 static bool blOpenStar = FALSE;
167 static bool blUseStar = FALSE;
168 static bool blLibBlink = FALSE;
169
170 // Read object data from a file
171 if(blUseStar)
172 {
173 SoInput mySceneInput;
174 if (mySceneInput.openFile("widgets/star.iv"))
175 {
176 SoSeparator *starObject = SoDB::readAll(&mySceneInput);
177 if (starObject == NULL)
178 {
179 blOpenStar=FALSE;
180 }
181 else
182 {
183 mySceneInput.closeFile();
184 libGrp->addChild(starObject);
185 }
186 }
187 else
188 {
189 blOpenStar = FALSE;
190 }
191 }
192
193 if(!blUseStar || !blOpenStar )
194 {
195 SoCube *lib = new SoCube;
196 lib->height= 1.0;
197 lib->width = 1.0;
198 lib->depth = 1.0;
199 libGrp->addChild(lib);
200 }
201
202 //define silver materil for the lib
203 SoMaterial *libMtl = new SoMaterial;
204 libMtl->ambientColor.setValue(1.0,1.0,1.0);
205 libMtl->diffuseColor.setValue(1.0,1.0,1.0);
206 libMtl->specularColor.setValue(0.5,0.5,0.5);
207 libMtl->shininess = 0.9;
208 libMtl->transparency = 0.0;
209 libSep->addChild(libMtl);
210
211 double lp[7][2] = {}, eps;
212 eps = 1.e-5;
213 lagpoint (mu, lp, eps);
214
215 float libPtMax[3], libPtMin[3];
216 libPtMax[0]=libPtMax[1]=libPtMax[2]=libPtMin[0]=libPtMin[1]=libPtMin[2]=0;
217
218 // decide the size of the libpoints
219 float x[5],y[5],z[5];
220 for(int libPtId=1; libPtId<6; libPtId++)
221 {
222 x[libPtId-1] = lp[libPtId+1][0];
223 y[libPtId-1] = lp[libPtId+1][1];
224 z[libPtId-1] = 0;
225
226 // define the lib transform
227 float xOffset = 0;
228 if(whichCoordSystem == INERTIAL_B)
229 xOffset = 0;
230 else if(whichCoordSystem == INERTIAL_S)
231 xOffset = mu;
232 else if(whichCoordSystem == INERTIAL_E)
233 xOffset = mu-1;
234
235 x[libPtId-1] += xOffset;
236
237 libPtMax[0] = (libPtMax[0]>x[libPtId-1]) ? libPtMax[0] : x[libPtId-1];
238 libPtMax[1] = (libPtMax[1]>y[libPtId-1]) ? libPtMax[1] : y[libPtId-1];
239 libPtMax[2] = (libPtMax[2]>z[libPtId-1]) ? libPtMax[2] : z[libPtId-1];
240 libPtMin[0] = (libPtMin[0]<x[libPtId-1]) ? libPtMin[0] : x[libPtId-1];
241 libPtMin[1] = (libPtMin[1]<y[libPtId-1]) ? libPtMin[1] : y[libPtId-1];
242 libPtMin[2] = (libPtMin[2]<z[libPtId-1]) ? libPtMin[2] : z[libPtId-1];
243 }
244
245 dis = std::max(std::max(dis,libPtMax[0]-libPtMin[0]),
246 std::max(libPtMax[1]-libPtMin[1],libPtMax[2]-libPtMin[2]));
247
248 // draw the lib points.
249 float sf = scale*dis/100.0;
250 for(int libPtId=1; libPtId<6; libPtId++)
251 {
252 SoSeparator *aLibPt = new SoSeparator;
253 SoTransform *libXform = new SoTransform;
254
255 libXform->translation.setValue(x[libPtId-1], y[libPtId-1], z[libPtId-1]);
256 libXform->scaleFactor.setValue(sf, sf, sf);
257 libXform->rotation.setValue(SbVec3f(1.0, 0.0, 0.0), M_PI_2);
258 aLibPt->addChild(libXform);
259
260 if(blLibBlink)
261 {
262 SoBlinker *libBlk = new SoBlinker;
263 libBlk->addChild(libGrp);
264 libBlk->speed = 0.10;
265 aLibPt->addChild(libBlk);
266 }
267 else
268 {
269 aLibPt->addChild(libGrp);
270 }
271
272 libSep->addChild(aLibPt);
273 }
274 return libSep;
275 }