Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:16

0001 // Hep-LIKE geometrical 3D LINE class
0002 //
0003 //
0004 // Author: BKH
0005 //
0006 
0007 #ifndef HepLine3D_hh
0008 #define HepLine3D_hh
0009 
0010 #include "CLHEP/Geometry/Point3D.h"
0011 #include "CLHEP/Geometry/Normal3D.h"
0012 #include "CLHEP/Geometry/Plane3D.h"
0013 #include <iostream>
0014 
0015 class HepLine3D {
0016 protected:
0017   HepGeom::Point3D<double> pp;
0018   HepGeom::Vector3D<double> uu;
0019   double eps;
0020 
0021 public:
0022   HepLine3D(const HepGeom::Point3D<double>& p, const HepGeom::Vector3D<double>& v, double sml = 1.e-10)
0023       : pp(p), uu(v * (v.mag() > 1.e-10 ? 1. / v.mag() : 1)), eps(fabs(sml)) {}
0024 
0025   HepLine3D(const HepGeom::Point3D<double>& p1, const HepGeom::Point3D<double>& p2, double sml = 1.e-10)
0026       : pp(p1), uu((p2 - p1) * ((p2 - p1).mag() > 1.e-10 ? 1. / (p2 - p1).mag() : 1)), eps(fabs(sml)) {}
0027 
0028   // Copy constructor
0029   HepLine3D(const HepLine3D& line) : pp(line.pp), uu(line.uu), eps(line.eps) {}
0030 
0031   // Destructor
0032   ~HepLine3D(){};
0033 
0034   // Assignment
0035   HepLine3D& operator=(const HepLine3D& line) {
0036     pp = line.pp;
0037     uu = line.uu;
0038     eps = line.eps;
0039     return *this;
0040   }
0041 
0042   // Test for equality
0043   bool operator==(const HepLine3D& l) const { return pp == l.pp && uu == l.uu; }
0044 
0045   // Test for inequality
0046   bool operator!=(const HepLine3D& l) const { return pp != l.pp || uu != l.uu; }
0047 
0048   const HepGeom::Point3D<double>& pt() const { return pp; }
0049 
0050   const HepGeom::Vector3D<double>& uv() const { return uu; }
0051 
0052   HepGeom::Point3D<double> point(const HepGeom::Plane3D<double>& pl, bool& parallel) const {
0053     const double num(-pl.d() - pl.a() * pp.x() - pl.b() * pp.y() - pl.c() * pp.z());
0054     const double den(pl.a() * uu.x() + pl.b() * uu.y() + pl.c() * uu.z());
0055 
0056     parallel = (eps > fabs(num)) || (eps > fabs(den));
0057 
0058     return (parallel ? pp : HepGeom::Point3D<double>(pp + uu * (num / den)));
0059   }
0060 
0061   HepGeom::Point3D<double> point(const HepGeom::Point3D<double>& q) const {
0062     return (pp + ((q.x() - pp.x()) * uu.x() + (q.y() - pp.y()) * uu.y() + (q.z() - pp.z()) * uu.z()) * uu);
0063   }
0064 
0065   double dist2(const HepGeom::Point3D<double>& q) const { return (q - point(q)).mag2(); }
0066   double dist(const HepGeom::Point3D<double>& q) const { return (q - point(q)).mag(); }
0067 };
0068 
0069 #endif