]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STARLIGHT/starlight/include/.svn/text-base/vector3.h.svn-base
STARLIGHT code and interface
[u/mrichter/AliRoot.git] / STARLIGHT / starlight / include / .svn / text-base / vector3.h.svn-base
CommitLineData
da32329d
AM
1///////////////////////////////////////////////////////////////////////////
2//
3// Copyright 2010
4//
5// This file is part of starlight.
6//
7// starlight is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// starlight is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with starlight. If not, see <http://www.gnu.org/licenses/>.
19//
20///////////////////////////////////////////////////////////////////////////
21//
22// File and Version Information:
23// $Rev:: $: revision of last commit
24// $Author:: $: author of last commit
25// $Date:: $: date of last commit
26//
27// Description:
28//
29//
30//
31///////////////////////////////////////////////////////////////////////////
32
33
34#ifndef VECTOR3_H
35#define VECTOR3_H
36
37
38#include <iostream>
39#include <cmath>
40
41
42class vector3
43{
44 public:
45 vector3();
46 vector3(double *vec);
47 vector3(double x, double y, double z);
48 virtual ~vector3();
49
50 const double* GetVector() const { return _vec; }
51
52 void SetVector(double x, double y, double z);
53 void SetVector(double *vec);
54
55 vector3& operator =(const vector3& vec)
56 {
57 if (this != &vec)
58 for (unsigned int i = 0; i < 3; ++i)
59 _vec[i] = vec._vec[i];
60 return *this;
61 }
62
63 vector3& operator +=(const vector3& vec)
64 {
65 for (unsigned int i = 0; i < 3; ++i)
66 _vec[i] += vec._vec[i];
67 return *this;
68 }
69 vector3& operator -=(const vector3& vec)
70 {
71 for (unsigned int i = 0; i < 3; ++i)
72 _vec[i] -= vec._vec[i];
73 return *this;
74 }
75
76 double X() const { return _vec[0]; }
77 double Y() const { return _vec[1]; }
78 double Z() const { return _vec[2]; }
79
80 double Mag2() const { return _vec[0] * _vec[0] + _vec[1] * _vec[1] + _vec[2] * _vec[2]; }
81 double Mag () const { return sqrt(Mag2()); }
82
83 friend std::ostream& operator << (std::ostream& out,
84 const vector3& vec)
85 {
86 out << "(" << vec.X() << ", " << vec.Y() << ", " << vec.Z() << ")";
87 return out;
88 }
89
90 private:
91
92 double _vec[3];
93
94};
95
96
97#endif // VECTOR3_H