CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Geometry/CaloGeometry/interface/Line3D.h

Go to the documentation of this file.
00001 // Hep-LIKE geometrical 3D LINE class
00002 //
00003 //
00004 // Author: BKH
00005 //
00006 
00007 #ifndef HepLine3D_hh
00008 #define HepLine3D_hh
00009 
00010 #include "CLHEP/Geometry/Point3D.h"
00011 #include "CLHEP/Geometry/Normal3D.h"
00012 #include "CLHEP/Geometry/Plane3D.h"
00013 #include <iostream>
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 class HepLine3D 
00022 {
00023    protected:
00024       HepGeom::Point3D<double>   pp ;
00025       HepGeom::Vector3D<double>  uu ;
00026       double   eps ;
00027 
00028    public:
00029 
00030       HepLine3D( const HepGeom::Point3D<double> &  p, 
00031                  const HepGeom::Vector3D<double> & v,
00032                  double          sml = 1.e-10 ) :
00033          pp  ( p ), 
00034          uu  ( v*( v.mag()>1.e-10 ? 1./v.mag() : 1 ) ), 
00035          eps ( fabs( sml ) ) {} 
00036 
00037       HepLine3D( const HepGeom::Point3D<double> & p1, 
00038                  const HepGeom::Point3D<double> & p2, 
00039                  double         sml = 1.e-10 ) :
00040          pp  ( p1 ), 
00041          uu  ( (p2-p1)*( (p2-p1).mag()>1.e-10 ? 1./(p2-p1).mag() : 1 ) ),
00042          eps ( fabs( sml ) ) {} 
00043 
00044       // Copy constructor
00045       HepLine3D( const HepLine3D& line ) :
00046          pp (line.pp), uu(line.uu), eps(line.eps) {}
00047       
00048       // Destructor
00049       ~HepLine3D() {};
00050       
00051       // Assignment
00052       HepLine3D& operator=(const HepLine3D& line) 
00053       {
00054          pp = line.pp; uu = line.uu; eps = line.eps; return *this;
00055       }
00056 
00057       // Test for equality
00058       bool operator == (const HepLine3D& l) const 
00059       {
00060          return pp == l.pp && uu == l.uu ;
00061       }
00062 
00063       // Test for inequality
00064       bool operator != (const HepLine3D& l) const 
00065       {
00066          return pp != l.pp || uu != l.uu ;
00067       }
00068 
00069       const HepGeom::Point3D<double> &  pt() const { return pp ; }
00070 
00071       const HepGeom::Vector3D<double> & uv() const { return uu ; }
00072 
00073       HepGeom::Point3D<double>  point( const HepGeom::Plane3D<double>& pl, bool& parallel ) const
00074       {
00075          const double num ( -pl.d() - pl.a()*pp.x() - pl.b()*pp.y() - pl.c()*pp.z() ) ;
00076          const double den (           pl.a()*uu.x() + pl.b()*uu.y() + pl.c()*uu.z() ) ;
00077 
00078          parallel = ( eps > fabs( num ) ) || ( eps > fabs( den ) ) ;
00079 
00080          return ( parallel ? pp : HepGeom::Point3D<double> ( pp + uu*(num/den) ) ) ;
00081       }
00082 
00083       HepGeom::Point3D<double>  point( const HepGeom::Point3D<double> & q ) const
00084       {
00085          return ( pp + ( ( q.x() - pp.x() )*uu.x() +
00086                          ( q.y() - pp.y() )*uu.y() +
00087                          ( q.z() - pp.z() )*uu.z() )*uu ) ; 
00088       }
00089 
00090       double dist2( const HepGeom::Point3D<double> & q ) const { return ( q - point( q ) ).mag2() ; }
00091       double dist( const HepGeom::Point3D<double> & q ) const { return ( q - point( q ) ).mag() ; }
00092 };
00093 
00094 #endif