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 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/Plane3D.h (Version 11.3.0) and /externals/clhep/include/CLHEP/Geometry/Plane3D.h (Version 10.4.p3)


  1 // -*- C++ -*-                                      1 // -*- C++ -*-
                                                   >>   2 // $Id:$
  2 // -------------------------------------------      3 // ---------------------------------------------------------------------------
  3 //                                                  4 //
  4 // This file is a part of the CLHEP - a Class       5 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
  5 //                                                  6 //
  6 // History:                                         7 // History:
  7 // 22.09.96 E.Chernyaev - initial version           8 // 22.09.96 E.Chernyaev - initial version
  8 // 19.10.96 J.Allison - added == and <<.            9 // 19.10.96 J.Allison - added == and <<.
  9 // 15.04.03 E.Chernyaev - CLHEP-1.9: template      10 // 15.04.03 E.Chernyaev - CLHEP-1.9: template version
 10                                                    11 
 11 #ifndef HEP_PLANE3D_H                              12 #ifndef HEP_PLANE3D_H
 12 #define HEP_PLANE3D_H                              13 #define HEP_PLANE3D_H
 13                                                    14 
 14 #include <iosfwd>                                  15 #include <iosfwd>
 15 #include "CLHEP/Geometry/Point3D.h"                16 #include "CLHEP/Geometry/Point3D.h"
 16 #include "CLHEP/Geometry/Normal3D.h"               17 #include "CLHEP/Geometry/Normal3D.h"
 17 #include "CLHEP/Geometry/Transform3D.h"            18 #include "CLHEP/Geometry/Transform3D.h"
 18                                                    19 
 19 namespace HepGeom {                                20 namespace HepGeom {
 20                                                    21 
 21   /**                                              22   /**
 22    * Template class for geometrical plane in 3     23    * Template class for geometrical plane in 3D.
 23    *                                               24    *
 24    * @author Evgeni Chernyaev <Evgueni.Tcherni     25    * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
 25    * @ingroup geometry                             26    * @ingroup geometry
 26    */                                              27    */
 27   template<class T>                                28   template<class T>
 28   class Plane3D {                                  29   class Plane3D {
 29   protected:                                       30   protected:
 30     T a_, b_, c_, d_;                              31     T a_, b_, c_, d_;
 31                                                <<  32  
 32   public:                                          33   public:
 33     /**                                            34     /**
 34      *  Default constructor - creates plane z=     35      *  Default constructor - creates plane z=0. */
 35     Plane3D() : a_(0.), b_(0.), c_(1.), d_(0.)     36     Plane3D() : a_(0.), b_(0.), c_(1.), d_(0.) {}
 36                                                    37 
 37     /**                                            38     /**
 38      * Constructor from four numbers - creates     39      * Constructor from four numbers - creates plane a*x+b*y+c*z+d=0. */
 39     Plane3D(T a1, T b1, T c1, T d1) : a_(a1),      40     Plane3D(T a1, T b1, T c1, T d1) : a_(a1), b_(b1), c_(c1), d_(d1) {}
 40                                                    41 
 41     /**                                            42     /**
 42      * Constructor from normal and point. */       43      * Constructor from normal and point. */
 43     Plane3D(const Normal3D<T> & n, const Point     44     Plane3D(const Normal3D<T> & n, const Point3D<T> & p)
 44       : a_(n.x()), b_(n.y()), c_(n.z()), d_(-n     45       : a_(n.x()), b_(n.y()), c_(n.z()), d_(-n*p) {}
 45                                                    46 
 46     /**                                            47     /**
 47      * Constructor from three points. */           48      * Constructor from three points. */
 48     Plane3D(const Point3D<T> & p1,                 49     Plane3D(const Point3D<T> & p1,
 49       const Point3D<T> & p2,                       50       const Point3D<T> & p2,
 50       const Point3D<T> & p3) {                     51       const Point3D<T> & p3) {
 51       Normal3D<T> n = (p2-p1).cross(p3-p1);        52       Normal3D<T> n = (p2-p1).cross(p3-p1);
 52       a_ = n.x(); b_ = n.y(); c_ = n.z(); d_ =     53       a_ = n.x(); b_ = n.y(); c_ = n.z(); d_ = -n*p1;
 53     }                                              54     }
 54                                                    55 
 55     /**                                        <<  56     /** Copy constructor.
 56      * Copy constructor. */                    <<  57      * Plane3D<double> has two constructors:
 57     Plane3D(const Plane3D<T> &) = default;     <<  58      * from Plane3D<double> (provided by compiler) and
 58                                                <<  59      * from Plane3D<float> (defined in this file).
 59     /**                                        <<  60      * Plane3D<float> has only the last one.
 60      * Constructor for Plane3D<double> from Pl <<  61      */
 61     template<typename U = T,                   << 
 62              typename = typename std::enable_i << 
 63     Plane3D(const Plane3D<float> & p)              62     Plane3D(const Plane3D<float> & p)
 64       : a_(p.a_), b_(p.b_), c_(p.c_), d_(p.d_)     63       : a_(p.a_), b_(p.b_), c_(p.c_), d_(p.d_) {}
 65                                                    64 
 66     /**                                            65     /**
 67      * Move constructor. */                    << 
 68     Plane3D(Plane3D<T> &&) = default;          << 
 69                                                << 
 70     /**                                        << 
 71      * Destructor. */                              66      * Destructor. */
 72     ~Plane3D() = default;                      <<  67     ~Plane3D() {};
 73                                                    68 
 74     /**                                            69     /**
 75      * Assignment. */                              70      * Assignment. */
 76     Plane3D<T> & operator=(const Plane3D<T> &) <<  71     Plane3D<T> & operator=(const Plane3D<T> & p) {
 77                                                <<  72       a_ = p.a_; b_ = p.b_; c_ = p.c_; d_ = p.d_; return *this;
 78     /**                                        <<  73     }
 79      * Move assignment. */                     << 
 80     Plane3D<T> & operator=(Plane3D<T> &&) = de << 
 81                                                    74 
 82     /**                                            75     /**
 83      * Returns the a-coefficient in the plane      76      * Returns the a-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
 84     T a() const { return a_; }                     77     T a() const { return a_; }
 85     /**                                            78     /**
 86      * Returns the b-coefficient in the plane      79      * Returns the b-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
 87     T b() const { return b_; }                     80     T b() const { return b_; }
 88     /**                                            81     /**
 89      * Returns the c-coefficient in the plane      82      * Returns the c-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
 90     T c() const { return c_; }                     83     T c() const { return c_; }
 91     /**                                            84     /**
 92      * Returns the free member of the plane eq     85      * Returns the free member of the plane equation: a*x+b*y+c*z+d=0. */
 93     T d() const { return d_; }                     86     T d() const { return d_; }
 94                                                    87 
 95     /**                                            88     /**
 96      * Returns normal. */                          89      * Returns normal. */
 97     Normal3D<T> normal() const { return Normal     90     Normal3D<T> normal() const { return Normal3D<T>(a_,b_,c_); }
 98                                                    91 
 99     /**                                            92     /**
100      * Normalization. */                           93      * Normalization. */
101     Plane3D<T> & normalize() {                     94     Plane3D<T> & normalize() {
102       double ll = std::sqrt(a_*a_ + b_*b_ + c_     95       double ll = std::sqrt(a_*a_ + b_*b_ + c_*c_);
103       if (ll > 0.) { a_ /= ll; b_ /= ll; c_ /=     96       if (ll > 0.) { a_ /= ll; b_ /= ll; c_ /= ll, d_ /= ll; }
104       return *this;                                97       return *this;
105     }                                              98     }
106                                                    99 
107     /**                                           100     /**
108      * Returns distance to the point. */          101      * Returns distance to the point. */
109     T distance(const Point3D<T> & p) const {      102     T distance(const Point3D<T> & p) const {
110       return a()*p.x() + b()*p.y() + c()*p.z()    103       return a()*p.x() + b()*p.y() + c()*p.z() + d();
111     }                                             104     }
112                                                   105 
113     /**                                           106     /**
114      * Returns projection of the point to the     107      * Returns projection of the point to the plane. */
115     Point3D<T> point(const Point3D<T> & p) con    108     Point3D<T> point(const Point3D<T> & p) const {
116       T k = distance(p)/(a()*a()+b()*b()+c()*c    109       T k = distance(p)/(a()*a()+b()*b()+c()*c());
117       return Point3D<T>(p.x()-a()*k, p.y()-b()    110       return Point3D<T>(p.x()-a()*k, p.y()-b()*k, p.z()-c()*k);
118     }                                             111     }
119                                                   112 
120     /**                                           113     /**
121      * Returns projection of the origin to the    114      * Returns projection of the origin to the plane. */
122     Point3D<T> point() const {                    115     Point3D<T> point() const {
123       T k = -d()/(a()*a()+b()*b()+c()*c());       116       T k = -d()/(a()*a()+b()*b()+c()*c());
124       return Point3D<T>(a()*k, b()*k, c()*k);     117       return Point3D<T>(a()*k, b()*k, c()*k);
125     }                                             118     }
126                                                   119 
127     /**                                           120     /**
128      * Test for equality. */                      121      * Test for equality. */
129     bool operator == (const Plane3D<T> & p) co    122     bool operator == (const Plane3D<T> & p) const {
130       return a() == p.a() && b() == p.b() && c    123       return a() == p.a() && b() == p.b() && c() == p.c() && d() == p.d();
131     }                                             124     }
132                                                   125 
133     /**                                           126     /**
134      * Test for inequality. */                    127      * Test for inequality. */
135     bool operator != (const Plane3D<T> & p) co    128     bool operator != (const Plane3D<T> & p) const {
136       return a() != p.a() || b() != p.b() || c    129       return a() != p.a() || b() != p.b() || c() != p.c() || d() != p.d();
137     }                                             130     }
138                                                   131 
139     /**                                           132     /**
140      * Transformation by Transform3D. */          133      * Transformation by Transform3D. */
141     Plane3D<T> & transform(const Transform3D &    134     Plane3D<T> & transform(const Transform3D & m) {
142       Normal3D<T> n = normal();                   135       Normal3D<T> n = normal();
143       n.transform(m);                             136       n.transform(m);
144       d_ = -n*point().transform(m); a_ = n.x()    137       d_ = -n*point().transform(m); a_ = n.x(); b_ = n.y(); c_ = n.z();
145       return *this;                               138       return *this;
146     }                                             139     }
147   };                                              140   };
148                                                   141 
149   /**                                             142   /**
150    * Output to the stream.                        143    * Output to the stream.
151    * @relates Plane3D                             144    * @relates Plane3D
152    */                                             145    */
153   std::ostream & operator<<(std::ostream & os,    146   std::ostream & operator<<(std::ostream & os, const Plane3D<float> & p);
154                                                   147 
155   /**                                             148   /**
156    * Output to the stream.                        149    * Output to the stream.
157    * @relates Plane3D                             150    * @relates Plane3D
158    */                                             151    */
159   std::ostream & operator<<(std::ostream & os,    152   std::ostream & operator<<(std::ostream & os, const Plane3D<double> & p);
160                                                   153 
161 } /* namespace HepGeom */                         154 } /* namespace HepGeom */
162                                                   155 
163 #endif /* HEP_PLANE3D_H */                        156 #endif /* HEP_PLANE3D_H */
164                                                   157