CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Line3D.h
Go to the documentation of this file.
1 // Hep-LIKE geometrical 3D LINE class
2 //
3 //
4 // Author: BKH
5 //
6 
7 #ifndef HepLine3D_hh
8 #define HepLine3D_hh
9 
10 #include "CLHEP/Geometry/Point3D.h"
11 #include "CLHEP/Geometry/Normal3D.h"
12 #include "CLHEP/Geometry/Plane3D.h"
13 #include <iostream>
14 
15 
16 
17 
18 
19 
20 
21 class HepLine3D
22 {
23  protected:
24  HepGeom::Point3D<double> pp ;
25  HepGeom::Vector3D<double> uu ;
26  double eps ;
27 
28  public:
29 
30  HepLine3D( const HepGeom::Point3D<double> & p,
31  const HepGeom::Vector3D<double> & v,
32  double sml = 1.e-10 ) :
33  pp ( p ),
34  uu ( v*( v.mag()>1.e-10 ? 1./v.mag() : 1 ) ),
35  eps ( fabs( sml ) ) {}
36 
37  HepLine3D( const HepGeom::Point3D<double> & p1,
38  const HepGeom::Point3D<double> & p2,
39  double sml = 1.e-10 ) :
40  pp ( p1 ),
41  uu ( (p2-p1)*( (p2-p1).mag()>1.e-10 ? 1./(p2-p1).mag() : 1 ) ),
42  eps ( fabs( sml ) ) {}
43 
44  // Copy constructor
45  HepLine3D( const HepLine3D& line ) :
46  pp (line.pp), uu(line.uu), eps(line.eps) {}
47 
48  // Destructor
49  ~HepLine3D() {};
50 
51  // Assignment
53  {
54  pp = line.pp; uu = line.uu; eps = line.eps; return *this;
55  }
56 
57  // Test for equality
58  bool operator == (const HepLine3D& l) const
59  {
60  return pp == l.pp && uu == l.uu ;
61  }
62 
63  // Test for inequality
64  bool operator != (const HepLine3D& l) const
65  {
66  return pp != l.pp || uu != l.uu ;
67  }
68 
69  const HepGeom::Point3D<double> & pt() const { return pp ; }
70 
71  const HepGeom::Vector3D<double> & uv() const { return uu ; }
72 
73  HepGeom::Point3D<double> point( const HepGeom::Plane3D<double>& pl, bool& parallel ) const
74  {
75  const double num ( -pl.d() - pl.a()*pp.x() - pl.b()*pp.y() - pl.c()*pp.z() ) ;
76  const double den ( pl.a()*uu.x() + pl.b()*uu.y() + pl.c()*uu.z() ) ;
77 
78  parallel = ( eps > fabs( num ) ) || ( eps > fabs( den ) ) ;
79 
80  return ( parallel ? pp : HepGeom::Point3D<double> ( pp + uu*(num/den) ) ) ;
81  }
82 
83  HepGeom::Point3D<double> point( const HepGeom::Point3D<double> & q ) const
84  {
85  return ( pp + ( ( q.x() - pp.x() )*uu.x() +
86  ( q.y() - pp.y() )*uu.y() +
87  ( q.z() - pp.z() )*uu.z() )*uu ) ;
88  }
89 
90  double dist2( const HepGeom::Point3D<double> & q ) const { return ( q - point( q ) ).mag2() ; }
91  double dist( const HepGeom::Point3D<double> & q ) const { return ( q - point( q ) ).mag() ; }
92 };
93 
94 #endif
double dist2(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:90
HepLine3D & operator=(const HepLine3D &line)
Definition: Line3D.h:52
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
HepGeom::Point3D< double > pp
Definition: Line3D.h:24
HepLine3D(const HepGeom::Point3D< double > &p, const HepGeom::Vector3D< double > &v, double sml=1.e-10)
Definition: Line3D.h:30
const HepGeom::Vector3D< double > & uv() const
Definition: Line3D.h:71
bool operator==(const HepLine3D &l) const
Definition: Line3D.h:58
double eps
Definition: Line3D.h:26
double p2[4]
Definition: TauolaWrapper.h:90
double dist(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:91
HepLine3D(const HepGeom::Point3D< double > &p1, const HepGeom::Point3D< double > &p2, double sml=1.e-10)
Definition: Line3D.h:37
bool operator!=(const HepLine3D &l) const
Definition: Line3D.h:64
HepGeom::Vector3D< double > uu
Definition: Line3D.h:25
HepGeom::Point3D< double > point(const HepGeom::Plane3D< double > &pl, bool &parallel) const
Definition: Line3D.h:73
HepGeom::Point3D< double > point(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:83
~HepLine3D()
Definition: Line3D.h:49
double p1[4]
Definition: TauolaWrapper.h:89
const HepGeom::Point3D< double > & pt() const
Definition: Line3D.h:69
HepLine3D(const HepLine3D &line)
Definition: Line3D.h:45