#include <TLine2D.h>
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 |
|
Constructors.
|
|
|
|
00041 : _slope(1), _yOffset(0), _det(0) { 00042 _list = new CAList<TPoint2D>(); 00043 _list->append(a); 00044 }
|
|
Destructor.
00046 { 00047 if (_list) delete _list; 00048 }
|
|
Constructors.
|
|
|
|
|
|
Destructor.
|
|
|
|
|
|
|
|
|
|
|
|
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 }
|
|
|
|
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 }
|
|
|
|
00064 { 00065 if (! _list) 00066 _list = new CAList<TPoint2D>(); 00067 return * _list; 00068 }
|
|
|
|
00058 { 00059 if (! _list) return; 00060 _list->remove(a); 00061 }
|
|
|
|
|
|
00094 { 00095 return _slope = a; 00096 }
|
|
00076 {
00077 return _slope;
00078 }
|
|
|
|
00088 { 00089 return - _yOffset / _slope; 00090 }
|
|
|
|
|
|
00100 { 00101 return _yOffset = a; 00102 }
|
|
00082 {
00083 return _yOffset;
00084 }
|
|
|
|
|
|
|
|
|
|
|