Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef Geom_Line_H
0002 #define Geom_Line_H
0003 
0004 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0005 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0006 
0007 /** A line in 3D space.
0008  */
0009 
0010 class Line {
0011 public:
0012   typedef GlobalPoint PositionType;
0013   typedef GlobalVector DirectionType;
0014 
0015   Line() {}
0016 
0017   //Line( const PositionType& pos, const  DirectionType& dir) :
0018   Line(PositionType& pos, DirectionType& dir) : thePos(pos), theDir(dir.unit()) {}
0019 
0020   ~Line(){};
0021 
0022   //const PositionType& position()   const { return thePos;}
0023   //const DirectionType& direction() const { return theDir;}
0024   PositionType position() const { return thePos; }
0025   DirectionType direction() const { return theDir; }
0026 
0027   GlobalPoint closerPointToLine(const Line& aLine) const {
0028     GlobalPoint V = aLine.position();
0029     GlobalVector J = aLine.direction();
0030     GlobalVector Q = theDir - J.dot(theDir) * J;
0031     double lambda = Q.dot(V - thePos) / Q.dot(theDir);
0032     return thePos + lambda * theDir;
0033   }
0034 
0035   GlobalVector distance(const Line& aLine) const {
0036     GlobalPoint V = aLine.position();
0037     GlobalVector J = aLine.direction();
0038     GlobalVector P = (theDir.cross(J)).unit();
0039     GlobalVector D;
0040     D = P.dot(thePos - V) * P;
0041     return D;
0042   }
0043 
0044   GlobalVector distance(const GlobalPoint& aPoint) const {
0045     GlobalVector P(aPoint.x(), aPoint.y(), aPoint.z());
0046     GlobalVector T0(thePos.x(), thePos.y(), thePos.z());
0047     return T0 - P + theDir.dot(P - T0) * theDir;
0048   }
0049 
0050 private:
0051   PositionType thePos;
0052   DirectionType theDir;
0053 };
0054 
0055 #endif  // Geom_Line_H