]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGForce.cpp
7a12a2f699c42557f38d7961e525f31878003fcc
[flightgear.git] / src / FDM / JSBSim / FGForce.cpp
1 /*******************************************************************************
2  
3  Source:       FGForce.cpp
4  Author:       Tony Peden
5  Date started: 6/10/00
6  
7  ------------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) -------------
8  
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13  
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18  
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22  
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25  
26  
27  HISTORY
28 --------------------------------------------------------------------------------
29 6/10/00  TP   Created
30  
31  
32 FUNCTIONAL DESCRIPTION
33 --------------------------------------------------------------------------------
34  
35 The purpose of this class is to provide storage for computed forces and
36 encapsulate all the functionality associated with transforming those 
37 forces from their native coord system to the body system.  This includes
38 computing the moments due to the difference between the point of application
39 and the cg.
40  
41 */
42
43 #include "FGFDMExec.h"
44 #include "FGAircraft.h"
45 #include "FGTranslation.h"
46 #include "FGMatrix.h"
47 #include "FGDefs.h"
48 #include "FGForce.h"
49
50
51 FGForce::FGForce(FGFDMExec *FDMExec) :
52     vFn(3),
53     vMn(3),
54     vFb(3),
55     vM(3),
56     vXYZn(3),
57     vDXYZ(3),
58     mT(3,3),
59     vSense(3),
60     fdmex(FDMExec),
61     ttype(tNone) 
62 {
63   mT(1,1)=1; //identity matrix
64   mT(2,2)=1;
65   mT(3,3)=1;
66   vSense.InitMatrix(1);
67 }
68
69 FGForce::~FGForce(void) {}
70
71 FGColumnVector FGForce::GetBodyForces(void) {
72   
73   
74   vFb=Transform()*(vFn.multElementWise(vSense));
75
76   //find the distance from this vector's location to the cg
77   //needs to be done like this to convert from structural to body coords
78   vDXYZ(1) = -(vXYZn(1) - fdmex->GetAircraft()->GetXYZcg()(1))*INCHTOFT;
79   vDXYZ(2) =  (vXYZn(2) - fdmex->GetAircraft()->GetXYZcg()(2))*INCHTOFT;  //cg and rp values are in inches
80   vDXYZ(3) = -(vXYZn(3) - fdmex->GetAircraft()->GetXYZcg()(3))*INCHTOFT;
81
82   vM=vMn +vDXYZ*vFb;
83   
84   return vFb;
85 }
86
87
88
89 FGMatrix FGForce::Transform(void) {
90   switch(ttype) {
91   case tWindBody:
92     return fdmex->GetState()->GetTs2b(fdmex->GetTranslation()->Getalpha(),fdmex->GetTranslation()->Getbeta());
93   case tLocalBody:
94     return fdmex->GetState()->GetTl2b();
95   case tCustom:
96     
97   case tNone:
98     return mT; 
99   default:
100     cout << "Unrecognized tranform requested from FGForce::Transform()" << endl;
101     exit(1);
102   }
103 }
104
105 void FGForce::SetAnglesToBody(float broll, float bpitch, float byaw) {
106
107   if(ttype == tCustom) {
108     float cp,sp,cr,sr,cy,sy;
109
110     cp=cos(bpitch); sp=sin(bpitch);
111     cr=cos(broll);  sr=sin(broll);
112     cy=cos(byaw);   sy=sin(byaw);
113
114     mT(1,1)=cp*cy;
115     mT(1,2)=cp*sy;
116     mT(1,3)=-1*sp;
117
118     mT(2,1)=sr*sp*cy-cr*sy;
119     mT(2,2)=sr*sp*sy+cr*cy;
120     mT(2,3)=sr*cp;
121
122     mT(3,1)=cr*sp*cy+sr*sy;
123     mT(3,2)=cr*sp*sy-sr*cy;
124     mT(3,3)=cr*cp;
125   }
126
127 }
128
129