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;
35 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
38 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 FGColumnVector3::FGColumnVector3(double X, double Y, double Z)
43 data[0] = 0; data[eX] = X; data[eY] = Y; data[eZ] = Z;
45 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
48 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FGColumnVector3::~FGColumnVector3(void)
52 if (debug_lvl & 2) cout << "Destroyed: FGColumnVector3" << endl;
56 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 FGColumnVector3::FGColumnVector3(const FGColumnVector3& b)
65 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
68 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 FGColumnVector3 FGColumnVector3::operator=(const FGColumnVector3& b)
77 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
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 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 void FGColumnVector3::Debug(int from)
290 //TODO: Add your source code here