00001
00002
00003
00004
00005
00006
00007
00008 #include "Line.hh"
00009
00010 Line::Line(const StThreeVectorD& o, const StThreeVectorD& d)
00011 {
00012 mOrigin = o;
00013 mDirection = d.unit();
00014 }
00015
00016 StThreeVectorD Line::at(double pathlength) const
00017 {
00018 return mOrigin + pathlength * mDirection;
00019 }
00020
00021 double Line::pathlength(const StThreeVectorD& point) const
00022 {
00023 return mDirection.dot(point - mOrigin);
00024 }
00025
00026 StThreeVectorD Line::perigee(const StThreeVectorD& point) const
00027 {
00028 return at(pathlength(point));
00029 }
00030
00031 StThreeVectorD Line::dca(const Line& line) const
00032 {
00033 double cosAngle = mDirection.dot(line.direction());
00034 double delta = cosAngle * cosAngle - 1;
00035 StThreeVectorD distance = mOrigin - line.origin();
00036 double pathlength = (distance.dot(mDirection) - cosAngle * distance.dot(line.direction())) / delta;
00037 double pathlength2 = (cosAngle * distance.dot(mDirection) - distance.dot(line.direction())) / delta;
00038 return at(pathlength) - line.at(pathlength2);
00039 }
00040
00041 pair<double, double> Line::pathlengths(const Line& line) const
00042 {
00043 double cosAngle = mDirection.dot(line.direction());
00044 double delta = cosAngle * cosAngle - 1;
00045 double s = pathlength(line.origin());
00046 double t = line.pathlength(mOrigin);
00047 return make_pair(-(s + t * cosAngle) / delta, -(s * cosAngle + t) / delta);
00048 }