Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/clhep/include/CLHEP/Geometry/BasicVector3D.h

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/clhep/include/CLHEP/Geometry/BasicVector3D.h (Version 11.3.0) and /externals/clhep/include/CLHEP/Geometry/BasicVector3D.h (Version 10.7.p4)


  1 // -*- C++ -*-                                      1 // -*- C++ -*-
  2 // -------------------------------------------      2 // ---------------------------------------------------------------------------
  3 //                                                  3 //
  4 // This file is a part of the CLHEP - a Class       4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
  5 //                                                  5 //
  6 // History:                                         6 // History:
  7 // 12.06.01 E.Chernyaev - CLHEP-1.7: initial        7 // 12.06.01 E.Chernyaev - CLHEP-1.7: initial  version
  8 // 14.03.03 E.Chernyaev - CLHEP-1.9: template       8 // 14.03.03 E.Chernyaev - CLHEP-1.9: template version
  9 //                                                  9 //
 10                                                    10 
 11 #ifndef BASIC_VECTOR3D_H                           11 #ifndef BASIC_VECTOR3D_H
 12 #define BASIC_VECTOR3D_H                           12 #define BASIC_VECTOR3D_H
 13                                                    13 
 14 #include <iosfwd>                                  14 #include <iosfwd>
 15 #include <type_traits>                             15 #include <type_traits>
 16 #include "CLHEP/Vector/ThreeVector.h"              16 #include "CLHEP/Vector/ThreeVector.h"
 17                                                    17 
 18 namespace HepGeom {                                18 namespace HepGeom {
 19   /**                                              19   /**
 20    * Base class for Point3D<T>, Vector3D<T> an     20    * Base class for Point3D<T>, Vector3D<T> and Normal3D<T>.
 21    * It defines only common functionality for      21    * It defines only common functionality for those classes and
 22    * should not be used as separate class.         22    * should not be used as separate class.
 23    *                                               23    *
 24    * @author Evgeni Chernyaev <Evgueni.Tcherni     24    * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
 25    * @ingroup geometry                             25    * @ingroup geometry
 26    */                                              26    */
 27   template<class T> class BasicVector3D {          27   template<class T> class BasicVector3D {
 28   protected:                                       28   protected:
 29     T v_[3];                                       29     T v_[3];
 30                                                    30 
 31     /**                                            31     /**
 32      * Default constructor.                        32      * Default constructor.
 33      * It is protected - this class should not     33      * It is protected - this class should not be instantiated directly.
 34      */                                            34      */
 35     BasicVector3D() { v_[0] = 0; v_[1] = 0; v_     35     BasicVector3D() { v_[0] = 0; v_[1] = 0; v_[2] = 0; }
 36                                                    36 
 37   public:                                          37   public:
 38     /**                                            38     /**
 39      * Safe indexing of the coordinates when u     39      * Safe indexing of the coordinates when using with matrices, arrays, etc.
 40      */                                            40      */
 41     enum {                                         41     enum {
 42       X = 0,                 /**< index for x-     42       X = 0,                 /**< index for x-component */
 43       Y = 1,                 /**< index for y-     43       Y = 1,                 /**< index for y-component */
 44       Z = 2,                 /**< index for z-     44       Z = 2,                 /**< index for z-component */
 45       NUM_COORDINATES = 3,   /**< number of co     45       NUM_COORDINATES = 3,   /**< number of components  */
 46       SIZE = NUM_COORDINATES /**< number of co     46       SIZE = NUM_COORDINATES /**< number of components  */
 47     };                                             47     };
 48                                                    48 
 49     /**                                            49     /**
 50      * Constructor from three numbers. */          50      * Constructor from three numbers. */
 51     BasicVector3D(T x1, T y1, T z1) { v_[0] =      51     BasicVector3D(T x1, T y1, T z1) { v_[0] = x1; v_[1] = y1; v_[2] = z1; }
 52                                                    52 
 53     /**                                            53     /**
 54      * Copy constructor. */                        54      * Copy constructor. */
 55     BasicVector3D(const BasicVector3D<T> &) =      55     BasicVector3D(const BasicVector3D<T> &) = default;
 56                                                    56 
 57     /**                                            57     /**
 58      * Constructor for BasicVector3D<double> f     58      * Constructor for BasicVector3D<double> from BasicVector3D<float>. */
 59     template<typename U = T,                       59     template<typename U = T,
 60              typename = typename std::enable_i     60              typename = typename std::enable_if<!std::is_same<U,float>::value >::type>
 61     BasicVector3D(const BasicVector3D<float> &     61     BasicVector3D(const BasicVector3D<float> & v) {
 62       v_[0] = v.x(); v_[1] = v.y(); v_[2] = v.     62       v_[0] = v.x(); v_[1] = v.y(); v_[2] = v.z();
 63     }                                              63     }
 64                                                    64 
 65     /**                                            65     /**
 66      * Move constructor. */                        66      * Move constructor. */
 67     BasicVector3D(BasicVector3D<T> &&) = defau     67     BasicVector3D(BasicVector3D<T> &&) = default;
 68                                                    68 
 69     /**                                            69     /**
 70      * Destructor. */                              70      * Destructor. */
 71     virtual ~BasicVector3D() = default;            71     virtual ~BasicVector3D() = default;
 72                                                    72 
 73     // -------------------------                   73     // -------------------------
 74     // Interface to "good old C"                   74     // Interface to "good old C"
 75     // -------------------------                   75     // -------------------------
 76                                                    76 
 77     /**                                            77     /**
 78      * Conversion (cast) to ordinary array. */     78      * Conversion (cast) to ordinary array. */
 79     operator T * () { return v_; }                 79     operator T * () { return v_; }
 80                                                    80 
 81     /**                                            81     /**
 82      * Conversion (cast) to ordinary const arr     82      * Conversion (cast) to ordinary const array. */
 83     operator const T * () const { return v_; }     83     operator const T * () const { return v_; }
 84                                                    84 
 85     /**                                            85     /**
 86      * Conversion (cast) to CLHEP::Hep3Vector.     86      * Conversion (cast) to CLHEP::Hep3Vector.
 87      * This operator is needed only for backwa     87      * This operator is needed only for backward compatibility and
 88      * in principle should not exit.               88      * in principle should not exit.
 89      */                                            89      */
 90     operator CLHEP::Hep3Vector () const { retu     90     operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }
 91                                                    91 
 92     // -----------------------------               92     // -----------------------------
 93     // General arithmetic operations               93     // General arithmetic operations
 94     // -----------------------------               94     // -----------------------------
 95                                                    95 
 96     /**                                            96     /**
 97      * Assignment. */                              97      * Assignment. */
 98     BasicVector3D<T> & operator= (const BasicV     98     BasicVector3D<T> & operator= (const BasicVector3D<T> &) = default;
 99     /**                                            99     /**
100      * Move assignment. */                        100      * Move assignment. */
101     BasicVector3D<T> & operator= (BasicVector3    101     BasicVector3D<T> & operator= (BasicVector3D<T> &&) = default;
102     /**                                           102     /**
103      * Addition. */                               103      * Addition. */
104     BasicVector3D<T> & operator+=(const BasicV    104     BasicVector3D<T> & operator+=(const BasicVector3D<T> & v) {
105       v_[0] += v.v_[0]; v_[1] += v.v_[1]; v_[2    105       v_[0] += v.v_[0]; v_[1] += v.v_[1]; v_[2] += v.v_[2]; return *this;
106     }                                             106     }
107     /**                                           107     /**
108      * Subtraction. */                            108      * Subtraction. */
109     BasicVector3D<T> & operator-=(const BasicV    109     BasicVector3D<T> & operator-=(const BasicVector3D<T> & v) {
110       v_[0] -= v.v_[0]; v_[1] -= v.v_[1]; v_[2    110       v_[0] -= v.v_[0]; v_[1] -= v.v_[1]; v_[2] -= v.v_[2]; return *this;
111     }                                             111     }
112     /**                                           112     /**
113      * Multiplication by scalar. */               113      * Multiplication by scalar. */
114     BasicVector3D<T> & operator*=(double a) {     114     BasicVector3D<T> & operator*=(double a) {
115       v_[0] *= a; v_[1] *= a; v_[2] *= a; retu    115       v_[0] *= a; v_[1] *= a; v_[2] *= a; return *this;
116     }                                             116     }
117     /**                                           117     /**
118      * Division by scalar. */                     118      * Division by scalar. */
119     BasicVector3D<T> & operator/=(double a) {     119     BasicVector3D<T> & operator/=(double a) {
120       v_[0] /= a; v_[1] /= a; v_[2] /= a; retu    120       v_[0] /= a; v_[1] /= a; v_[2] /= a; return *this;
121     }                                             121     }
122                                                   122 
123     // ------------                               123     // ------------
124     // Subscripting                               124     // Subscripting
125     // ------------                               125     // ------------
126                                                   126 
127     /**                                           127     /**
128      * Gets components by index. */               128      * Gets components by index. */
129     T operator()(int i) const { return v_[i];     129     T operator()(int i) const { return v_[i]; }
130     /**                                           130     /**
131      * Gets components by index. */               131      * Gets components by index. */
132     T operator[](int i) const { return v_[i];     132     T operator[](int i) const { return v_[i]; }
133                                                   133 
134     /**                                           134     /**
135      * Sets components by index. */               135      * Sets components by index. */
136     T & operator()(int i) { return v_[i]; }       136     T & operator()(int i) { return v_[i]; }
137     /**                                           137     /**
138      * Sets components by index. */               138      * Sets components by index. */
139     T & operator[](int i) { return v_[i]; }       139     T & operator[](int i) { return v_[i]; }
140                                                   140 
141     // ------------------------------------       141     // ------------------------------------
142     // Cartesian coordinate system: x, y, z       142     // Cartesian coordinate system: x, y, z
143     // ------------------------------------       143     // ------------------------------------
144                                                   144 
145     /**                                           145     /**
146      * Gets x-component in cartesian coordinat    146      * Gets x-component in cartesian coordinate system. */
147     T x() const { return v_[0]; }                 147     T x() const { return v_[0]; }
148     /**                                           148     /**
149      * Gets y-component in cartesian coordinat    149      * Gets y-component in cartesian coordinate system. */
150     T y() const { return v_[1]; }                 150     T y() const { return v_[1]; }
151     /**                                           151     /**
152      * Gets z-component in cartesian coordinat    152      * Gets z-component in cartesian coordinate system. */
153     T z() const { return v_[2]; }                 153     T z() const { return v_[2]; }
154                                                   154 
155     /**                                           155     /**
156      * Sets x-component in cartesian coordinat    156      * Sets x-component in cartesian coordinate system. */
157     void setX(T a) { v_[0] = a; }                 157     void setX(T a) { v_[0] = a; }
158     /**                                           158     /**
159      * Sets y-component in cartesian coordinat    159      * Sets y-component in cartesian coordinate system. */
160     void setY(T a) { v_[1] = a; }                 160     void setY(T a) { v_[1] = a; }
161     /**                                           161     /**
162      * Sets z-component in cartesian coordinat    162      * Sets z-component in cartesian coordinate system. */
163     void setZ(T a) { v_[2] = a; }                 163     void setZ(T a) { v_[2] = a; }
164                                                   164 
165     /**                                           165     /**
166      * Sets components in cartesian coordinate    166      * Sets components in cartesian coordinate system.  */
167     void set(T x1, T y1, T z1) { v_[0] = x1; v    167     void set(T x1, T y1, T z1) { v_[0] = x1; v_[1] = y1; v_[2] = z1; }
168                                                   168 
169     // ---------------------------------------    169     // ------------------------------------------
170     // Cylindrical coordinate system: rho, phi    170     // Cylindrical coordinate system: rho, phi, z
171     // ---------------------------------------    171     // ------------------------------------------
172                                                   172 
173     /**                                           173     /**
174      * Gets transverse component squared. */      174      * Gets transverse component squared. */
175     T perp2() const { return x()*x()+y()*y();     175     T perp2() const { return x()*x()+y()*y(); }
176     /**                                           176     /**
177      * Gets transverse component. */              177      * Gets transverse component. */
178     T perp() const { return std::sqrt(perp2())    178     T perp() const { return std::sqrt(perp2()); }
179     /**                                           179     /**
180      * Gets rho-component in cylindrical coord    180      * Gets rho-component in cylindrical coordinate system */
181     T rho() const { return perp(); }              181     T rho() const { return perp(); }
182                                                   182 
183     /**                                           183     /**
184      * Sets transverse component keeping phi a    184      * Sets transverse component keeping phi and z constant. */
185     void setPerp(T rh) {                          185     void setPerp(T rh) {
186       T factor = perp();                          186       T factor = perp();
187       if (factor > 0) {                           187       if (factor > 0) {
188   factor = rh/factor; v_[0] *= factor; v_[1] *    188   factor = rh/factor; v_[0] *= factor; v_[1] *= factor;
189       }                                           189       }
190     }                                             190     }
191                                                   191 
192     // ---------------------------------------    192     // ------------------------------------------
193     // Spherical coordinate system: r, phi, th    193     // Spherical coordinate system: r, phi, theta
194     // ---------------------------------------    194     // ------------------------------------------
195                                                   195 
196     /**                                           196     /**
197      * Gets magnitude squared of the vector. *    197      * Gets magnitude squared of the vector. */
198     T mag2() const { return x()*x()+y()*y()+z(    198     T mag2() const { return x()*x()+y()*y()+z()*z(); }
199     /**                                           199     /**
200      * Gets magnitude of the vector. */           200      * Gets magnitude of the vector. */
201     T mag() const { return std::sqrt(mag2());     201     T mag() const { return std::sqrt(mag2()); }
202     /**                                           202     /**
203      * Gets r-component in spherical coordinat    203      * Gets r-component in spherical coordinate system */
204     T r() const { return mag(); }                 204     T r() const { return mag(); }
205     /**                                           205     /**
206      * Gets azimuth angle. */                     206      * Gets azimuth angle. */
207     T phi() const {                               207     T phi() const {
208       return x() == 0 && y() == 0 ? 0 : std::a    208       return x() == 0 && y() == 0 ? 0 : std::atan2(y(),x());
209     }                                             209     }
210     /**                                           210     /**
211      * Gets polar angle. */                       211      * Gets polar angle. */
212     T theta() const {                             212     T theta() const {
213       return x() == 0 && y() == 0 && z() == 0     213       return x() == 0 && y() == 0 && z() == 0 ? 0 : std::atan2(perp(),z());
214     }                                             214     }
215     /**                                           215     /**
216      * Gets cosine of polar angle. */             216      * Gets cosine of polar angle. */
217     T cosTheta() const { T ma = mag(); return     217     T cosTheta() const { T ma = mag(); return ma == 0 ? 1 : z()/ma; }
218                                                   218 
219     /**                                           219     /**
220      * Gets r-component in spherical coordinat    220      * Gets r-component in spherical coordinate system */
221     T getR() const { return r(); }                221     T getR() const { return r(); }
222     /**                                           222     /**
223      * Gets phi-component in spherical coordin    223      * Gets phi-component in spherical coordinate system */
224     T getPhi() const { return phi(); }            224     T getPhi() const { return phi(); }
225     /**                                           225     /**
226      * Gets theta-component in spherical coord    226      * Gets theta-component in spherical coordinate system */
227     T getTheta() const { return theta(); }        227     T getTheta() const { return theta(); }
228                                                   228 
229     /**                                           229     /**
230      * Sets magnitude. */                         230      * Sets magnitude. */
231     void setMag(T ma) {                           231     void setMag(T ma) {
232       T factor = mag();                           232       T factor = mag();
233       if (factor > 0) {                           233       if (factor > 0) {
234   factor = ma/factor; v_[0] *= factor; v_[1] *    234   factor = ma/factor; v_[0] *= factor; v_[1] *= factor; v_[2] *= factor;
235       }                                           235       }
236     }                                             236     }
237     /**                                           237     /**
238      * Sets r-component in spherical coordinat    238      * Sets r-component in spherical coordinate system. */
239     void setR(T ma) { setMag(ma); }               239     void setR(T ma) { setMag(ma); }
240     /**                                           240     /**
241      * Sets phi-component in spherical coordin    241      * Sets phi-component in spherical coordinate system. */
242     void setPhi(T ph) { T xy = perp(); setX(xy    242     void setPhi(T ph) { T xy = perp(); setX(xy*std::cos(ph)); setY(xy*std::sin(ph)); }
243     /**                                           243     /**
244      * Sets theta-component in spherical coord    244      * Sets theta-component in spherical coordinate system. */
245     void setTheta(T th) {                         245     void setTheta(T th) {
246       T ma = mag();                               246       T ma = mag();
247       T ph = phi();                               247       T ph = phi();
248       set(ma*std::sin(th)*std::cos(ph), ma*std    248       set(ma*std::sin(th)*std::cos(ph), ma*std::sin(th)*std::sin(ph), ma*std::cos(th));
249     }                                             249     }
250                                                   250 
251     // ---------------                            251     // ---------------
252     // Pseudo rapidity                            252     // Pseudo rapidity
253     // ---------------                            253     // ---------------
254                                                   254 
255     /**                                           255     /**
256      * Gets pseudo-rapidity: -ln(tan(theta/2))    256      * Gets pseudo-rapidity: -ln(tan(theta/2)) */
257     T pseudoRapidity() const;                     257     T pseudoRapidity() const;
258     /**                                           258     /**
259      * Gets pseudo-rapidity. */                   259      * Gets pseudo-rapidity. */
260     T eta() const { return pseudoRapidity(); }    260     T eta() const { return pseudoRapidity(); }
261     /**                                           261     /**
262      * Gets pseudo-rapidity. */                   262      * Gets pseudo-rapidity. */
263     T getEta() const { return pseudoRapidity()    263     T getEta() const { return pseudoRapidity(); }
264                                                   264 
265     /**                                           265     /**
266      * Sets pseudo-rapidity, keeping magnitude    266      * Sets pseudo-rapidity, keeping magnitude and phi fixed. */
267     void setEta(T a);                             267     void setEta(T a);
268                                                   268 
269     // -------------------                        269     // -------------------
270     // Combine two vectors                        270     // Combine two vectors
271     // -------------------                        271     // -------------------
272                                                   272 
273     /**                                           273     /**
274      * Scalar product. */                         274      * Scalar product. */
275     T dot(const BasicVector3D<T> & v) const {     275     T dot(const BasicVector3D<T> & v) const {
276       return x()*v.x()+y()*v.y()+z()*v.z();       276       return x()*v.x()+y()*v.y()+z()*v.z();
277     }                                             277     }
278                                                   278 
279     /**                                           279     /**
280      * Vector product. */                         280      * Vector product. */
281     BasicVector3D<T> cross(const BasicVector3D    281     BasicVector3D<T> cross(const BasicVector3D<T> & v) const {
282       return BasicVector3D<T>(y()*v.z()-v.y()*    282       return BasicVector3D<T>(y()*v.z()-v.y()*z(),
283             z()*v.x()-v.z()*x(),                  283             z()*v.x()-v.z()*x(),
284             x()*v.y()-v.x()*y());                 284             x()*v.y()-v.x()*y());
285     }                                             285     }
286                                                   286 
287     /**                                           287     /**
288      * Returns transverse component w.r.t. giv    288      * Returns transverse component w.r.t. given axis squared. */
289     T perp2(const BasicVector3D<T> & v) const     289     T perp2(const BasicVector3D<T> & v) const {
290       T tot = v.mag2(), s = dot(v);               290       T tot = v.mag2(), s = dot(v);
291       return tot > 0 ? mag2()-s*s/tot : mag2()    291       return tot > 0 ? mag2()-s*s/tot : mag2();
292     }                                             292     }
293                                                   293 
294     /**                                           294     /**
295      * Returns transverse component w.r.t. giv    295      * Returns transverse component w.r.t. given axis. */
296     T perp(const BasicVector3D<T> & v) const {    296     T perp(const BasicVector3D<T> & v) const {
297       return std::sqrt(perp2(v));                 297       return std::sqrt(perp2(v));
298     }                                             298     }
299                                                   299 
300     /**                                           300     /**
301      * Returns angle w.r.t. another vector. */    301      * Returns angle w.r.t. another vector. */
302     T angle(const BasicVector3D<T> & v) const;    302     T angle(const BasicVector3D<T> & v) const;
303                                                   303 
304     // ---------------                            304     // ---------------
305     // Related vectors                            305     // Related vectors
306     // ---------------                            306     // ---------------
307                                                   307 
308     /**                                           308     /**
309      * Returns unit vector parallel to this. *    309      * Returns unit vector parallel to this. */
310     BasicVector3D<T> unit() const {               310     BasicVector3D<T> unit() const {
311       T len = mag();                              311       T len = mag();
312       return (len > 0) ?                          312       return (len > 0) ?
313   BasicVector3D<T>(x()/len, y()/len, z()/len)     313   BasicVector3D<T>(x()/len, y()/len, z()/len) : BasicVector3D<T>();
314     }                                             314     }
315                                                   315 
316     /**                                           316     /**
317      * Returns orthogonal vector. */              317      * Returns orthogonal vector. */
318     BasicVector3D<T> orthogonal() const {         318     BasicVector3D<T> orthogonal() const {
319       T dx = x() < 0 ? -x() : x();                319       T dx = x() < 0 ? -x() : x();
320       T dy = y() < 0 ? -y() : y();                320       T dy = y() < 0 ? -y() : y();
321       T dz = z() < 0 ? -z() : z();                321       T dz = z() < 0 ? -z() : z();
322       if (dx < dy) {                              322       if (dx < dy) {
323   return dx < dz ?                                323   return dx < dz ?
324     BasicVector3D<T>(0,z(),-y()) : BasicVector    324     BasicVector3D<T>(0,z(),-y()) : BasicVector3D<T>(y(),-x(),0);
325       }else{                                      325       }else{
326   return dy < dz ?                                326   return dy < dz ?
327     BasicVector3D<T>(-z(),0,x()) : BasicVector    327     BasicVector3D<T>(-z(),0,x()) : BasicVector3D<T>(y(),-x(),0);
328       }                                           328       }
329     }                                             329     }
330                                                   330 
331     // ---------                                  331     // ---------
332     // Rotations                                  332     // Rotations
333     // ---------                                  333     // ---------
334                                                   334 
335     /**                                           335     /**
336      * Rotates around x-axis. */                  336      * Rotates around x-axis. */
337     BasicVector3D<T> & rotateX(T a);              337     BasicVector3D<T> & rotateX(T a);
338     /**                                           338     /**
339      * Rotates around y-axis. */                  339      * Rotates around y-axis. */
340     BasicVector3D<T> & rotateY(T a);              340     BasicVector3D<T> & rotateY(T a);
341     /**                                           341     /**
342      * Rotates around z-axis. */                  342      * Rotates around z-axis. */
343     BasicVector3D<T> & rotateZ(T a);              343     BasicVector3D<T> & rotateZ(T a);
344     /**                                           344     /**
345      * Rotates around the axis specified by an    345      * Rotates around the axis specified by another vector. */
346     BasicVector3D<T> & rotate(T a, const Basic    346     BasicVector3D<T> & rotate(T a, const BasicVector3D<T> & v);
347   };                                              347   };
348                                                   348 
349   /*******************************************    349   /*************************************************************************
350    *                                              350    *                                                                       *
351    * Non-member functions for BasicVector3D<fl    351    * Non-member functions for BasicVector3D<float>                         *
352    *                                              352    *                                                                       *
353    *******************************************    353    *************************************************************************/
354                                                   354 
355   /**                                             355   /**
356    * Output to stream.                            356    * Output to stream.
357    * @relates BasicVector3D                       357    * @relates BasicVector3D
358    */                                             358    */
359   std::ostream &                                  359   std::ostream &
360   operator<<(std::ostream &, const BasicVector    360   operator<<(std::ostream &, const BasicVector3D<float> &);
361                                                   361 
362   /**                                             362   /**
363    * Input from stream.                           363    * Input from stream.
364    * @relates BasicVector3D                       364    * @relates BasicVector3D
365    */                                             365    */
366   std::istream &                                  366   std::istream &
367   operator>>(std::istream &, BasicVector3D<flo    367   operator>>(std::istream &, BasicVector3D<float> &);
368                                                   368 
369   /**                                             369   /**
370    * Unary plus.                                  370    * Unary plus.
371    * @relates BasicVector3D                       371    * @relates BasicVector3D
372    */                                             372    */
373   inline BasicVector3D<float>                     373   inline BasicVector3D<float>
374   operator+(const BasicVector3D<float> & v) {     374   operator+(const BasicVector3D<float> & v) { return v; }
375                                                   375 
376   /**                                             376   /**
377    * Addition of two vectors.                     377    * Addition of two vectors.
378    * @relates BasicVector3D                       378    * @relates BasicVector3D
379    */                                             379    */
380   inline BasicVector3D<float>                     380   inline BasicVector3D<float>
381   operator+(const BasicVector3D<float> & a, co    381   operator+(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
382     return BasicVector3D<float>(a.x()+b.x(), a    382     return BasicVector3D<float>(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
383   }                                               383   }
384                                                   384 
385   /**                                             385   /**
386    * Unary minus.                                 386    * Unary minus.
387    * @relates BasicVector3D                       387    * @relates BasicVector3D
388    */                                             388    */
389   inline BasicVector3D<float>                     389   inline BasicVector3D<float>
390   operator-(const BasicVector3D<float> & v) {     390   operator-(const BasicVector3D<float> & v) {
391     return BasicVector3D<float>(-v.x(), -v.y()    391     return BasicVector3D<float>(-v.x(), -v.y(), -v.z());
392   }                                               392   }
393                                                   393 
394   /**                                             394   /**
395    * Subtraction of two vectors.                  395    * Subtraction of two vectors.
396    * @relates BasicVector3D                       396    * @relates BasicVector3D
397    */                                             397    */
398   inline BasicVector3D<float>                     398   inline BasicVector3D<float>
399   operator-(const BasicVector3D<float> & a, co    399   operator-(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
400     return BasicVector3D<float>(a.x()-b.x(), a    400     return BasicVector3D<float>(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
401   }                                               401   }
402                                                   402 
403   /**                                             403   /**
404    * Multiplication vector by scalar.             404    * Multiplication vector by scalar.
405    * @relates BasicVector3D                       405    * @relates BasicVector3D
406    */                                             406    */
407   inline BasicVector3D<float>                     407   inline BasicVector3D<float>
408   operator*(const BasicVector3D<float> & v, do    408   operator*(const BasicVector3D<float> & v, double a) {
409     return BasicVector3D<float>(v.x()*static_c    409     return BasicVector3D<float>(v.x()*static_cast<float>(a), v.y()*static_cast<float>(a), v.z()*static_cast<float>(a));
410   }                                               410   }
411                                                   411 
412   /**                                             412   /**
413    * Scalar product of two vectors.               413    * Scalar product of two vectors.
414    * @relates BasicVector3D                       414    * @relates BasicVector3D
415    */                                             415    */
416   inline float                                    416   inline float
417   operator*(const BasicVector3D<float> & a, co    417   operator*(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
418     return a.dot(b);                              418     return a.dot(b);
419   }                                               419   }
420                                                   420 
421   /**                                             421   /**
422    * Multiplication scalar by vector.             422    * Multiplication scalar by vector.
423    * @relates BasicVector3D                       423    * @relates BasicVector3D
424    */                                             424    */
425   inline BasicVector3D<float>                     425   inline BasicVector3D<float>
426   operator*(double a, const BasicVector3D<floa    426   operator*(double a, const BasicVector3D<float> & v) {
427     return BasicVector3D<float>(static_cast<fl    427     return BasicVector3D<float>(static_cast<float>(a)*v.x(), static_cast<float>(a)*v.y(), static_cast<float>(a)*v.z());
428   }                                               428   }
429                                                   429 
430   /**                                             430   /**
431    * Division vector by scalar.                   431    * Division vector by scalar.
432    * @relates BasicVector3D                       432    * @relates BasicVector3D
433    */                                             433    */
434   inline BasicVector3D<float>                     434   inline BasicVector3D<float>
435   operator/(const BasicVector3D<float> & v, do    435   operator/(const BasicVector3D<float> & v, double a) {
436     return BasicVector3D<float>(v.x()/static_c    436     return BasicVector3D<float>(v.x()/static_cast<float>(a), v.y()/static_cast<float>(a), v.z()/static_cast<float>(a));
437   }                                               437   }
438                                                   438 
439   /**                                             439   /**
440    * Comparison of two vectors for equality.      440    * Comparison of two vectors for equality.
441    * @relates BasicVector3D                       441    * @relates BasicVector3D
442    */                                             442    */
443   inline bool                                     443   inline bool
444   operator==(const BasicVector3D<float> & a, c    444   operator==(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
445     return (a.x()==b.x() && a.y()==b.y() && a.    445     return (a.x()==b.x() && a.y()==b.y() && a.z()==b.z());
446   }                                               446   }
447                                                   447 
448   /**                                             448   /**
449    * Comparison of two vectors for inequality.    449    * Comparison of two vectors for inequality.
450    * @relates BasicVector3D                       450    * @relates BasicVector3D
451    */                                             451    */
452   inline bool                                     452   inline bool
453   operator!=(const BasicVector3D<float> & a, c    453   operator!=(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
454     return (a.x()!=b.x() || a.y()!=b.y() || a.    454     return (a.x()!=b.x() || a.y()!=b.y() || a.z()!=b.z());
455   }                                               455   }
456                                                   456 
457   /*******************************************    457   /*************************************************************************
458    *                                              458    *                                                                       *
459    * Non-member functions for BasicVector3D<do    459    * Non-member functions for BasicVector3D<double>                        *
460    *                                              460    *                                                                       *
461    *******************************************    461    *************************************************************************/
462                                                   462 
463   /**                                             463   /**
464    * Output to stream.                            464    * Output to stream.
465    * @relates BasicVector3D                       465    * @relates BasicVector3D
466    */                                             466    */
467   std::ostream &                                  467   std::ostream &
468   operator<<(std::ostream &, const BasicVector    468   operator<<(std::ostream &, const BasicVector3D<double> &);
469                                                   469 
470   /**                                             470   /**
471    * Input from stream.                           471    * Input from stream.
472    * @relates BasicVector3D                       472    * @relates BasicVector3D
473    */                                             473    */
474   std::istream &                                  474   std::istream &
475   operator>>(std::istream &, BasicVector3D<dou    475   operator>>(std::istream &, BasicVector3D<double> &);
476                                                   476 
477   /**                                             477   /**
478    * Unary plus.                                  478    * Unary plus.
479    * @relates BasicVector3D                       479    * @relates BasicVector3D
480    */                                             480    */
481   inline BasicVector3D<double>                    481   inline BasicVector3D<double>
482   operator+(const BasicVector3D<double> & v) {    482   operator+(const BasicVector3D<double> & v) { return v; }
483                                                   483 
484   /**                                             484   /**
485    * Addition of two vectors.                     485    * Addition of two vectors.
486    * @relates BasicVector3D                       486    * @relates BasicVector3D
487    */                                             487    */
488   inline BasicVector3D<double>                    488   inline BasicVector3D<double>
489   operator+(const BasicVector3D<double> & a,co    489   operator+(const BasicVector3D<double> & a,const BasicVector3D<double> & b) {
490     return BasicVector3D<double>(a.x()+b.x(),     490     return BasicVector3D<double>(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
491   }                                               491   }
492                                                   492 
493   /**                                             493   /**
494    * Unary minus.                                 494    * Unary minus.
495    * @relates BasicVector3D                       495    * @relates BasicVector3D
496    */                                             496    */
497   inline BasicVector3D<double>                    497   inline BasicVector3D<double>
498   operator-(const BasicVector3D<double> & v) {    498   operator-(const BasicVector3D<double> & v) {
499     return BasicVector3D<double>(-v.x(), -v.y(    499     return BasicVector3D<double>(-v.x(), -v.y(), -v.z());
500   }                                               500   }
501                                                   501 
502   /**                                             502   /**
503    * Subtraction of two vectors.                  503    * Subtraction of two vectors.
504    * @relates BasicVector3D                       504    * @relates BasicVector3D
505    */                                             505    */
506   inline BasicVector3D<double>                    506   inline BasicVector3D<double>
507   operator-(const BasicVector3D<double> & a,co    507   operator-(const BasicVector3D<double> & a,const BasicVector3D<double> & b) {
508     return BasicVector3D<double>(a.x()-b.x(),     508     return BasicVector3D<double>(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
509   }                                               509   }
510                                                   510 
511   /**                                             511   /**
512    * Multiplication vector by scalar.             512    * Multiplication vector by scalar.
513    * @relates BasicVector3D                       513    * @relates BasicVector3D
514    */                                             514    */
515   inline BasicVector3D<double>                    515   inline BasicVector3D<double>
516   operator*(const BasicVector3D<double> & v, d    516   operator*(const BasicVector3D<double> & v, double a) {
517     return BasicVector3D<double>(v.x()*a, v.y(    517     return BasicVector3D<double>(v.x()*a, v.y()*a, v.z()*a);
518   }                                               518   }
519                                                   519 
520   /**                                             520   /**
521    * Scalar product of two vectors.               521    * Scalar product of two vectors.
522    * @relates BasicVector3D                       522    * @relates BasicVector3D
523    */                                             523    */
524   inline double                                   524   inline double
525   operator*(const BasicVector3D<double> & a,co    525   operator*(const BasicVector3D<double> & a,const BasicVector3D<double> & b) {
526     return a.dot(b);                              526     return a.dot(b);
527   }                                               527   }
528                                                   528 
529   /**                                             529   /**
530    * Multiplication scalar by vector.             530    * Multiplication scalar by vector.
531    * @relates BasicVector3D                       531    * @relates BasicVector3D
532    */                                             532    */
533   inline BasicVector3D<double>                    533   inline BasicVector3D<double>
534   operator*(double a, const BasicVector3D<doub    534   operator*(double a, const BasicVector3D<double> & v) {
535     return BasicVector3D<double>(a*v.x(), a*v.    535     return BasicVector3D<double>(a*v.x(), a*v.y(), a*v.z());
536   }                                               536   }
537                                                   537 
538   /**                                             538   /**
539    * Division vector by scalar.                   539    * Division vector by scalar.
540    * @relates BasicVector3D                       540    * @relates BasicVector3D
541    */                                             541    */
542   inline BasicVector3D<double>                    542   inline BasicVector3D<double>
543   operator/(const BasicVector3D<double> & v, d    543   operator/(const BasicVector3D<double> & v, double a) {
544     return BasicVector3D<double>(v.x()/a, v.y(    544     return BasicVector3D<double>(v.x()/a, v.y()/a, v.z()/a);
545   }                                               545   }
546                                                   546 
547   /**                                             547   /**
548    * Comparison of two vectors for equality.      548    * Comparison of two vectors for equality.
549    * @relates BasicVector3D                       549    * @relates BasicVector3D
550    */                                             550    */
551   inline bool                                     551   inline bool
552   operator==(const BasicVector3D<double> & a,     552   operator==(const BasicVector3D<double> & a, const BasicVector3D<double> & b)
553   {                                               553   {
554     return (a.x()==b.x() && a.y()==b.y() && a.    554     return (a.x()==b.x() && a.y()==b.y() && a.z()==b.z());
555   }                                               555   }
556                                                   556 
557   /**                                             557   /**
558    * Comparison of two vectors for inequality.    558    * Comparison of two vectors for inequality.
559    * @relates BasicVector3D                       559    * @relates BasicVector3D
560    */                                             560    */
561   inline bool                                     561   inline bool
562   operator!=(const BasicVector3D<double> & a,     562   operator!=(const BasicVector3D<double> & a, const BasicVector3D<double> & b)
563   {                                               563   {
564     return (a.x()!=b.x() || a.y()!=b.y() || a.    564     return (a.x()!=b.x() || a.y()!=b.y() || a.z()!=b.z());
565   }                                               565   }
566 } /* namespace HepGeom */                         566 } /* namespace HepGeom */
567                                                   567 
568 #endif /* BASIC_VECTOR3D_H */                     568 #endif /* BASIC_VECTOR3D_H */
569                                                   569