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)
34 data[0] = data[1] = data[2] = 0.0;
38 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 FGColumnVector3 FGColumnVector3::operator/(const double scalar) const
43 return operator*( 1.0/scalar );
45 cerr << "Attempt to divide by zero in method "
46 "FGColumnVector3::operator/(const double scalar), "
47 "object " << this << endl;
48 return FGColumnVector3();
51 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 FGColumnVector3& FGColumnVector3::operator/=(const double scalar)
56 operator*=( 1.0/scalar );
58 cerr << "Attempt to divide by zero in method "
59 "FGColumnVector3::operator/=(const double scalar), "
60 "object " << this << endl;
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 double FGColumnVector3::Magnitude(void) const
69 if (data[1] == 0.0 && data[2] == 0.0 && data[3] == 0.0)
72 return sqrt( Entry(1)*Entry(1) + Entry(2)*Entry(2) + Entry(3)*Entry(3) );
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 FGColumnVector3& FGColumnVector3::Normalize(void)
79 double Mag = Magnitude();
82 operator*=( 1.0/Mag );
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 FGColumnVector3 FGColumnVector3::multElementWise(const FGColumnVector3& V) const
91 return FGColumnVector3(Entry(1) * V(1), Entry(2) * V(2), Entry(3) * V(3));
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 ostream& operator<<(ostream& os, const FGColumnVector3& col)
98 os << col(1) << " , " << col(2) << " , " << col(3);
102 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
103 // The bitmasked value choices are as follows:
104 // unset: In this case (the default) JSBSim would only print
105 // out the normally expected messages, essentially echoing
106 // the config files as they are read. If the environment
107 // variable is not set, debug_lvl is set to 1 internally
108 // 0: This requests JSBSim not to output any messages
110 // 1: This value explicity requests the normal JSBSim
112 // 2: This value asks for a message to be printed out when
113 // a class is instantiated
114 // 4: When this value is set, a message is displayed when a
115 // FGModel object executes its Run() method
116 // 8: When this value is set, various runtime state variables
117 // are printed out periodically
118 // 16: When set various parameters are sanity checked and
119 // a message is printed out when they go out of bounds
121 void FGColumnVector3::Debug(int from)
123 if (debug_lvl <= 0) return;
125 if (debug_lvl & 1) { // Standard console startup message output
127 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
128 if (from == 0) cout << "Instantiated: FGColumnVector3" << endl;
129 if (from == 1) cout << "Destroyed: FGColumnVector3" << endl;
131 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
133 if (debug_lvl & 8 ) { // Runtime state variables
135 if (debug_lvl & 16) { // Sanity checking
137 if (debug_lvl & 64) {
138 if (from == 0) { // Constructor
139 cout << IdSrc << endl;
140 cout << IdHdr << endl;
145 } // namespace JSBSim