TLine2D Class Reference

A class to represent a line in 2D. More...

#include <TLine2D.h>

List of all members.

Public Member Functions

 TLine2D ()
 Constructors.
 TLine2D (double slope, double yOffset)
 TLine2D (const AList< TPoint2D > &)
virtual ~TLine2D ()
 Destructor.
double slope (void) const
double yOffset (void) const
double xOffset (void) const
double slope (double)
double yOffset (double)
int fit (void)
double det (void) const
double distance (const TPoint2D &) const
void append (const TPoint2D &)
void remove (const TPoint2D &)
const CAList< TPoint2D > & list (void) const

Private Attributes

double _slope
double _yOffset
double _det
CAList< TPoint2D > * _list


Detailed Description

A class to represent a line in 2D.

Definition at line 25 of file TLine2D.h.


Constructor & Destructor Documentation

TLine2D::TLine2D (  ) 

Constructors.

Definition at line 31 of file TLine2D.cxx.

00031                  : _slope(1), _yOffset(0), _det(0), _list(0) {
00032 }

TLine2D::TLine2D ( double  slope,
double  yOffset 
)

Definition at line 34 of file TLine2D.cxx.

00035 : _slope(a),
00036   _yOffset(b),
00037   _det(0),
00038   _list(0) {
00039 }

TLine2D::TLine2D ( const AList< TPoint2D > &   ) 

Definition at line 41 of file TLine2D.cxx.

References _list.

00041                                           : _slope(1), _yOffset(0), _det(0) {
00042     _list = new CAList<TPoint2D>();
00043     _list->append(a);
00044 }

TLine2D::~TLine2D (  )  [virtual]

Destructor.

Definition at line 46 of file TLine2D.cxx.

References _list.

00046                   {
00047     if (_list) delete _list;
00048 }


Member Function Documentation

void TLine2D::append ( const TPoint2D  ) 

Definition at line 51 of file TLine2D.cxx.

References _list.

00051                                   {
00052     if (! _list)
00053         _list = new CAList<TPoint2D>();
00054     _list->append(a);
00055 }

double TLine2D::det ( void   )  const

double TLine2D::distance ( const TPoint2D  )  const

Definition at line 112 of file TLine2D.cxx.

References _slope, _yOffset, TPoint2D::x(), and TPoint2D::y().

00112                                           {
00113     double ydif = p.y() - _yOffset;
00114     double vmag = sqrt(1. + _slope * _slope);
00115     double dot = (p.x() + ydif * _slope) / vmag;
00116     double xmag2 = p.x() * p.x() + ydif * ydif;
00117     return sqrt(xmag2 - dot * dot);
00118 }

int TLine2D::fit ( void   ) 

Definition at line 71 of file TLine2D.cxx.

References _det, _list, _slope, _yOffset, genRecEmupikp::i, and x.

00071                  {
00072     if (! _list) return -1;
00073 
00074     unsigned n = _list->length();
00075     if (! n) return -1;
00076 
00077     if (n == 2) {
00078         double x0 = (* _list)[0]->x();
00079         double y0 = (* _list)[0]->y();
00080         double x1 = (* _list)[1]->x();
00081         double y1 = (* _list)[1]->y();
00082         if (x0 == x1) return -2;
00083         _slope = (y0 - y1) / (x0 - x1);
00084         _yOffset = - _slope * x1 + y1;
00085         
00086         return 0;
00087     }
00088 
00089     double sum = double(n);
00090     double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
00091     for (unsigned i = 0; i < n; i++) {
00092         const TPoint2D & p = * (* _list)[i];
00093         double x = p.x();
00094         double y = p.y();
00095         sumX  += x;
00096         sumY  += y;
00097         sumX2 += x * x;
00098         sumXY += x * y;
00099         sumY2 += y * y;
00100     }
00101 
00102     _det = sum * sumX2 - sumX * sumX;
00103     if (_det == 0.) return -3;
00104 
00105     _slope = (sumXY * sum - sumX * sumY) / _det;
00106     _yOffset = (sumX2 * sumY - sumX * sumXY) / _det;    
00107 
00108     return 0;
00109 }

const CAList< TPoint2D > & TLine2D::list ( void   )  const

Definition at line 64 of file TLine2D.cxx.

References _list.

00064                         {
00065     if (! _list)
00066         _list = new CAList<TPoint2D>();
00067     return * _list;
00068 }

void TLine2D::remove ( const TPoint2D  ) 

Definition at line 58 of file TLine2D.cxx.

References _list.

00058                                   {
00059     if (! _list) return;
00060     _list->remove(a);
00061 }

double TLine2D::slope ( double   )  [inline]

Definition at line 94 of file TLine2D.h.

References _slope.

00094                        {
00095     return _slope = a;
00096 }

double TLine2D::slope ( void   )  const [inline]

Definition at line 76 of file TLine2D.h.

References _slope.

00076                          {
00077     return _slope;
00078 }

double TLine2D::xOffset ( void   )  const [inline]

Definition at line 88 of file TLine2D.h.

References _slope, and _yOffset.

00088                            {
00089     return - _yOffset / _slope;
00090 }

double TLine2D::yOffset ( double   )  [inline]

Definition at line 100 of file TLine2D.h.

References _yOffset.

00100                          {
00101     return _yOffset = a;
00102 }

double TLine2D::yOffset ( void   )  const [inline]

Definition at line 82 of file TLine2D.h.

References _yOffset.

00082                            {
00083     return _yOffset;
00084 }


Member Data Documentation

double TLine2D::_det [private]

Definition at line 60 of file TLine2D.h.

Referenced by fit().

CAList<TPoint2D>* TLine2D::_list [mutable, private]

Definition at line 61 of file TLine2D.h.

Referenced by append(), fit(), list(), remove(), TLine2D(), and ~TLine2D().

double TLine2D::_slope [private]

Definition at line 58 of file TLine2D.h.

Referenced by distance(), fit(), slope(), and xOffset().

double TLine2D::_yOffset [private]

Definition at line 59 of file TLine2D.h.

Referenced by distance(), fit(), xOffset(), and yOffset().


Generated on Tue Nov 29 23:36:01 2016 for BOSS_7.0.2 by  doxygen 1.4.7