]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGColumnVector3.cpp
Cygwin fixes.
[flightgear.git] / src / FDM / JSBSim / FGColumnVector3.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGColumnVector3.cpp
4 Author: Originally by Tony Peden [formatted here (and broken??) by JSB]
5 Date started: 1998
6 Purpose: FGColumnVector3 class
7 Called by: Various
8
9 FUNCTIONAL DESCRIPTION
10 --------------------------------------------------------------------------------
11
12 HISTORY
13 --------------------------------------------------------------------------------
14 ??/??/??   TP   Created
15 03/16/2000 JSB  Added exception throwing
16
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 INCLUDES
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include "FGColumnVector3.h"
26 #include <cstdio>
27
28 namespace JSBSim {
29
30 static const char *IdSrc = "$Id$";
31 static const char *IdHdr = ID_COLUMNVECTOR3;
32
33 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 CLASS IMPLEMENTATION
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36
37 FGColumnVector3::FGColumnVector3(void)
38 {
39   data[0] = data[1] = data[2] = 0.0;
40   Debug(0);
41 }
42
43 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44
45 string FGColumnVector3::Dump(string delimeter) const
46 {
47   char buffer[256];
48   sprintf(buffer, "%f%s%f%s%f", Entry(1), delimeter.c_str(), Entry(2), delimeter.c_str(), Entry(3));
49   return string(buffer);
50 }
51
52 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54 FGColumnVector3 FGColumnVector3::operator/(const double scalar) const
55 {
56   if (scalar != 0.0)
57     return operator*( 1.0/scalar );
58
59   cerr << "Attempt to divide by zero in method "
60     "FGColumnVector3::operator/(const double scalar), "
61     "object " << this << endl;
62   return FGColumnVector3();
63 }
64
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
67 FGColumnVector3& FGColumnVector3::operator/=(const double scalar)
68 {
69   if (scalar != 0.0)
70     operator*=( 1.0/scalar );
71   else
72     cerr << "Attempt to divide by zero in method "
73       "FGColumnVector3::operator/=(const double scalar), "
74       "object " << this << endl;
75
76   return *this;
77 }
78
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80
81 double FGColumnVector3::Magnitude(void) const
82 {
83   if (Entry(1) == 0.0 && Entry(2) == 0.0 && Entry(3) == 0.0)
84     return 0.0;
85   else
86     return sqrt( Entry(1)*Entry(1) +  Entry(2)*Entry(2) +  Entry(3)*Entry(3) );
87 }
88
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90
91 FGColumnVector3& FGColumnVector3::Normalize(void)
92 {
93   double Mag = Magnitude();
94
95   if (Mag != 0.0)
96     operator*=( 1.0/Mag );
97
98   return *this;
99 }
100
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102
103 FGColumnVector3 FGColumnVector3::multElementWise(const FGColumnVector3& V) const
104 {
105   return FGColumnVector3(Entry(1) * V(1), Entry(2) * V(2), Entry(3) * V(3));
106 }
107
108 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
110 ostream& operator<<(ostream& os, const FGColumnVector3& col)
111 {
112   os << col(1) << " , " << col(2) << " , " << col(3);
113   return os;
114 }
115
116 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
117 //    The bitmasked value choices are as follows:
118 //    unset: In this case (the default) JSBSim would only print
119 //       out the normally expected messages, essentially echoing
120 //       the config files as they are read. If the environment
121 //       variable is not set, debug_lvl is set to 1 internally
122 //    0: This requests JSBSim not to output any messages
123 //       whatsoever.
124 //    1: This value explicity requests the normal JSBSim
125 //       startup messages
126 //    2: This value asks for a message to be printed out when
127 //       a class is instantiated
128 //    4: When this value is set, a message is displayed when a
129 //       FGModel object executes its Run() method
130 //    8: When this value is set, various runtime state variables
131 //       are printed out periodically
132 //    16: When set various parameters are sanity checked and
133 //       a message is printed out when they go out of bounds
134
135 void FGColumnVector3::Debug(int from)
136 {
137   if (debug_lvl <= 0) return;
138
139   if (debug_lvl & 1) { // Standard console startup message output
140   }
141   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
142     if (from == 0) cout << "Instantiated: FGColumnVector3" << endl;
143     if (from == 1) cout << "Destroyed:    FGColumnVector3" << endl;
144   }
145   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
146   }
147   if (debug_lvl & 8 ) { // Runtime state variables
148   }
149   if (debug_lvl & 16) { // Sanity checking
150   }
151   if (debug_lvl & 64) {
152     if (from == 0) { // Constructor
153       cout << IdSrc << endl;
154       cout << IdHdr << endl;
155     }
156   }
157 }
158
159 } // namespace JSBSim