Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/lina/line is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_line
0005 #define tools_line
0006 
0007 namespace tools {
0008 
0009 // Parametric description:
0010 //  l(t) = pos + t * dir
0011 
0012 template <class VEC3>
0013 class line {
0014 protected:
0015   typedef typename VEC3::elem_t T;
0016 public:
0017   line(){}
0018   line(const VEC3& a_p0,const VEC3& a_p1) {
0019     // Construct a line from two points lying on the line.  If you
0020     // want to construct a line from a position and a direction, use
0021     // line(p, p + d).
0022     // line is directed from p0 to p1.
0023     m_pos = a_p0;
0024     m_dir = a_p0;
0025     m_dir.multiply(-1);
0026     m_dir.add(a_p1);
0027     m_dir.normalize();
0028   }
0029   line(const T& a_0_x,const T& a_0_y,const T& a_0_z,
0030        const T& a_1_x,const T& a_1_y,const T& a_1_z) {
0031     m_pos.set_value(a_0_x,a_0_y,a_0_z);
0032     m_dir.set_value(a_1_x-a_0_x,a_1_y-a_0_y,a_1_z-a_0_z);
0033     m_dir.normalize();
0034   }
0035   virtual ~line() {}
0036 public:
0037   line(const line& a_from)
0038   :m_pos(a_from.m_pos)
0039   ,m_dir(a_from.m_dir)
0040   {}
0041   line& operator=(const line& a_from) {
0042     m_pos = a_from.m_pos;
0043     m_dir = a_from.m_dir;
0044     return *this;
0045   }
0046 public:
0047   void set_value(const VEC3& a_p0,const VEC3& a_p1) {
0048     m_pos = a_p0;
0049     m_dir = a_p0;
0050     m_dir.multiply(-1);
0051     m_dir.add(a_p1);
0052     m_dir.normalize();
0053   }
0054   void set_value(const T& a_0_x,const T& a_0_y,const T& a_0_z,
0055                  const T& a_1_x,const T& a_1_y,const T& a_1_z) {
0056     m_pos.set_value(a_0_x,a_0_y,a_0_z);
0057     m_dir.set_value(a_1_x-a_0_x,a_1_y-a_0_y,a_1_z-a_0_z);
0058     m_dir.normalize();
0059   }
0060 
0061   const VEC3& position() const {return m_pos;}
0062   const VEC3& direction() const {return m_dir;}
0063 
0064 protected:
0065   VEC3 m_pos;
0066   VEC3 m_dir; //normalized.
0067 };
0068 
0069 }
0070 
0071 #endif