]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGState.cpp
Sync with current JSBSim devel code.
[flightgear.git] / src / FDM / JSBSim / FGState.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2                                                                        
3  Module:       FGState.cpp
4  Author:       Jon Berndt
5  Date started: 11/17/98
6  Called by:    FGFDMExec and accessed by all models.
7  
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
9  
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14  
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19  
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23  
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26  
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29 See header file.
30  
31 HISTORY
32 --------------------------------------------------------------------------------
33 11/17/98   JSB   Created
34  
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 INCLUDES
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39 #ifdef FGFS
40 #  include <simgear/compiler.h>
41 #  ifdef FG_HAVE_STD_INCLUDES
42 #    include <cmath>
43 #  else
44 #    include <math.h>
45 #  endif
46 #else
47 #  include <cmath>
48 #endif
49
50 #ifndef M_PI 
51 #  include <simgear/constants.h>
52 #  define M_PI FG_PI
53 #endif
54
55 #include "FGState.h"
56 #include "FGFDMExec.h"
57 #include "FGAtmosphere.h"
58 #include "FGFCS.h"
59 #include "FGAircraft.h"
60 #include "FGTranslation.h"
61 #include "FGRotation.h"
62 #include "FGPosition.h"
63 #include "FGAuxiliary.h"
64 #include "FGOutput.h"
65
66 static const char *IdSrc = "$Header$";
67 static const char *IdHdr = ID_STATE;
68
69 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 MACROS
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72
73 #define RegisterVariable(ID,DEF) coeffdef[#ID] = ID; paramdef[ID] = DEF
74
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 CLASS IMPLEMENTATION
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 //
81 // For every term registered here there must be a corresponding handler in
82 // GetParameter() below that retrieves that parameter. Also, there must be an
83 // entry in the enum eParam definition in FGDefs.h. The ID is what must be used
84 // in any config file entry which references that item.
85
86 FGState::FGState(FGFDMExec* fdex) : mTb2l(3,3),
87     mTl2b(3,3),
88     mTs2b(3,3),
89     vQtrn(4)
90 {
91   FDMExec = fdex;
92
93   a = 1000.0;
94   sim_time = 0.0;
95   dt = 1.0/120.0;
96
97   RegisterVariable(FG_QBAR,           " qbar "           );
98   RegisterVariable(FG_WINGAREA,       " wing_area "      );
99   RegisterVariable(FG_WINGSPAN,       " wingspan "       );
100   RegisterVariable(FG_CBAR,           " cbar "           );
101   RegisterVariable(FG_ALPHA,          " alpha "          );
102   RegisterVariable(FG_ALPHADOT,       " alphadot "       );
103   RegisterVariable(FG_BETA,           " beta "           );
104   RegisterVariable(FG_BETADOT,        " betadot "        );
105   RegisterVariable(FG_PITCHRATE,      " pitch_rate "     );
106   RegisterVariable(FG_ROLLRATE,       " roll_rate "      );
107   RegisterVariable(FG_YAWRATE,        " yaw_rate "       );
108   RegisterVariable(FG_MACH,           " mach "           );
109   RegisterVariable(FG_ALTITUDE,       " altitude "       );
110   RegisterVariable(FG_BI2VEL,         " BI2Vel "         );
111   RegisterVariable(FG_CI2VEL,         " CI2Vel "         );
112   RegisterVariable(FG_ELEVATOR_POS,   " elevator_pos "   );
113   RegisterVariable(FG_AILERON_POS,    " aileron_pos "    );
114   RegisterVariable(FG_RUDDER_POS,     " rudder_pos "     );
115   RegisterVariable(FG_SPDBRAKE_POS,   " speedbrake_pos " );
116   RegisterVariable(FG_SPOILERS_POS,   " spoiler_pos "    );
117   RegisterVariable(FG_FLAPS_POS,      " flaps_pos "      );
118   RegisterVariable(FG_ELEVATOR_CMD,   " elevator_cmd "   );
119   RegisterVariable(FG_AILERON_CMD,    " aileron_cmd "    );
120   RegisterVariable(FG_RUDDER_CMD,     " rudder_cmd "     );
121   RegisterVariable(FG_SPDBRAKE_CMD,   " speedbrake_cmd " );
122   RegisterVariable(FG_SPOILERS_CMD,   " spoiler_cmd "    );
123   RegisterVariable(FG_FLAPS_CMD,      " flaps_cmd "      );
124   RegisterVariable(FG_THROTTLE_CMD,   " throttle_cmd "   );
125   RegisterVariable(FG_THROTTLE_POS,   " throttle_pos "   );
126   RegisterVariable(FG_HOVERB,         " height/span "    );
127   RegisterVariable(FG_PITCH_TRIM_CMD, " pitch_trim_cmd " );
128 }
129
130 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131
132 FGState::~FGState(void) {}
133
134 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135
136 float FGState::GetParameter(eParam val_idx) {
137   switch(val_idx) {
138   case FG_QBAR:
139     return FDMExec->GetTranslation()->Getqbar();
140   case FG_WINGAREA:
141     return FDMExec->GetAircraft()->GetWingArea();
142   case FG_WINGSPAN:
143     return FDMExec->GetAircraft()->GetWingSpan();
144   case FG_CBAR:
145     return FDMExec->GetAircraft()->Getcbar();
146   case FG_ALPHA:
147     return FDMExec->GetTranslation()->Getalpha();
148   case FG_ALPHADOT:
149     return FDMExec->GetTranslation()->Getadot();
150   case FG_BETA:
151     return FDMExec->GetTranslation()->Getbeta();
152   case FG_BETADOT:
153     return FDMExec->GetTranslation()->Getbdot();
154   case FG_PITCHRATE:
155     return (FDMExec->GetRotation()->GetPQR())(2);
156   case FG_ROLLRATE:
157     return (FDMExec->GetRotation()->GetPQR())(1);
158   case FG_YAWRATE:
159     return (FDMExec->GetRotation()->GetPQR())(3);
160   case FG_ELEVATOR_POS:
161     return FDMExec->GetFCS()->GetDePos();
162   case FG_AILERON_POS:
163     return FDMExec->GetFCS()->GetDaPos();
164   case FG_RUDDER_POS:
165     return FDMExec->GetFCS()->GetDrPos();
166   case FG_SPDBRAKE_POS:
167     return FDMExec->GetFCS()->GetDsbPos();
168   case FG_SPOILERS_POS:
169     return FDMExec->GetFCS()->GetDspPos();
170   case FG_FLAPS_POS:
171     return FDMExec->GetFCS()->GetDfPos();
172   case FG_ELEVATOR_CMD:
173     return FDMExec->GetFCS()->GetDeCmd();
174   case FG_AILERON_CMD:
175     return FDMExec->GetFCS()->GetDaCmd();
176   case FG_RUDDER_CMD:
177     return FDMExec->GetFCS()->GetDrCmd();
178   case FG_SPDBRAKE_CMD:
179     return FDMExec->GetFCS()->GetDsbCmd();
180   case FG_SPOILERS_CMD:
181     return FDMExec->GetFCS()->GetDspCmd();
182   case FG_FLAPS_CMD:
183     return FDMExec->GetFCS()->GetDfCmd();
184   case FG_MACH:
185     return FDMExec->GetTranslation()->GetMach();
186   case FG_ALTITUDE:
187     return FDMExec->GetPosition()->Geth();
188   case FG_BI2VEL:
189     if(FDMExec->GetTranslation()->GetVt() > 0)
190         return FDMExec->GetAircraft()->GetWingSpan()/(2.0 * FDMExec->GetTranslation()->GetVt());
191     else
192         return 0;
193   case FG_CI2VEL:
194     if(FDMExec->GetTranslation()->GetVt() > 0)
195         return FDMExec->GetAircraft()->Getcbar()/(2.0 * FDMExec->GetTranslation()->GetVt());
196     else
197         return 0;
198   case FG_THROTTLE_CMD:
199     return FDMExec->GetFCS()->GetThrottleCmd(0);
200   case FG_THROTTLE_POS:
201     return FDMExec->GetFCS()->GetThrottlePos(0);
202   case FG_HOVERB:
203     return FDMExec->GetPosition()->GetHOverB();
204   case FG_PITCH_TRIM_CMD:
205     return FDMExec->GetFCS()->GetPitchTrimCmd();
206   default:
207     cerr << "FGState::GetParameter() - No handler for parameter " << val_idx << endl;
208     return 0.0;
209   }
210   return 0;
211 }
212
213 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214
215 float FGState::GetParameter(string val_string) {
216   return GetParameter(coeffdef[val_string]);
217 }
218
219 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220
221 eParam FGState::GetParameterIndex(string val_string) {
222   return coeffdef[val_string];
223 }
224
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226
227 void FGState::SetParameter(eParam val_idx, float val) {
228   switch(val_idx) {
229   case FG_ELEVATOR_POS:
230     FDMExec->GetFCS()->SetDePos(val);
231     break;
232   case FG_AILERON_POS:
233     FDMExec->GetFCS()->SetDaPos(val);
234     break;
235   case FG_RUDDER_POS:
236     FDMExec->GetFCS()->SetDrPos(val);
237     break;
238   case FG_SPDBRAKE_POS:
239     FDMExec->GetFCS()->SetDsbPos(val);
240     break;
241   case FG_SPOILERS_POS:
242     FDMExec->GetFCS()->SetDspPos(val);
243     break;
244   case FG_FLAPS_POS:
245     FDMExec->GetFCS()->SetDfPos(val);
246     break;
247   case FG_THROTTLE_POS:
248     FDMExec->GetFCS()->SetThrottlePos(-1,val);
249   }
250 }
251
252 //***************************************************************************
253 //
254 // Reset: Assume all angles READ FROM FILE IN DEGREES !!
255 //
256
257 bool FGState::Reset(string path, string acname, string fname) {
258   string resetDef;
259   float U, V, W;
260   float phi, tht, psi;
261   float latitude, longitude, h;
262
263   resetDef = path + "/" + acname + "/" + fname;
264
265   ifstream resetfile(resetDef.c_str());
266
267   if (resetfile) {
268     resetfile >> U;
269     resetfile >> V;
270     resetfile >> W;
271     resetfile >> latitude;
272     resetfile >> longitude;
273     resetfile >> phi;
274     resetfile >> tht;
275     resetfile >> psi;
276     resetfile >> h;
277     resetfile.close();
278
279     FDMExec->GetPosition()->SetLatitude(latitude*DEGTORAD);
280     FDMExec->GetPosition()->SetLongitude(longitude*DEGTORAD);
281     FDMExec->GetPosition()->Seth(h);
282
283     Initialize(U, V, W, phi*DEGTORAD, tht*DEGTORAD, psi*DEGTORAD,
284                latitude*DEGTORAD, longitude*DEGTORAD, h);
285
286     return true;
287   } else {
288     cerr << "Unable to load reset file " << fname << endl;
289     return false;
290   }
291 }
292
293 //***************************************************************************
294 //
295 // Initialize: Assume all angles GIVEN IN RADIANS !!
296 //
297
298 void FGState::Initialize(float U, float V, float W,
299                          float phi, float tht, float psi,
300                          float Latitude, float Longitude, float H) {
301   FGColumnVector vUVW(3);
302   FGColumnVector vLocalVelNED(3);
303   FGColumnVector vEuler(3);
304   float alpha, beta;
305   float qbar, Vt;
306
307   FDMExec->GetPosition()->SetLatitude(Latitude);
308   FDMExec->GetPosition()->SetLongitude(Longitude);
309   FDMExec->GetPosition()->Seth(H);
310
311   FDMExec->GetAtmosphere()->Run();
312
313   if (W != 0.0)
314     alpha = U*U > 0.0 ? atan2(W, U) : 0.0;
315   else
316     alpha = 0.0;
317   if (V != 0.0)
318     beta = U*U+W*W > 0.0 ? atan2(V, (fabs(U)/U)*sqrt(U*U + W*W)) : 0.0;
319   else
320     beta = 0.0;
321
322   vUVW << U << V << W;
323   FDMExec->GetTranslation()->SetUVW(vUVW);
324
325   vEuler << phi << tht << psi;
326   FDMExec->GetRotation()->SetEuler(vEuler);
327
328   FDMExec->GetTranslation()->SetAB(alpha, beta);
329
330   Vt = sqrt(U*U + V*V + W*W);
331   FDMExec->GetTranslation()->SetVt(Vt);
332
333   FDMExec->GetTranslation()->SetMach(Vt/FDMExec->GetAtmosphere()->GetSoundSpeed());
334
335   qbar = 0.5*(U*U + V*V + W*W)*FDMExec->GetAtmosphere()->GetDensity();
336   FDMExec->GetTranslation()->Setqbar(qbar);
337
338   InitMatrices(phi, tht, psi);
339
340   vLocalVelNED = mTb2l*vUVW;
341   FDMExec->GetPosition()->SetvVel(vLocalVelNED);
342 }
343
344 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345
346 void FGState::Initialize(FGInitialCondition *FGIC) {
347
348   float tht,psi,phi;
349   float U, V, W, h;
350   float latitude, longitude;
351
352   latitude = FGIC->GetLatitudeRadIC();
353   longitude = FGIC->GetLongitudeRadIC();
354   h = FGIC->GetAltitudeFtIC();
355   U = FGIC->GetUBodyFpsIC();
356   V = FGIC->GetVBodyFpsIC();
357   W = FGIC->GetWBodyFpsIC();
358   tht = FGIC->GetThetaRadIC();
359   phi = FGIC->GetPhiRadIC();
360   psi = FGIC->GetPsiRadIC();
361
362   Initialize(U, V, W, phi, tht, psi, latitude, longitude, h);
363   
364   FDMExec->GetPosition()->SetSeaLevelRadius( FGIC->GetSeaLevelRadiusFtIC() );
365   FDMExec->GetPosition()->SetRunwayRadius( FGIC->GetSeaLevelRadiusFtIC() + 
366                                              FGIC->GetTerrainAltitudeFtIC() );
367
368 }
369
370 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371
372 bool FGState::StoreData(string fname) {
373   ofstream datafile(fname.c_str());
374
375   if (datafile) {
376     datafile << (FDMExec->GetTranslation()->GetUVW())(1);
377     datafile << (FDMExec->GetTranslation()->GetUVW())(2);
378     datafile << (FDMExec->GetTranslation()->GetUVW())(3);
379     datafile << FDMExec->GetPosition()->GetLatitude();
380     datafile << FDMExec->GetPosition()->GetLongitude();
381     datafile << (FDMExec->GetRotation()->GetEuler())(1);
382     datafile << (FDMExec->GetRotation()->GetEuler())(2);
383     datafile << (FDMExec->GetRotation()->GetEuler())(3);
384     datafile << FDMExec->GetPosition()->Geth();
385     datafile.close();
386     return true;
387   } else {
388     cerr << "Could not open dump file " << fname << endl;
389     return false;
390   }
391 }
392
393 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394
395 void FGState::InitMatrices(float phi, float tht, float psi) {
396   float thtd2, psid2, phid2;
397   float Sthtd2, Spsid2, Sphid2;
398   float Cthtd2, Cpsid2, Cphid2;
399   float Cphid2Cthtd2;
400   float Cphid2Sthtd2;
401   float Sphid2Sthtd2;
402   float Sphid2Cthtd2;
403
404   thtd2 = tht/2.0;
405   psid2 = psi/2.0;
406   phid2 = phi/2.0;
407
408   Sthtd2 = sin(thtd2);
409   Spsid2 = sin(psid2);
410   Sphid2 = sin(phid2);
411
412   Cthtd2 = cos(thtd2);
413   Cpsid2 = cos(psid2);
414   Cphid2 = cos(phid2);
415
416   Cphid2Cthtd2 = Cphid2*Cthtd2;
417   Cphid2Sthtd2 = Cphid2*Sthtd2;
418   Sphid2Sthtd2 = Sphid2*Sthtd2;
419   Sphid2Cthtd2 = Sphid2*Cthtd2;
420
421   vQtrn(1) = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
422   vQtrn(2) = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
423   vQtrn(3) = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
424   vQtrn(4) = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
425
426   CalcMatrices();
427 }
428
429 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430
431 void FGState::CalcMatrices(void) {
432   float Q0Q0, Q1Q1, Q2Q2, Q3Q3;
433   float Q0Q1, Q0Q2, Q0Q3, Q1Q2;
434   float Q1Q3, Q2Q3;
435
436   Q0Q0 = vQtrn(1)*vQtrn(1);
437   Q1Q1 = vQtrn(2)*vQtrn(2);
438   Q2Q2 = vQtrn(3)*vQtrn(3);
439   Q3Q3 = vQtrn(4)*vQtrn(4);
440   Q0Q1 = vQtrn(1)*vQtrn(2);
441   Q0Q2 = vQtrn(1)*vQtrn(3);
442   Q0Q3 = vQtrn(1)*vQtrn(4);
443   Q1Q2 = vQtrn(2)*vQtrn(3);
444   Q1Q3 = vQtrn(2)*vQtrn(4);
445   Q2Q3 = vQtrn(3)*vQtrn(4);
446
447   mTl2b(1,1) = Q0Q0 + Q1Q1 - Q2Q2 - Q3Q3;
448   mTl2b(1,2) = 2*(Q1Q2 + Q0Q3);
449   mTl2b(1,3) = 2*(Q1Q3 - Q0Q2);
450   mTl2b(2,1) = 2*(Q1Q2 - Q0Q3);
451   mTl2b(2,2) = Q0Q0 - Q1Q1 + Q2Q2 - Q3Q3;
452   mTl2b(2,3) = 2*(Q2Q3 + Q0Q1);
453   mTl2b(3,1) = 2*(Q1Q3 + Q0Q2);
454   mTl2b(3,2) = 2*(Q2Q3 - Q0Q1);
455   mTl2b(3,3) = Q0Q0 - Q1Q1 - Q2Q2 + Q3Q3;
456
457   mTb2l = mTl2b;
458   mTb2l.T();
459 }
460
461 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462
463 void FGState::IntegrateQuat(FGColumnVector vPQR, int rate) {
464   static FGColumnVector vlastQdot(4);
465   static FGColumnVector vQdot(4);
466
467   vQdot(1) = -0.5*(vQtrn(2)*vPQR(eP) + vQtrn(3)*vPQR(eQ) + vQtrn(4)*vPQR(eR));
468   vQdot(2) =  0.5*(vQtrn(1)*vPQR(eP) + vQtrn(3)*vPQR(eR) - vQtrn(4)*vPQR(eQ));
469   vQdot(3) =  0.5*(vQtrn(1)*vPQR(eQ) + vQtrn(4)*vPQR(eP) - vQtrn(2)*vPQR(eR));
470   vQdot(4) =  0.5*(vQtrn(1)*vPQR(eR) + vQtrn(2)*vPQR(eQ) - vQtrn(3)*vPQR(eP));
471
472   vQtrn += 0.5*dt*rate*(vlastQdot + vQdot);
473
474   vQtrn.Normalize();
475
476   vlastQdot = vQdot;
477 }
478
479 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480
481 FGColumnVector FGState::CalcEuler(void) {
482   static FGColumnVector vEuler(3);
483
484   if (mTl2b(3,3) == 0.0) mTl2b(3,3) = 0.0000001;
485   if (mTl2b(1,1) == 0.0) mTl2b(1,1) = 0.0000001;
486
487   vEuler(ePhi) = atan2(mTl2b(2,3), mTl2b(3,3));
488   vEuler(eTht) = asin(-mTl2b(1,3));
489   vEuler(ePsi) = atan2(mTl2b(1,2), mTl2b(1,1));
490
491   if (vEuler(ePsi) < 0.0) vEuler(ePsi) += 2*M_PI;
492
493   return vEuler;
494 }
495
496 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497
498 FGMatrix FGState::GetTs2b(float alpha, float beta) {
499   float ca, cb, sa, sb;
500
501   ca = cos(alpha);
502   sa = sin(alpha);
503   cb = cos(beta);
504   sb = sin(beta);
505
506   mTs2b(1,1) = -ca*cb;
507   mTs2b(1,2) = -ca*sb;
508   mTs2b(1,3) = sa;
509   mTs2b(2,1) = -sb;
510   mTs2b(2,2) = cb;
511   mTs2b(2,3) = 0.0;
512   mTs2b(3,1) = -sa*cb;
513   mTs2b(3,2) = -sa*sb;
514   mTs2b(3,3) = -ca;
515
516   return mTs2b;
517 }
518
519 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520