#include <TLine2D.h>
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 |
Definition at line 25 of file TLine2D.h.
TLine2D::TLine2D | ( | ) |
TLine2D::TLine2D | ( | double | slope, | |
double | yOffset | |||
) |
TLine2D::TLine2D | ( | const AList< TPoint2D > & | ) |
TLine2D::~TLine2D | ( | ) | [virtual] |
void TLine2D::append | ( | const TPoint2D & | ) |
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 |
void TLine2D::remove | ( | const TPoint2D & | ) |
double TLine2D::slope | ( | double | ) | [inline] |
double TLine2D::slope | ( | void | ) | const [inline] |
double TLine2D::xOffset | ( | void | ) | const [inline] |
double TLine2D::yOffset | ( | double | ) | [inline] |
double TLine2D::yOffset | ( | void | ) | const [inline] |
double TLine2D::_det [private] |
CAList<TPoint2D>* TLine2D::_list [mutable, private] |
double TLine2D::_slope [private] |
double TLine2D::_yOffset [private] |