Debian Codegraph @

src/FDM/UIUCModel/uiuc_3Dinterpolation.cpp

raw
1 /**********************************************************************
2
3 FILENAME: uiuc_3Dinterpolation.cpp
4
5 ----------------------------------------------------------------------
6
7 DESCRIPTION: A 3D interpolator. Does a linear interpolation between
8 two values that were found from using the 2D
9 interpolator (3Dinterpolation()), or uses 3Dinterp_quick()
10 to perform a 3D linear interpolation on "nice" data
11
12 ----------------------------------------------------------------------
13
14 STATUS: alpha version
15
16 ----------------------------------------------------------------------
17
18 REFERENCES:
19
20 ----------------------------------------------------------------------
21
22 HISTORY: 11/07/2001 initial release
23 02/18/2002 (RD) Created uiuc_3Dinterp_quick() to take
24 advantage of the "nice" format of the
25 nonlinear Twin Otter data. Performs a
26 quicker 3D interpolation. Modified
27 uiuc_3Dinterpolation() to handle new input
28 form of the data.
29 ----------------------------------------------------------------------
30
31 AUTHOR(S): Robert Deters <[email protected]>
32
33 ----------------------------------------------------------------------
34
35 VARIABLES:
36
37 ----------------------------------------------------------------------
38
39 INPUTS:
40
41 ----------------------------------------------------------------------
42
43 OUTPUTS: interpI
44
45 ----------------------------------------------------------------------
46
47 CALLED BY: uiuc_coef_drag
48 uiuc_coef_lift
49 uiuc_coef_pitch
50 uiuc_coef_roll
51 uiuc_coef_sideforce
52 uiuc_coef_yaw
53
54 ----------------------------------------------------------------------
55
56 CALLS TO: 2Dinterpolation
57
58 ----------------------------------------------------------------------
59
60 COPYRIGHT: (C) 2001 by Michael Selig
61
62 This program is free software; you can redistribute it and/or
63 modify it under the terms of the GNU General Public License
64 as published by the Free Software Foundation.
65
66 This program is distributed in the hope that it will be useful,
67 but WITHOUT ANY WARRANTY; without even the implied warranty of
68 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69 GNU General Public License for more details.
70
71 You should have received a copy of the GNU General Public License
72 along with this program; if not, write to the Free Software
73 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
74
75 **********************************************************************/
76 #include <simgear/compiler.h> // MSVC: to disable C4244 d to f warning
77
78 #include "uiuc_3Dinterpolation.h"
79
80 void uiuc_1DtoSingle( int temp1Darray[30],
81 int filenumber,
82 int &single_value)
83 {
84 single_value = temp1Darray[filenumber];
85 }
86
87 void uiuc_2Dto1D( double temp2Darray[30][100],
88 int filenumber,
89 double array1D[100])
90 {
91 int count1;
92
93 for (count1=0; count1<=99; count1++)
94 {
95 array1D[count1] = temp2Darray[filenumber][count1];
96 }
97 }
98
99 void uiuc_2Dto1D_int( int temp2Darray[30][100],
100 int filenumber,
101 int array1D[100])
102 {
103 int count1;
104
105 for (count1=0; count1<=99; count1++)
106 {
107 array1D[count1] = temp2Darray[filenumber][count1];
108 }
109 }
110
111 void uiuc_3Dto2D( double temp3Darray[30][100][100],
112 int filenumber,
113 double array2D[100][100])
114 {
115 int count1, count2;
116
117 for (count1=0; count1<=99; count1++)
118 {
119 for (count2=0; count2<=99; count2++)
120 {
121 array2D[count1][count2] = temp3Darray[filenumber][count1][count2];
122 }
123 }
124 }
125
126 double uiuc_3Dinterpolation( double third_Array[30],
127 double full_xArray[30][100][100],
128 double full_yArray[30][100],
129 double full_zArray[30][100][100],
130 int full_nxArray[30][100],
131 int full_ny[30],
132 int third_max,
133 double third_bet,
134 double x_value,
135 double y_value)
136 {
137 double reduced_xArray[100][100], reduced_yArray[100];
138 double reduced_zArray[100][100];
139 int reduced_nxArray[100], reduced_ny;
140
141 double interpmin, interpmax, third_u, third_l;
142 double interpI;
143 int third_min;
144 int k=1;
145 bool third_same=false;
146
147 if (third_bet <= third_Array[1])
148 {
149 third_min = 1;
150 third_same = true;
151 }
152 else if (third_bet >= third_Array[third_max])
153 {
154 third_min = third_max;
155 third_same = true;
156 }
157 else
158 {
159 while (third_Array[k] <= third_bet)
160 {
161 k++;
162 }
163 third_max = k;
164 third_min = k-1;
165 }
166 if (third_same)
167 {
168
169 uiuc_3Dto2D(full_xArray, third_min, reduced_xArray);
170 uiuc_2Dto1D(full_yArray, third_min, reduced_yArray);
171 uiuc_3Dto2D(full_zArray, third_min, reduced_zArray);
172 uiuc_2Dto1D_int(full_nxArray, third_min, reduced_nxArray);
173 uiuc_1DtoSingle(full_ny, third_min, reduced_ny);
174
175 interpI = uiuc_2Dinterpolation(reduced_xArray,
176 reduced_yArray,
177 reduced_zArray,
178 reduced_nxArray,
179 reduced_ny,
180 x_value,
181 y_value);
182 }
183 else
184 {
185 uiuc_3Dto2D(full_xArray, third_min, reduced_xArray);
186 uiuc_2Dto1D(full_yArray, third_min, reduced_yArray);
187 uiuc_3Dto2D(full_zArray, third_min, reduced_zArray);
188 uiuc_2Dto1D_int(full_nxArray, third_min, reduced_nxArray);
189 uiuc_1DtoSingle(full_ny, third_min, reduced_ny);
190
191 interpmin = uiuc_2Dinterpolation(reduced_xArray,
192 reduced_yArray,
193 reduced_zArray,
194 reduced_nxArray,
195 reduced_ny,
196 x_value,
197 y_value);
198
199 uiuc_3Dto2D(full_xArray, third_max, reduced_xArray);
200 uiuc_2Dto1D(full_yArray, third_max, reduced_yArray);
201 uiuc_3Dto2D(full_zArray, third_max, reduced_zArray);
202 uiuc_2Dto1D_int(full_nxArray, third_max, reduced_nxArray);
203 uiuc_1DtoSingle(full_ny, third_max, reduced_ny);
204
205 interpmax = uiuc_2Dinterpolation(reduced_xArray,
206 reduced_yArray,
207 reduced_zArray,
208 reduced_nxArray,
209 reduced_ny,
210 x_value,
211 y_value);
212
213 third_u = third_Array[third_max];
214 third_l = third_Array[third_min];
215
216 interpI=interpmax - (third_u-third_bet)*(interpmax-interpmin)/(third_u-third_l);
217 }
218
219 return interpI;
220
221 }
222
223
224 double uiuc_3Dinterp_quick( double z[30],
225 double x[100],
226 double y[100],
227 double fxyz[30][100][100],
228 int xmax,
229 int ymax,
230 int zmax,
231 double zp,
232 double xp,
233 double yp)
234 {
235
236 int xnuml, xnumu, ynuml, ynumu, znuml, znumu;
237 double xl, xu, yl, yu, zl, zu;
238 double ptxl, ptxu, ptyl, ptyu, ptylxl, ptylxu, ptyuxl, ptyuxu;
239 double ptzl, ptzu, ptzlxl, ptzlxu, ptzuxl, ptzuxu;
240 double ptzlyl, ptzlyu, ptzuyl, ptzuyu;
241 double ptzlylxl, ptzlylxu, ptzlyuxl, ptzlyuxu;
242 double ptzuylxl, ptzuylxu, ptzuyuxl, ptzuyuxu, data_point;
243
244 int i=1;
245 int j=1;
246 int k=1;
247
248 bool xsame=false;
249 bool ysame=false;
250 bool zsame=false;
251
252
253 // Find the z's
254 znumu=0;
255 zl=0.0;
256 zu=0.0;
257 if (zp <= z[1])
258 {
259 znuml=1;
260 zsame=true;
261 }
262 else if (zp >= z[zmax])
263 {
264 znuml=zmax;
265 zsame=true;
266 }
267 else
268 {
269 while (z[k] <= zp)
270 k++;
271 zu=z[k];
272 zl=z[k-1];
273 znumu=k;
274 znuml=k-1;
275 }
276
277 // Find the y's
278 ynumu=0;
279 yl=0.0;
280 yu=0.0;
281 if (yp <= y[1])
282 {
283 ynuml=1;
284 ysame=true;
285 }
286 else if (yp >= y[ymax])
287 {
288 ynuml=ymax;
289 ysame=true;
290 }
291 else
292 {
293 while (y[j] <= yp)
294 j++;
295 yu=y[j];
296 yl=y[j-1];
297 ynumu=j;
298 ynuml=j-1;
299 }
300
301
302 // Find the x's
303 xnumu=0;
304 xl=0.0;
305 xu=0.0;
306 if (xp <= x[1])
307 {
308 xnuml=1;
309 xsame=true;
310 }
311 else if (xp >= x[xmax])
312 {
313 xnuml=xmax;
314 xsame=true;
315 }
316 else
317 {
318 while (x[i] <= xp)
319 i++;
320 xu=x[i];
321 xl=x[i-1];
322 xnumu=i;
323 xnuml=i-1;
324 }
325
326 if (zsame)
327 {
328 if (ysame && xsame)
329 {
330 data_point = fxyz[znuml][ynuml][xnuml];
331 }
332 else if (ysame)
333 {
334 ptxl = fxyz[znuml][ynuml][xnuml];
335 ptxu = fxyz[znuml][ynuml][xnumu];
336 data_point = ptxu - (xu-xp)*(ptxu-ptxl)/(xu-xl);
337 }
338 else if (xsame)
339 {
340 ptyl = fxyz[znuml][ynuml][xnuml];
341 ptyu = fxyz[znuml][ynumu][xnuml];
342 data_point = ptyu - (yu-yp)*(ptyu-ptyl)/(yu-yl);
343 }
344 else
345 {
346 ptylxl = fxyz[znuml][ynuml][xnuml];
347 ptylxu = fxyz[znuml][ynuml][xnumu];
348 ptyuxl = fxyz[znuml][ynumu][xnuml];
349 ptyuxu = fxyz[znuml][ynumu][xnumu];
350 ptyl = ptylxu - (xu-xp)*(ptylxu-ptylxl)/(xu-xl);
351 ptyu = ptyuxu - (xu-xp)*(ptyuxu-ptyuxl)/(xu-xl);
352 data_point = ptyu - (yu-yp)*(ptyu-ptyl)/(yu-yl);
353 }
354 }
355 else
356 {
357 if (ysame && xsame)
358 {
359 ptzl = fxyz[znuml][ynuml][xnuml];
360 ptzu = fxyz[znumu][ynuml][xnuml];
361 data_point = ptzu - (zu-zp)*(ptzu-ptzl)/(zu-zl);
362 }
363 else if (ysame)
364 {
365 ptzlxl = fxyz[znuml][ynuml][xnuml];
366 ptzlxu = fxyz[znuml][ynuml][xnumu];
367 ptzuxl = fxyz[znumu][ynuml][xnuml];
368 ptzuxu = fxyz[znumu][ynuml][xnumu];
369 ptzl = ptzlxu - (xu-xp)*(ptzlxu-ptzlxl)/(xu-xl);
370 ptzu = ptzuxu - (xu-xp)*(ptzuxu-ptzuxl)/(xu-xl);
371 data_point = ptzu - (zu-zp)*(ptzu-ptzl)/(zu-zl);
372 }
373 else if (xsame)
374 {
375 ptzlyl = fxyz[znuml][ynuml][xnuml];
376 ptzlyu = fxyz[znuml][ynumu][xnuml];
377 ptzuyl = fxyz[znumu][ynuml][xnuml];
378 ptzuyu = fxyz[znumu][ynumu][xnuml];
379 ptzl = ptzlyu - (yu-yp)*(ptzlyu-ptzlyl)/(yu-yl);
380 ptzu = ptzuyu - (yu-yp)*(ptzuyu-ptzuyl)/(yu-yl);
381 data_point = ptzu - (zu-zp)*(ptzu-ptzl)/(zu-zl);
382 }
383 else
384 {
385 ptzlylxl = fxyz[znuml][ynuml][xnuml];
386 ptzlylxu = fxyz[znuml][ynuml][xnumu];
387 ptzlyuxl = fxyz[znuml][ynumu][xnuml];
388 ptzlyuxu = fxyz[znuml][ynumu][xnumu];
389 ptzuylxl = fxyz[znumu][ynuml][xnuml];
390 ptzuylxu = fxyz[znumu][ynuml][xnumu];
391 ptzuyuxl = fxyz[znumu][ynumu][xnuml];
392 ptzuyuxu = fxyz[znumu][ynumu][xnumu];
393 ptzlyl = ptzlylxu - (xu-xp)*(ptzlylxu-ptzlylxl)/(xu-xl);
394 ptzlyu = ptzlyuxu - (xu-xp)*(ptzlyuxu-ptzlyuxl)/(xu-xl);
395 ptzuyl = ptzuylxu - (xu-xp)*(ptzuylxu-ptzuylxl)/(xu-xl);
396 ptzuyu = ptzuyuxu - (xu-xp)*(ptzuyuxu-ptzuyuxl)/(xu-xl);
397 ptzl = ptzlyu - (yu-yp)*(ptzlyu-ptzlyl)/(yu-yl);
398 ptzu = ptzuyu - (yu-yp)*(ptzuyu-ptzuyl)/(yu-yl);
399 data_point = ptzu - (zu-zp)*(ptzu-ptzl)/(zu-zl);
400 }
401 }
402
403
404 return data_point;
405 }