Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TLine2D Class Reference

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

#include <TLine2D.h>

List of all members.

Public Member Functions

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

Private Attributes

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


Detailed Description

A class to represent a line in 2D.


Constructor & Destructor Documentation

TLine2D::TLine2D  ) 
 

Constructors.

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

TLine2D::TLine2D double  slope,
double  yOffset
 

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

TLine2D::TLine2D const AList< TPoint2D > &   ) 
 

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

TLine2D::~TLine2D  )  [virtual]
 

Destructor.

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

TLine2D::TLine2D  ) 
 

Constructors.

TLine2D::TLine2D double  slope,
double  yOffset
 

TLine2D::TLine2D const AList< TPoint2D > &   ) 
 

virtual TLine2D::~TLine2D  )  [virtual]
 

Destructor.


Member Function Documentation

void TLine2D::append const TPoint2D  ) 
 

void TLine2D::append const TPoint2D  ) 
 

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

double TLine2D::det void   )  const
 

double TLine2D::det void   )  const
 

double TLine2D::distance const TPoint2D  )  const
 

double TLine2D::distance const TPoint2D  )  const
 

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   ) 
 

int TLine2D::fit void   ) 
 

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
 

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

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

void TLine2D::remove const TPoint2D  ) 
 

void TLine2D::remove const TPoint2D  ) 
 

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

double TLine2D::slope double   ) 
 

double TLine2D::slope void   )  const
 

double TLine2D::slope double   )  [inline]
 

00094                        {
00095     return _slope = a;
00096 }

double TLine2D::slope void   )  const [inline]
 

00076                          {
00077     return _slope;
00078 }

double TLine2D::xOffset void   )  const
 

double TLine2D::xOffset void   )  const [inline]
 

00088                            {
00089     return - _yOffset / _slope;
00090 }

double TLine2D::yOffset double   ) 
 

double TLine2D::yOffset void   )  const
 

double TLine2D::yOffset double   )  [inline]
 

00100                          {
00101     return _yOffset = a;
00102 }

double TLine2D::yOffset void   )  const [inline]
 

00082                            {
00083     return _yOffset;
00084 }


Member Data Documentation

double TLine2D::_det [private]
 

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

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

double TLine2D::_slope [private]
 

double TLine2D::_yOffset [private]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 18:53:46 2011 for BOSS6.5.5 by  doxygen 1.3.9.1