1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGColumnVector3.cpp
4 Author: Originally by Tony Peden [formatted here (and broken??) by JSB]
6 Purpose: FGColumnVector3 class
10 --------------------------------------------------------------------------------
13 --------------------------------------------------------------------------------
15 03/16/2000 JSB Added exception throwing
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
21 #include "FGColumnVector3.h"
25 static const char *IdSrc = "$Id$";
26 static const char *IdHdr = ID_COLUMNVECTOR3;
28 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32 FGColumnVector3::FGColumnVector3(void)
35 data[0]=0; data[1]=0; data[2]=0; data[3]=0;
40 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 FGColumnVector3::FGColumnVector3(double X, double Y, double Z)
45 data[0] = 0; data[eX] = X; data[eY] = Y; data[eZ] = Z;
50 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FGColumnVector3::~FGColumnVector3(void)
58 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 FGColumnVector3::FGColumnVector3(const FGColumnVector3& b)
70 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 FGColumnVector3 FGColumnVector3::operator=(const FGColumnVector3& b)
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 FGColumnVector3 FGColumnVector3::operator+(const FGColumnVector3& C)
87 Sum(1) = C(1) + data[1];
88 Sum(2) = C(2) + data[2];
89 Sum(3) = C(3) + data[3];
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 void FGColumnVector3::operator+=(const FGColumnVector3& C)
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 FGColumnVector3 FGColumnVector3::operator*(const double scalar)
107 FGColumnVector3 Product;
109 Product(1) = scalar * data[1];
110 Product(2) = scalar * data[2];
111 Product(3) = scalar * data[3];
116 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 void FGColumnVector3::operator*=(const double scalar)
125 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 FGColumnVector3 FGColumnVector3::operator-(const FGColumnVector3& V)
130 FGColumnVector3 Diff;
132 Diff(1) = data[1] - V(1);
133 Diff(2) = data[2] - V(2);
134 Diff(3) = data[3] - V(3);
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 void FGColumnVector3::operator-=(const FGColumnVector3& V)
148 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 FGColumnVector3 FGColumnVector3::operator/(const double scalar)
152 FGColumnVector3 Quotient;
155 double tmp = 1.0/scalar;
156 Quotient(1) = data[1] * tmp;
157 Quotient(2) = data[2] * tmp;
158 Quotient(3) = data[3] * tmp;
160 cerr << "Attempt to divide by zero in method FGColumnVector3::operator/(const double scalar), object " << this << endl;
165 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 void FGColumnVector3::operator/=(const double scalar)
169 FGColumnVector3 Quotient;
172 double tmp = 1.0/scalar;
177 cerr << "Attempt to divide by zero in method FGColumnVector3::operator/=(const double scalar), object " << this << endl;
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 FGColumnVector3 operator*(const double scalar, const FGColumnVector3& C)
185 FGColumnVector3 Product;
187 Product(1) = scalar * C(1);
188 Product(2) = scalar * C(2);
189 Product(3) = scalar * C(3);
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 double FGColumnVector3::Magnitude(void)
200 if ((data[1] == 0.00) &&
206 num = data[1]*data[1];
207 num += data[2]*data[2];
208 num += data[3]*data[3];
213 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 FGColumnVector3 FGColumnVector3::Normalize(void)
217 double Mag = Magnitude();
229 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 FGColumnVector3 FGColumnVector3::operator*(const FGColumnVector3& V)
233 FGColumnVector3 Product;
235 Product(1) = data[2] * V(3) - data[3] * V(2);
236 Product(2) = data[3] * V(1) - data[1] * V(3);
237 Product(3) = data[1] * V(2) - data[2] * V(1);
242 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 void FGColumnVector3::operator*=(const FGColumnVector3& V)
247 a = data[1]; b=data[2]; c=data[3];
249 data[1] = b * V(3) - c * V(2);
250 data[2] = c * V(1) - a * V(3);
251 data[3] = a * V(2) - b * V(1);
255 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 FGColumnVector3 FGColumnVector3::multElementWise(const FGColumnVector3& V)
259 FGColumnVector3 Product;
261 Product(1) = data[1] * V(1);
262 Product(2) = data[2] * V(2);
263 Product(3) = data[3] * V(3);
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 ostream& operator<<(ostream& os, const FGColumnVector3& col)
272 os << col(1) << " , " << col(2) << " , " << col(3);
276 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 FGColumnVector3& FGColumnVector3::operator<<(const double ff)
286 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
287 // The bitmasked value choices are as follows:
288 // unset: In this case (the default) JSBSim would only print
289 // out the normally expected messages, essentially echoing
290 // the config files as they are read. If the environment
291 // variable is not set, debug_lvl is set to 1 internally
292 // 0: This requests JSBSim not to output any messages
294 // 1: This value explicity requests the normal JSBSim
296 // 2: This value asks for a message to be printed out when
297 // a class is instantiated
298 // 4: When this value is set, a message is displayed when a
299 // FGModel object executes its Run() method
300 // 8: When this value is set, various runtime state variables
301 // are printed out periodically
302 // 16: When set various parameters are sanity checked and
303 // a message is printed out when they go out of bounds
305 void FGColumnVector3::Debug(int from)
307 if (debug_lvl <= 0) return;
309 if (debug_lvl & 1) { // Standard console startup message output
311 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
312 if (from == 0) cout << "Instantiated: FGColumnVector3" << endl;
313 if (from == 1) cout << "Destroyed: FGColumnVector3" << endl;
315 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
317 if (debug_lvl & 8 ) { // Runtime state variables
319 if (debug_lvl & 16) { // Sanity checking
321 if (debug_lvl & 64) {
322 if (from == 0) { // Constructor
323 cout << IdSrc << endl;
324 cout << IdHdr << endl;
329 } // namespace JSBSim