File indexing completed on 2024-09-27 07:03:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
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