00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00002 00003 Module: FGColumnVector3.cpp 00004 Author: Originally by Tony Peden [formatted here by JSB] 00005 Date started: 1998 00006 Purpose: FGColumnVector3 class 00007 Called by: Various 00008 00009 ------------- Copyright (C) 1998 Tony Peden and Jon S. Berndt (jsb@hal-pc.org) - 00010 00011 This program is free software; you can redistribute it and/or modify it under 00012 the terms of the GNU Lesser General Public License as published by the Free Software 00013 Foundation; either version 2 of the License, or (at your option) any later 00014 version. 00015 00016 This program is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00018 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00019 details. 00020 00021 You should have received a copy of the GNU Lesser General Public License along with 00022 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00023 Place - Suite 330, Boston, MA 02111-1307, USA. 00024 00025 Further information about the GNU Lesser General Public License can also be found on 00026 the world wide web at http://www.gnu.org. 00027 00028 FUNCTIONAL DESCRIPTION 00029 -------------------------------------------------------------------------------- 00030 00031 HISTORY 00032 -------------------------------------------------------------------------------- 00033 ??/??/?? TP Created 00034 03/16/2000 JSB Added exception throwing 00035 00036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00037 INCLUDES 00038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00039 00040 #include "FGColumnVector3.h" 00041 #include <cstdio> 00042 00043 namespace JSBSim { 00044 00045 static const char *IdSrc = "$Id: FGColumnVector3.cpp,v 1.9 2009/03/15 15:38:31 jberndt Exp $"; 00046 static const char *IdHdr = ID_COLUMNVECTOR3; 00047 00048 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00049 CLASS IMPLEMENTATION 00050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00051 00052 FGColumnVector3::FGColumnVector3(void) 00053 { 00054 data[0] = data[1] = data[2] = 0.0; 00055 // Debug(0); 00056 } 00057 00058 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00059 00060 string FGColumnVector3::Dump(string delimeter) const 00061 { 00062 char buffer[256]; 00063 sprintf(buffer, "%18.16f%s%18.16f%s%18.16f", Entry(1), delimeter.c_str(), Entry(2), delimeter.c_str(), Entry(3)); 00064 return string(buffer); 00065 } 00066 00067 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00068 00069 ostream& operator<<(ostream& os, const FGColumnVector3& col) 00070 { 00071 os << col(1) << " , " << col(2) << " , " << col(3); 00072 return os; 00073 } 00074 00075 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00076 00077 FGColumnVector3 FGColumnVector3::operator/(const double scalar) const 00078 { 00079 if (scalar != 0.0) 00080 return operator*( 1.0/scalar ); 00081 00082 cerr << "Attempt to divide by zero in method \ 00083 FGColumnVector3::operator/(const double scalar), \ 00084 object " << data[0] << " , " << data[1] << " , " << data[2] << endl; 00085 return FGColumnVector3(); 00086 } 00087 00088 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00089 00090 FGColumnVector3& FGColumnVector3::operator/=(const double scalar) 00091 { 00092 if (scalar != 0.0) 00093 operator*=( 1.0/scalar ); 00094 else 00095 cerr << "Attempt to divide by zero in method \ 00096 FGColumnVector3::operator/=(const double scalar), \ 00097 object " << data[0] << " , " << data[1] << " , " << data[2] << endl; 00098 00099 return *this; 00100 } 00101 00102 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00103 00104 double FGColumnVector3::Magnitude(void) const 00105 { 00106 if (Entry(1) == 0.0 && Entry(2) == 0.0 && Entry(3) == 0.0) 00107 return 0.0; 00108 else 00109 return sqrt( Entry(1)*Entry(1) + Entry(2)*Entry(2) + Entry(3)*Entry(3) ); 00110 } 00111 00112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00113 00114 FGColumnVector3& FGColumnVector3::Normalize(void) 00115 { 00116 double Mag = Magnitude(); 00117 00118 if (Mag != 0.0) 00119 operator*=( 1.0/Mag ); 00120 00121 return *this; 00122 } 00123 00124 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00125 // The bitmasked value choices are as follows: 00126 // unset: In this case (the default) JSBSim would only print 00127 // out the normally expected messages, essentially echoing 00128 // the config files as they are read. If the environment 00129 // variable is not set, debug_lvl is set to 1 internally 00130 // 0: This requests JSBSim not to output any messages 00131 // whatsoever. 00132 // 1: This value explicity requests the normal JSBSim 00133 // startup messages 00134 // 2: This value asks for a message to be printed out when 00135 // a class is instantiated 00136 // 4: When this value is set, a message is displayed when a 00137 // FGModel object executes its Run() method 00138 // 8: When this value is set, various runtime state variables 00139 // are printed out periodically 00140 // 16: When set various parameters are sanity checked and 00141 // a message is printed out when they go out of bounds 00142 00143 void FGColumnVector3::Debug(int from) 00144 { 00145 if (debug_lvl <= 0) return; 00146 00147 if (debug_lvl & 1) { // Standard console startup message output 00148 } 00149 if (debug_lvl & 2 ) { // Instantiation/Destruction notification 00150 if (from == 0) cout << "Instantiated: FGColumnVector3" << endl; 00151 if (from == 1) cout << "Destroyed: FGColumnVector3" << endl; 00152 } 00153 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects 00154 } 00155 if (debug_lvl & 8 ) { // Runtime state variables 00156 } 00157 if (debug_lvl & 16) { // Sanity checking 00158 } 00159 if (debug_lvl & 64) { 00160 if (from == 0) { // Constructor 00161 cout << IdSrc << endl; 00162 cout << IdHdr << endl; 00163 } 00164 } 00165 } 00166 00167 } // namespace JSBSim
1.5.5