CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/RecoPixelVertexing/PixelTrackFitting/src/CircleFromThreePoints.cc

Go to the documentation of this file.
00001 #include "CircleFromThreePoints.h"
00002 
00003 CircleFromThreePoints::CircleFromThreePoints( const GlobalPoint& inner,
00004                                     const GlobalPoint& mid,
00005                                     const GlobalPoint& outer,
00006                                     double precision)
00007 {
00008   // move to frame where inner.x() == inner.y() == 0;
00009   Vector2D b( mid.x()-inner.x(), mid.y()-inner.y());
00010   Vector2D c( outer.x()-inner.x(), outer.y()-inner.y());
00011   init( b, c, Vector2D( inner.x(), inner.y()), precision);
00012 }
00013 
00014 void CircleFromThreePoints::init( const Vector2D& b, const Vector2D& c,
00015                           const Vector2D& offset, double precision)
00016 {
00017   double b2 = b.mag2();
00018   double c2 = c.mag2();
00019 
00020   double oX(0), oY(0);
00021   bool solved = false;
00022   if (fabs(b.x()) > fabs(b.y())) {    // solve for y first
00023     double k = c.x()/b.x();
00024     double div = 2*(k*b.y() - c.y());
00025     if (fabs(div) < precision) theCurvature = 0;  // if the 3 points lie on a line
00026     else {
00027       oY = (k*b2 - c2) / div;
00028       oX = b2/(2*b.x()) - b.y()/b.x() * oY;
00029       solved = true;
00030     }
00031   }
00032   else {    // solve for x first
00033     double k = c.y()/b.y();
00034     double div = 2*(k*b.x()-c.x());
00035     if (fabs(div) < precision) theCurvature = 0;  // if the 3 points lie on a line
00036     else {
00037       oX = (k*b2 - c2) / div;
00038       oY = b2/(2*b.y()) - b.x()/b.y() * oX;
00039       solved = true;
00040     }
00041   }
00042   if (solved) {
00043     theCurvature = 1./sqrt(oX*oX + oY*oY);
00044     double xC = oX + offset.x();
00045     double yC = oY + offset.y();
00046     theCenter = Vector2D( xC, yC);
00047     //    thePhi = acos(xC/sqrt(xC*xC + yC*yC));
00048 
00049     //    if (xC<0.) thePhi = thePhi - PI;
00050     //    cout << setiosflags(ios::showpoint | ios::fixed);
00051     //
00052     //    cout << "CircleFromThreePoints::init curv = " << theCurvature << endl;
00053     //    cout << "CircleFromThreePoints::init center prime = " << oX << " " << oY << endl;
00054     //    cout << "CircleFromThreePoints::init offset = " << offset.x() << " " << offset.y() << endl;
00055     //    cout << "CircleFromThreePoints::init center = " << theCenter.x()<< " " << theCenter.y() << endl;
00056     //
00057     //    float d = sqrt(theCenter.x()*theCenter.x()+theCenter.y()*theCenter.y());
00058     //    cout << "CircleFromThreePoints::init dfloat = " << setw(10) << setprecision(5) << d << endl;
00059     //    cout << "CircleFromThreePoints::init radius = " << 1/theCurvature << endl;
00060   }
00061 }
00062