CMS 3D CMS Logo

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 class HepLine3D {
16 protected:
17  HepGeom::Point3D<double> pp;
18  HepGeom::Vector3D<double> uu;
19  double eps;
20 
21 public:
22  HepLine3D(const HepGeom::Point3D<double>& p, const HepGeom::Vector3D<double>& v, double sml = 1.e-10)
23  : pp(p), uu(v * (v.mag() > 1.e-10 ? 1. / v.mag() : 1)), eps(fabs(sml)) {}
24 
25  HepLine3D(const HepGeom::Point3D<double>& p1, const HepGeom::Point3D<double>& p2, double sml = 1.e-10)
26  : pp(p1), uu((p2 - p1) * ((p2 - p1).mag() > 1.e-10 ? 1. / (p2 - p1).mag() : 1)), eps(fabs(sml)) {}
27 
28  // Copy constructor
30 
31  // Destructor
33 
34  // Assignment
36  pp = line.pp;
37  uu = line.uu;
38  eps = line.eps;
39  return *this;
40  }
41 
42  // Test for equality
43  bool operator==(const HepLine3D& l) const { return pp == l.pp && uu == l.uu; }
44 
45  // Test for inequality
46  bool operator!=(const HepLine3D& l) const { return pp != l.pp || uu != l.uu; }
47 
48  const HepGeom::Point3D<double>& pt() const { return pp; }
49 
50  const HepGeom::Vector3D<double>& uv() const { return uu; }
51 
52  HepGeom::Point3D<double> point(const HepGeom::Plane3D<double>& pl, bool& parallel) const {
53  const double num(-pl.d() - pl.a() * pp.x() - pl.b() * pp.y() - pl.c() * pp.z());
54  const double den(pl.a() * uu.x() + pl.b() * uu.y() + pl.c() * uu.z());
55 
56  parallel = (eps > fabs(num)) || (eps > fabs(den));
57 
58  return (parallel ? pp : HepGeom::Point3D<double>(pp + uu * (num / den)));
59  }
60 
61  HepGeom::Point3D<double> point(const HepGeom::Point3D<double>& q) const {
62  return (pp + ((q.x() - pp.x()) * uu.x() + (q.y() - pp.y()) * uu.y() + (q.z() - pp.z()) * uu.z()) * uu);
63  }
64 
65  double dist2(const HepGeom::Point3D<double>& q) const { return (q - point(q)).mag2(); }
66  double dist(const HepGeom::Point3D<double>& q) const { return (q - point(q)).mag(); }
67 };
68 
69 #endif
double dist(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:66
const HepGeom::Vector3D< double > & uv() const
Definition: Line3D.h:50
HepLine3D & operator=(const HepLine3D &line)
Definition: Line3D.h:35
HepGeom::Point3D< double > pp
Definition: Line3D.h:17
HepLine3D(const HepGeom::Point3D< double > &p, const HepGeom::Vector3D< double > &v, double sml=1.e-10)
Definition: Line3D.h:22
const HepGeom::Point3D< double > & pt() const
Definition: Line3D.h:48
double dist2(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:65
bool operator!=(const HepLine3D &l) const
Definition: Line3D.h:46
HepGeom::Point3D< double > point(const HepGeom::Plane3D< double > &pl, bool &parallel) const
Definition: Line3D.h:52
HepGeom::Point3D< double > point(const HepGeom::Point3D< double > &q) const
Definition: Line3D.h:61
double eps
Definition: Line3D.h:19
HepLine3D(const HepGeom::Point3D< double > &p1, const HepGeom::Point3D< double > &p2, double sml=1.e-10)
Definition: Line3D.h:25
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
HepGeom::Vector3D< double > uu
Definition: Line3D.h:18
~HepLine3D()
Definition: Line3D.h:32
HepLine3D(const HepLine3D &line)
Definition: Line3D.h:29
bool operator==(const HepLine3D &l) const
Definition: Line3D.h:43