00001 // @(#)root/g3d:$Id: TPoints3DABC.cxx 21394 2007-12-17 08:57:17Z couet $ 00002 // Author: Valery Fine(fine@mail.cern.ch) 04/05/99 00003 00004 // @(#)root/g3d:$Id: TPoints3DABC.cxx 21394 2007-12-17 08:57:17Z couet $ 00005 // Author: Valery Fine(fine@mail.cern.ch) 24/04/99 00006 00007 #include "TPoints3DABC.h" 00008 #include "TMath.h" 00009 00010 ClassImp(TPoints3DABC) 00011 00012 //______________________________________________________________________________ 00013 /* Begin_Html 00014 <center><h2>The TPoints3DABC class</h2></center> 00015 Abstract class to define Arrays of 3D points. 00016 End_Html */ 00017 00018 00019 00020 //______________________________________________________________________________ 00021 Int_t TPoints3DABC::Add(Float_t x, Float_t y, Float_t z) 00022 { 00023 // Add one 3D point defined by x,y,z to the array of the points 00024 // as its last element 00025 00026 return AddLast(x,y,z); 00027 } 00028 00029 00030 //______________________________________________________________________________ 00031 Int_t TPoints3DABC::AddLast(Float_t x, Float_t y, Float_t z) 00032 { 00033 // Add one 3D point defined by x,y,z to the array of the points 00034 // as its last element 00035 00036 return SetNextPoint(x,y,z); 00037 } 00038 00039 00040 //______________________________________________________________________________ 00041 Int_t TPoints3DABC::DistancetoLine(Int_t px, Int_t py, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Int_t lineWidth ) 00042 { 00043 // Compute distance from point px,py to an axis of the band defined. 00044 // by pair points (x1,y1),(x2,y2) where lineWidth is the width of the band 00045 // 00046 // Compute the closest distance of approach from point px,py to this line. 00047 // The distance is computed in pixels units. 00048 // 00049 // 00050 // Algorithm: 00051 // 00052 // A(x1,y1) P B(x2,y2) 00053 // ------------------------------------------------ 00054 // I 00055 // I 00056 // I 00057 // I 00058 // M(x,y) 00059 // 00060 // Let us call a = distance AM a2=a**2 00061 // b = distance BM b2=b**2 00062 // c = distance AB c2=c**2 00063 // d = distance PM d2=d**2 00064 // u = distance AP u2=u**2 00065 // v = distance BP v2=v**2 c = u + v 00066 // 00067 // d2 = a2 - u2 00068 // d2 = b2 - v2 = b2 -(c-u)**2 00069 // ==> u = (a2 -b2 +c2)/2c 00070 // 00071 // Float_t x1 = gPad->XtoAbsPixel(xp1); 00072 // Float_t y1 = gPad->YtoAbsPixel(yp1); 00073 // Float_t x2 = gPad->XtoAbsPixel(xp2); 00074 // Float_t y2 = gPad->YtoAbsPixel(yp2); 00075 00076 Float_t xl, xt, yl, yt; 00077 Float_t x = px; 00078 Float_t y = py; 00079 if (x1 < x2) {xl = x1; xt = x2;} 00080 else {xl = x2; xt = x1;} 00081 if (y1 < y2) {yl = y1; yt = y2;} 00082 else {yl = y2; yt = y1;} 00083 if (x < xl-2 || x> xt+2) return 9999; //following algorithm only valid in the box 00084 if (y < yl-2 || y> yt+2) return 9999; //surrounding the line 00085 Float_t xx1 = x - x1; 00086 Float_t xx2 = x - x2; 00087 Float_t x1x2 = x1 - x2; 00088 Float_t yy1 = y - y1; 00089 Float_t yy2 = y - y2; 00090 Float_t y1y2 = y1 - y2; 00091 Float_t a2 = xx1*xx1 + yy1*yy1; 00092 Float_t b2 = xx2*xx2 + yy2*yy2; 00093 Float_t c2 = x1x2*x1x2 + y1y2*y1y2; 00094 if (c2 <= 0) return 9999; 00095 Float_t c = TMath::Sqrt(c2); 00096 Float_t u = (a2 - b2 + c2)/(2*c); 00097 Float_t d2 = TMath::Abs(a2 - u*u); 00098 if (d2 < 0) return 9999; 00099 00100 return Int_t(TMath::Sqrt(d2) - 0.5*float(lineWidth)); 00101 } 00102 00103 00104 //______________________________________________________________________________ 00105 Int_t TPoints3DABC::SetNextPoint(Float_t x, Float_t y, Float_t z) 00106 { 00107 // Add one 3D point defined by x,y,z to the array of the points 00108 // as its last element 00109 00110 return SetPoint(GetLastPosition()+1,x,y,z); 00111 } 00112 00113 00114 //______________________________________________________________________________ 00115 Int_t TPoints3DABC::GetN() const 00116 { 00117 // GetN() returns the number of allocated cells if any. 00118 // GetN() > 0 shows how many cells 00119 // can be available via GetP() method. 00120 // GetN() == 0 then GetP() must return 0 as well 00121 00122 return 0; 00123 } 00124 00125 00126 //______________________________________________________________________________ 00127 Float_t *TPoints3DABC::GetP() const 00128 { 00129 // GetP() returns the pointer to the float point array 00130 // of points if available 00131 // The number of the available celss can be found via 00132 // GetN() method. 00133 // GetN() > 0 shows how many cells 00134 00135 return 0; 00136 } 00137 00138 00139 //______________________________________________________________________________ 00140 Float_t *TPoints3DABC::GetXYZ(Float_t *xyz,Int_t idx,Int_t num) const 00141 { 00142 // GetXYZ(Float_t *xyz,Int_t idx,Int_t num=1) fills the buffer supplied 00143 // by the calling code with the points information. 00144 // 00145 // Input parameters: 00146 // 00147 // Float_t *xyz - an external user supplied floating point array. 00148 // Int_t num - the total number of the points to be copied 00149 // the dimension of that array the size of the 00150 // array is num*sizeof(Float_t) at least 00151 // Int_t idx - The index of the first copy to be taken. 00152 // 00153 // Return: The pointer to the buffer array supplied 00154 00155 if (xyz) { 00156 Int_t size = TMath::Min(idx+num,Size()); 00157 Int_t j=0; 00158 for (Int_t i=idx;i<size;i++) { 00159 xyz[j++] = GetX(i); 00160 xyz[j++] = GetY(i); 00161 xyz[j++] = GetZ(i); 00162 } 00163 } 00164 return xyz; 00165 }