CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
CircleFromThreePoints Class Reference

#include <CircleFromThreePoints.h>

Public Types

typedef Basic2DVector< float > Vector2D
 

Public Member Functions

Vector2D center () const
 
 CircleFromThreePoints ()
 dummy More...
 
 CircleFromThreePoints (const GlobalPoint &inner, const GlobalPoint &mid, const GlobalPoint &outer, double precision=1.e-7)
 
float curvature () const
 

Private Member Functions

void init (const Vector2D &b, const Vector2D &c, const Vector2D &offset, double precision)
 

Private Attributes

Vector2D theCenter
 
float theCurvature
 

Detailed Description

Computes the curvature (1/radius) and, if possible, the center of the circle passing through three points. The input points are three dimensional for convenience, but the calculation is done in the transverse (x,y) plane. No verification of the reasonableness of the z coordinate is done. If the three points lie on a line the curvature is zero and the center position is undefined. The 3 points are assumed to make sense: if the distance between two of them is very small compared to the ditance to the third the result will be numerically unstable.

Definition at line 18 of file CircleFromThreePoints.h.

Member Typedef Documentation

Definition at line 24 of file CircleFromThreePoints.h.

Constructor & Destructor Documentation

CircleFromThreePoints::CircleFromThreePoints ( )
inline

dummy

Definition at line 22 of file CircleFromThreePoints.h.

22 {}
CircleFromThreePoints::CircleFromThreePoints ( const GlobalPoint inner,
const GlobalPoint mid,
const GlobalPoint outer,
double  precision = 1.e-7 
)

Construct from three points (see class description). The order of points is not essential, but accuracy should be better if the second point lies between the other two on the circle. The optional argument "precision" specifies how accurately the straight line check has to be satisfied for setting the curvature to zero and the center position to "undefined".

Definition at line 3 of file CircleFromThreePoints.cc.

References b, EnergyCorrector::c, init(), PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

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 }
T y() const
Definition: PV3DBase.h:63
Basic2DVector< double >::MathVector Vector2D
Definition: LinkByRecHit.cc:7
void init(const Vector2D &b, const Vector2D &c, const Vector2D &offset, double precision)
double b
Definition: hdecay.h:120
Basic2DVector< float > Vector2D
T x() const
Definition: PV3DBase.h:62

Member Function Documentation

Vector2D CircleFromThreePoints::center ( ) const
inline

returns the position of the center of the circle. If curvature is zero, center() throws an exception to avoid use of undefined position. If the curvature is very small the position of the center will be very inaccurate.

Definition at line 52 of file CircleFromThreePoints.h.

References theCenter.

Referenced by ClusterShapeTrackFilter::getGlobalDirs(), PixelFitterByHelixProjections::run(), TrackFitter::run(), and KFBasedPixelFitter::run().

52 { return theCenter; }
float CircleFromThreePoints::curvature ( ) const
inline

Returns the curvature (1/radius), in cm^(-1). The curvature is precomputed, this is just access method (takes no time). If curvature is zero the center is undefined (see description of presicion above).

Definition at line 44 of file CircleFromThreePoints.h.

References theCurvature.

Referenced by ClusterShapeTrackFilter::getGlobalDirs(), PixelFitterByHelixProjections::run(), TrackFitter::run(), and KFBasedPixelFitter::run().

void CircleFromThreePoints::init ( const Vector2D b,
const Vector2D c,
const Vector2D offset,
double  precision 
)
private

Definition at line 14 of file CircleFromThreePoints.cc.

References relval_2017::k, Basic2DVector< T >::mag2(), mathSSE::sqrt(), theCenter, theCurvature, Basic2DVector< T >::x(), and Basic2DVector< T >::y().

Referenced by CircleFromThreePoints().

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 }
T sqrt(T t)
Definition: SSEVec.h:18
double b
Definition: hdecay.h:120
Basic2DVector< float > Vector2D

Member Data Documentation

Vector2D CircleFromThreePoints::theCenter
private

Definition at line 57 of file CircleFromThreePoints.h.

Referenced by center(), and init().

float CircleFromThreePoints::theCurvature
private

Definition at line 56 of file CircleFromThreePoints.h.

Referenced by curvature(), and init().