JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++

FGColumnVector3.cpp

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 (jon@jsbsim.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 <iostream>
00042 #include <sstream>
00043 #include <iomanip>
00044 #include <cmath>
00045 
00046 using namespace std;
00047 
00048 namespace JSBSim {
00049 
00050 static const char *IdSrc = "$Id: FGColumnVector3.cpp,v 1.15 2012/02/07 00:27:51 jentron Exp $";
00051 static const char *IdHdr = ID_COLUMNVECTOR3;
00052 
00053 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00054 CLASS IMPLEMENTATION
00055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00056 
00057 FGColumnVector3::FGColumnVector3(void)
00058 {
00059   data[0] = data[1] = data[2] = 0.0;
00060   // Debug(0);
00061 }
00062 
00063 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00064 
00065 string FGColumnVector3::Dump(const string& delimiter) const
00066 {
00067   ostringstream buffer;
00068   buffer << std::setprecision(16) << data[0] << delimiter;
00069   buffer << std::setprecision(16) << data[1] << delimiter;
00070   buffer << std::setprecision(16) << data[2];
00071   return buffer.str();
00072 }
00073 
00074 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00075 
00076 ostream& operator<<(ostream& os, const FGColumnVector3& col)
00077 {
00078   os << col(1) << " , " << col(2) << " , " << col(3);
00079   return os;
00080 }
00081 
00082 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00083 
00084 FGColumnVector3 FGColumnVector3::operator/(const double scalar) const
00085 {
00086   if (scalar != 0.0)
00087     return operator*( 1.0/scalar );
00088 
00089   cerr << "Attempt to divide by zero in method \
00090     FGColumnVector3::operator/(const double scalar), \
00091     object " << data[0] << " , " << data[1] << " , " << data[2] << endl;
00092   return FGColumnVector3();
00093 }
00094 
00095 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00096 
00097 FGColumnVector3& FGColumnVector3::operator/=(const double scalar)
00098 {
00099   if (scalar != 0.0)
00100     operator*=( 1.0/scalar );
00101   else
00102     cerr << "Attempt to divide by zero in method \
00103       FGColumnVector3::operator/=(const double scalar), \
00104       object " << data[0] << " , " << data[1] << " , " << data[2] << endl;
00105 
00106   return *this;
00107 }
00108 
00109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00110 
00111 double FGColumnVector3::Magnitude(void) const
00112 {
00113   return sqrt( data[0]*data[0] +  data[1]*data[1] +  data[2]*data[2] );
00114 }
00115 
00116 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00117 
00118 FGColumnVector3& FGColumnVector3::Normalize(void)
00119 {
00120   double Mag = Magnitude();
00121 
00122   if (Mag != 0.0)
00123     operator*=( 1.0/Mag );
00124 
00125   return *this;
00126 }
00127 
00128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00129 
00130 double FGColumnVector3::Magnitude(const int idx1, const int idx2) const {
00131   return sqrt( data[idx1-1]*data[idx1-1] +  data[idx2-1]*data[idx2-1] );
00132 }
00133 
00134 
00135 } // namespace JSBSim