1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGColumnVector3.cpp
4 Author: Originally by Tony Peden [formatted here by JSB]
6 Purpose: FGColumnVector3 class
9 ------------- Copyright (C) 1998 Tony Peden and Jon S. Berndt (jon@jsbsim.org) -
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
32 --------------------------------------------------------------------------------
34 03/16/2000 JSB Added exception throwing
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGColumnVector3.h"
50 static const char *IdSrc = "$Id: FGColumnVector3.cpp,v 1.14 2010/12/07 12:57:14 jberndt Exp $";
51 static const char *IdHdr = ID_COLUMNVECTOR3;
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 FGColumnVector3::FGColumnVector3(void)
59 data[0] = data[1] = data[2] = 0.0;
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 string FGColumnVector3::Dump(const string& delimiter) const
68 buffer << std::setw(18) << std::setprecision(16) << data[0] << delimiter;
69 buffer << std::setw(18) << std::setprecision(16) << data[1] << delimiter;
70 buffer << std::setw(18) << std::setprecision(16) << data[2];
74 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 ostream& operator<<(ostream& os, const FGColumnVector3& col)
78 os << col(1) << " , " << col(2) << " , " << col(3);
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 FGColumnVector3 FGColumnVector3::operator/(const double scalar) const
87 return operator*( 1.0/scalar );
89 cerr << "Attempt to divide by zero in method \
90 FGColumnVector3::operator/(const double scalar), \
91 object " << data[0] << " , " << data[1] << " , " << data[2] << endl;
92 return FGColumnVector3();
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 FGColumnVector3& FGColumnVector3::operator/=(const double scalar)
100 operator*=( 1.0/scalar );
102 cerr << "Attempt to divide by zero in method \
103 FGColumnVector3::operator/=(const double scalar), \
104 object " << data[0] << " , " << data[1] << " , " << data[2] << endl;
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 double FGColumnVector3::Magnitude(void) const
113 return sqrt( data[0]*data[0] + data[1]*data[1] + data[2]*data[2] );
116 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 FGColumnVector3& FGColumnVector3::Normalize(void)
120 double Mag = Magnitude();
123 operator*=( 1.0/Mag );
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 double FGColumnVector3::Magnitude(const int idx1, const int idx2) const {
131 return sqrt( data[idx1-1]*data[idx1-1] + data[idx2-1]*data[idx2-1] );
135 } // namespace JSBSim