Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPoints3DABC.cxx
Go to the documentation of this file.
1// @(#)root/g3d:$Id$
2// Author: Valery Fine(fine@mail.cern.ch) 04/05/99
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TPoints3DABC.h"
13#include "TMath.h"
14
16
17/** \class TPoints3DABC
18\ingroup g3d
19Abstract class to define Arrays of 3D points.
20*/
21
22////////////////////////////////////////////////////////////////////////////////
23/// Add one 3D point defined by x,y,z to the array of the points
24/// as its last element
25
27{
28 return AddLast(x,y,z);
29}
30
31////////////////////////////////////////////////////////////////////////////////
32/// Add one 3D point defined by x,y,z to the array of the points
33/// as its last element
34
36{
37 return SetNextPoint(x,y,z);
38}
39
40////////////////////////////////////////////////////////////////////////////////
41/// Compute distance from point px,py to an axis of the band defined.
42/// by pair points (x1,y1),(x2,y2) where lineWidth is the width of the band
43///
44/// Compute the closest distance of approach from point px,py to this line.
45/// The distance is computed in pixels units.
46///
47/// Algorithm:
48/// ~~~ {.cpp}
49///
50/// A(x1,y1) P B(x2,y2)
51/// ------------------------------------------------
52/// I
53/// I
54/// I
55/// I
56/// M(x,y)
57///
58/// Let us call a = distance AM a2=a**2
59/// b = distance BM b2=b**2
60/// c = distance AB c2=c**2
61/// d = distance PM d2=d**2
62/// u = distance AP u2=u**2
63/// v = distance BP v2=v**2 c = u + v
64///
65/// d2 = a2 - u2
66/// d2 = b2 - v2 = b2 -(c-u)**2
67/// ==> u = (a2 -b2 +c2)/2c
68///
69/// Float_t x1 = gPad->XtoAbsPixel(xp1);
70/// Float_t y1 = gPad->YtoAbsPixel(yp1);
71/// Float_t x2 = gPad->XtoAbsPixel(xp2);
72/// Float_t y2 = gPad->YtoAbsPixel(yp2);
73/// ~~~
74
76{
77 Float_t xl, xt, yl, yt;
78 Float_t x = px;
79 Float_t y = py;
80 if (x1 < x2) {xl = x1; xt = x2;}
81 else {xl = x2; xt = x1;}
82 if (y1 < y2) {yl = y1; yt = y2;}
83 else {yl = y2; yt = y1;}
84 if (x < xl-2 || x> xt+2) return 9999; //following algorithm only valid in the box
85 if (y < yl-2 || y> yt+2) return 9999; //surrounding the line
86 Float_t xx1 = x - x1;
87 Float_t xx2 = x - x2;
88 Float_t x1x2 = x1 - x2;
89 Float_t yy1 = y - y1;
90 Float_t yy2 = y - y2;
91 Float_t y1y2 = y1 - y2;
92 Float_t a2 = xx1*xx1 + yy1*yy1;
93 Float_t b2 = xx2*xx2 + yy2*yy2;
94 Float_t c2 = x1x2*x1x2 + y1y2*y1y2;
95 if (c2 <= 0) return 9999;
97 Float_t u = (a2 - b2 + c2)/(2*c);
98 Float_t d2 = TMath::Abs(a2 - u*u);
99 if (d2 < 0) return 9999;
100
101 return Int_t(TMath::Sqrt(d2) - 0.5*float(lineWidth));
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Add one 3D point defined by x,y,z to the array of the points
106/// as its last element
107
109{
110 return SetPoint(GetLastPosition()+1,x,y,z);
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// GetN() returns the number of allocated cells if any.
115/// GetN() > 0 shows how many cells
116/// can be available via GetP() method.
117/// GetN() == 0 then GetP() must return 0 as well
118
120{
121 return 0;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// GetP() returns the pointer to the float point array
126/// of points if available
127/// The number of the available cells can be found via
128/// GetN() method.
129/// GetN() > 0 shows how many cells
130
132{
133 return 0;
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// GetXYZ(Float_t *xyz,Int_t idx,Int_t num=1) fills the buffer supplied
138/// by the calling code with the points information.
139///
140/// Input parameters:
141///
142/// - Float_t *xyz : an external user supplied floating point array.
143/// - Int_t num : the total number of the points to be copied
144/// the dimension of that array the size of the
145/// array is num*sizeof(Float_t) at least
146/// - Int_t idx : The index of the first copy to be taken.
147///
148/// Return: The pointer to the buffer array supplied
149
151{
152 if (xyz) {
153 Int_t size = TMath::Min(idx+num,Size());
154 Int_t j=0;
155 for (Int_t i=idx;i<size;i++) {
156 xyz[j++] = GetX(i);
157 xyz[j++] = GetY(i);
158 xyz[j++] = GetZ(i);
159 }
160 }
161 return xyz;
162}
#define c(i)
Definition RSha256.hxx:101
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
Abstract class to define Arrays of 3D points.
virtual Float_t GetX(Int_t idx) const =0
virtual Int_t AddLast(Float_t x, Float_t y, Float_t z)
Add one 3D point defined by x,y,z to the array of the points as its last element.
virtual Int_t SetNextPoint(Float_t x, Float_t y, Float_t z)
Add one 3D point defined by x,y,z to the array of the points as its last element.
static Int_t DistancetoLine(Int_t px, Int_t py, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Int_t lineWidth=1)
Compute distance from point px,py to an axis of the band defined.
virtual Float_t * GetXYZ(Float_t *xyz, Int_t idx, Int_t num=1) const
GetXYZ(Float_t *xyz,Int_t idx,Int_t num=1) fills the buffer supplied by the calling code with the poi...
virtual Float_t GetZ(Int_t idx) const =0
virtual Int_t GetN() const
GetN() returns the number of allocated cells if any.
virtual Int_t Size() const =0
virtual Float_t * GetP() const
GetP() returns the pointer to the float point array of points if available The number of the availabl...
virtual Int_t SetPoint(Int_t point, Float_t x, Float_t y, Float_t z)=0
virtual Int_t Add(Float_t x, Float_t y, Float_t z)
Add one 3D point defined by x,y,z to the array of the points as its last element.
virtual Float_t GetY(Int_t idx) const =0
virtual Int_t GetLastPosition() const =0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
return c2
Definition legend2.C:14
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123