CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CircleFromThreePoints.cc
Go to the documentation of this file.
2 
4  const GlobalPoint& mid,
5  const GlobalPoint& outer,
6  double precision)
7 {
8  // move to frame where inner.x() == inner.y() == 0;
9  Vector2D b( mid.x()-inner.x(), mid.y()-inner.y());
10  Vector2D c( outer.x()-inner.x(), outer.y()-inner.y());
11  init( b, c, Vector2D( inner.x(), inner.y()), precision);
12 }
13 
15  const Vector2D& offset, double precision)
16 {
17  double b2 = b.mag2();
18  double c2 = c.mag2();
19 
20  double oX(0), oY(0);
21  bool solved = false;
22  if (fabs(b.x()) > fabs(b.y())) { // solve for y first
23  double k = c.x()/b.x();
24  double div = 2*(k*b.y() - c.y());
25  if (fabs(div) < precision) theCurvature = 0; // if the 3 points lie on a line
26  else {
27  oY = (k*b2 - c2) / div;
28  oX = b2/(2*b.x()) - b.y()/b.x() * oY;
29  solved = true;
30  }
31  }
32  else { // solve for x first
33  double k = c.y()/b.y();
34  double div = 2*(k*b.x()-c.x());
35  if (fabs(div) < precision) theCurvature = 0; // if the 3 points lie on a line
36  else {
37  oX = (k*b2 - c2) / div;
38  oY = b2/(2*b.y()) - b.x()/b.y() * oX;
39  solved = true;
40  }
41  }
42  if (solved) {
43  theCurvature = 1./sqrt(oX*oX + oY*oY);
44  double xC = oX + offset.x();
45  double yC = oY + offset.y();
46  theCenter = Vector2D( xC, yC);
47  // thePhi = acos(xC/sqrt(xC*xC + yC*yC));
48 
49  // if (xC<0.) thePhi = thePhi - PI;
50  // cout << setiosflags(ios::showpoint | ios::fixed);
51  //
52  // cout << "CircleFromThreePoints::init curv = " << theCurvature << endl;
53  // cout << "CircleFromThreePoints::init center prime = " << oX << " " << oY << endl;
54  // cout << "CircleFromThreePoints::init offset = " << offset.x() << " " << offset.y() << endl;
55  // cout << "CircleFromThreePoints::init center = " << theCenter.x()<< " " << theCenter.y() << endl;
56  //
57  // float d = sqrt(theCenter.x()*theCenter.x()+theCenter.y()*theCenter.y());
58  // cout << "CircleFromThreePoints::init dfloat = " << setw(10) << setprecision(5) << d << endl;
59  // cout << "CircleFromThreePoints::init radius = " << 1/theCurvature << endl;
60  }
61 }
62 
T y() const
Definition: PV3DBase.h:62
T sqrt(T t)
Definition: SSEVec.h:46
unsigned int offset(bool)
T y() const
Cartesian y coordinate.
int k[5][pyjets_maxn]
void init(const Vector2D &b, const Vector2D &c, const Vector2D &offset, double precision)
double b
Definition: hdecay.h:120
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Basic2DVector< float > Vector2D
T x() const
Definition: PV3DBase.h:61
T x() const
Cartesian x coordinate.