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"
26 static const char *IdSrc = "$Id$";
27 static const char *IdHdr = ID_COLUMNVECTOR3;
29 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33 FGColumnVector3::FGColumnVector3(void)
35 data[0] = data[1] = data[2] = 0.0;
39 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 string FGColumnVector3::Dump(string delimeter) const
44 sprintf(buffer, "%f%s%f%s%f", Entry(1), delimeter.c_str(), Entry(2), delimeter.c_str(), Entry(3));
45 return string(buffer);
48 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 ostream& operator<<(ostream& os, const FGColumnVector3& col)
52 os << col(1) << " , " << col(2) << " , " << col(3);
56 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 FGColumnVector3 FGColumnVector3::operator/(const double scalar) const
61 return operator*( 1.0/scalar );
63 cerr << "Attempt to divide by zero in method \
64 FGColumnVector3::operator/(const double scalar), \
65 object " << data[0] << " , " << data[1] << " , " << data[2] << endl;
66 return FGColumnVector3();
69 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 FGColumnVector3& FGColumnVector3::operator/=(const double scalar)
74 operator*=( 1.0/scalar );
76 cerr << "Attempt to divide by zero in method \
77 FGColumnVector3::operator/=(const double scalar), \
78 object " << data[0] << " , " << data[1] << " , " << data[2] << endl;
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 double FGColumnVector3::Magnitude(void) const
87 if (Entry(1) == 0.0 && Entry(2) == 0.0 && Entry(3) == 0.0)
90 return sqrt( Entry(1)*Entry(1) + Entry(2)*Entry(2) + Entry(3)*Entry(3) );
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 FGColumnVector3& FGColumnVector3::Normalize(void)
97 double Mag = Magnitude();
100 operator*=( 1.0/Mag );
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 FGColumnVector3 FGColumnVector3::multElementWise(const FGColumnVector3& V) const
109 return FGColumnVector3(Entry(1) * V(1), Entry(2) * V(2), Entry(3) * V(3));
112 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
113 // The bitmasked value choices are as follows:
114 // unset: In this case (the default) JSBSim would only print
115 // out the normally expected messages, essentially echoing
116 // the config files as they are read. If the environment
117 // variable is not set, debug_lvl is set to 1 internally
118 // 0: This requests JSBSim not to output any messages
120 // 1: This value explicity requests the normal JSBSim
122 // 2: This value asks for a message to be printed out when
123 // a class is instantiated
124 // 4: When this value is set, a message is displayed when a
125 // FGModel object executes its Run() method
126 // 8: When this value is set, various runtime state variables
127 // are printed out periodically
128 // 16: When set various parameters are sanity checked and
129 // a message is printed out when they go out of bounds
131 void FGColumnVector3::Debug(int from)
133 if (debug_lvl <= 0) return;
135 if (debug_lvl & 1) { // Standard console startup message output
137 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
138 if (from == 0) cout << "Instantiated: FGColumnVector3" << endl;
139 if (from == 1) cout << "Destroyed: FGColumnVector3" << endl;
141 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
143 if (debug_lvl & 8 ) { // Runtime state variables
145 if (debug_lvl & 16) { // Sanity checking
147 if (debug_lvl & 64) {
148 if (from == 0) { // Constructor
149 cout << IdSrc << endl;
150 cout << IdHdr << endl;
155 } // namespace JSBSim