Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-17 07:07:00

0001 ///////////////////////////////////////////////////////////////////////////
0002 //
0003 //    Copyright 2010
0004 //
0005 //    This file is part of starlight.
0006 //
0007 //    starlight is free software: you can redistribute it and/or modify
0008 //    it under the terms of the GNU General Public License as published by
0009 //    the Free Software Foundation, either version 3 of the License, or
0010 //    (at your option) any later version.
0011 //
0012 //    starlight is distributed in the hope that it will be useful,
0013 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015 //    GNU General Public License for more details.
0016 //
0017 //    You should have received a copy of the GNU General Public License
0018 //    along with starlight. If not, see <http://www.gnu.org/licenses/>.
0019 //
0020 ///////////////////////////////////////////////////////////////////////////
0021 //
0022 // File and Version Information:
0023 // $Rev:: 28                          $: revision of last commit
0024 // $Author:: bgrube                   $: author of last commit
0025 // $Date:: 2010-12-10 18:30:01 +0000 #$: date of last commit
0026 //
0027 // Description:
0028 //
0029 //
0030 //
0031 ///////////////////////////////////////////////////////////////////////////
0032 
0033 
0034 #ifndef VECTOR3_H
0035 #define VECTOR3_H
0036 
0037 
0038 #include <iostream>
0039 #include <cmath>
0040 
0041 
0042 class vector3
0043 {
0044    public:
0045       vector3();
0046       vector3(const vector3&) = default;
0047       vector3(double *vec);
0048       vector3(double x, double y, double z);
0049       virtual ~vector3();
0050       
0051       const double* GetVector() const { return _vec; }
0052       
0053       void SetVector(double x, double y, double z);
0054       void SetVector(double *vec);
0055 
0056         vector3& operator =(const vector3& vec)
0057         {
0058             if (this != &vec)
0059                 for (unsigned int i = 0; i < 3; ++i)
0060                     _vec[i] = vec._vec[i];
0061             return *this;
0062         }
0063 
0064         vector3& operator +=(const vector3& vec)
0065         {
0066             for (unsigned int i = 0; i < 3; ++i)
0067                 _vec[i] += vec._vec[i];
0068             return *this;
0069         }
0070         vector3& operator -=(const vector3& vec)
0071         {
0072             for (unsigned int i = 0; i < 3; ++i)
0073                 _vec[i] -= vec._vec[i];
0074             return *this;
0075         }
0076 
0077         double X() const { return _vec[0]; }
0078         double Y() const { return _vec[1]; }
0079         double Z() const { return _vec[2]; }
0080 
0081         double Mag2() const { return _vec[0] * _vec[0] + _vec[1] * _vec[1] + _vec[2] * _vec[2]; }
0082         double Mag () const { return sqrt(Mag2()); }
0083       
0084         friend std::ostream& operator << (std::ostream&  out,
0085                                           const vector3& vec)
0086         {
0087             out << "(" << vec.X() << ", " << vec.Y() << ", " << vec.Z() << ")";
0088             return out;
0089         }
0090     
0091    private:
0092       
0093       double _vec[3];
0094    
0095 };
0096 
0097 
0098 #endif  // VECTOR3_H