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"
23 static const char *IdSrc = "$Id$";
24 static const char *IdHdr = ID_COLUMNVECTOR3;
26 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
30 FGColumnVector3::FGColumnVector3(void)
33 data[0]=0; data[1]=0; data[2]=0; data[3]=0;
38 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 FGColumnVector3::FGColumnVector3(double X, double Y, double Z)
43 data[0] = 0; data[eX] = X; data[eY] = Y; data[eZ] = Z;
48 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FGColumnVector3::~FGColumnVector3(void)
56 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 FGColumnVector3::FGColumnVector3(const FGColumnVector3& b)
68 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 FGColumnVector3 FGColumnVector3::operator=(const FGColumnVector3& b)
80 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 FGColumnVector3 FGColumnVector3::operator+(const FGColumnVector3& C)
85 Sum(1) = C(1) + data[1];
86 Sum(2) = C(2) + data[2];
87 Sum(3) = C(3) + data[3];
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 void FGColumnVector3::operator+=(const FGColumnVector3& C)
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 FGColumnVector3 FGColumnVector3::operator*(const double scalar)
105 FGColumnVector3 Product;
107 Product(1) = scalar * data[1];
108 Product(2) = scalar * data[2];
109 Product(3) = scalar * data[3];
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 void FGColumnVector3::operator*=(const double scalar)
123 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 FGColumnVector3 FGColumnVector3::operator-(const FGColumnVector3& V)
128 FGColumnVector3 Diff;
130 Diff(1) = data[1] - V(1);
131 Diff(2) = data[2] - V(2);
132 Diff(3) = data[3] - V(3);
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 void FGColumnVector3::operator-=(const FGColumnVector3& V)
146 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 FGColumnVector3 FGColumnVector3::operator/(const double scalar)
150 FGColumnVector3 Quotient;
153 double tmp = 1.0/scalar;
154 Quotient(1) = data[1] * tmp;
155 Quotient(2) = data[2] * tmp;
156 Quotient(3) = data[3] * tmp;
158 cerr << "Attempt to divide by zero in method FGColumnVector3::operator/(const double scalar), object " << this << endl;
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 void FGColumnVector3::operator/=(const double scalar)
167 FGColumnVector3 Quotient;
170 double tmp = 1.0/scalar;
175 cerr << "Attempt to divide by zero in method FGColumnVector3::operator/=(const double scalar), object " << this << endl;
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 FGColumnVector3 operator*(const double scalar, const FGColumnVector3& C)
183 FGColumnVector3 Product;
185 Product(1) = scalar * C(1);
186 Product(2) = scalar * C(2);
187 Product(3) = scalar * C(3);
192 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 double FGColumnVector3::Magnitude(void)
198 if ((data[1] == 0.00) &&
204 num = data[1]*data[1];
205 num += data[2]*data[2];
206 num += data[3]*data[3];
211 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 FGColumnVector3 FGColumnVector3::Normalize(void)
215 double Mag = Magnitude();
227 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 FGColumnVector3 FGColumnVector3::operator*(const FGColumnVector3& V)
231 FGColumnVector3 Product;
233 Product(1) = data[2] * V(3) - data[3] * V(2);
234 Product(2) = data[3] * V(1) - data[1] * V(3);
235 Product(3) = data[1] * V(2) - data[2] * V(1);
240 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 void FGColumnVector3::operator*=(const FGColumnVector3& V)
245 a = data[1]; b=data[2]; c=data[3];
247 data[1] = b * V(3) - c * V(2);
248 data[2] = c * V(1) - a * V(3);
249 data[3] = a * V(2) - b * V(1);
253 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255 FGColumnVector3 FGColumnVector3::multElementWise(const FGColumnVector3& V)
257 FGColumnVector3 Product;
259 Product(1) = data[1] * V(1);
260 Product(2) = data[2] * V(2);
261 Product(3) = data[3] * V(3);
266 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268 ostream& operator<<(ostream& os, const FGColumnVector3& col)
270 os << col(1) << " , " << col(2) << " , " << col(3);
274 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 FGColumnVector3& FGColumnVector3::operator<<(const double ff)
284 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
285 // The bitmasked value choices are as follows:
286 // unset: In this case (the default) JSBSim would only print
287 // out the normally expected messages, essentially echoing
288 // the config files as they are read. If the environment
289 // variable is not set, debug_lvl is set to 1 internally
290 // 0: This requests JSBSim not to output any messages
292 // 1: This value explicity requests the normal JSBSim
294 // 2: This value asks for a message to be printed out when
295 // a class is instantiated
296 // 4: When this value is set, a message is displayed when a
297 // FGModel object executes its Run() method
298 // 8: When this value is set, various runtime state variables
299 // are printed out periodically
300 // 16: When set various parameters are sanity checked and
301 // a message is printed out when they go out of bounds
303 void FGColumnVector3::Debug(int from)
305 if (debug_lvl <= 0) return;
307 if (debug_lvl & 1) { // Standard console startup message output
309 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
310 if (from == 0) cout << "Instantiated: FGColumnVector3" << endl;
311 if (from == 1) cout << "Destroyed: FGColumnVector3" << endl;
313 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
315 if (debug_lvl & 8 ) { // Runtime state variables
317 if (debug_lvl & 16) { // Sanity checking
319 if (debug_lvl & 64) {
320 if (from == 0) { // Constructor
321 cout << IdSrc << endl;
322 cout << IdHdr << endl;