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
15
16/** \class TPoints3DABC
17\ingroup g3d
18Abstract class to define Arrays of 3D points.
19*/
20
21////////////////////////////////////////////////////////////////////////////////
22/// Add one 3D point defined by x,y,z to the array of the points
23/// as its last element
24
29
30////////////////////////////////////////////////////////////////////////////////
31/// Add one 3D point defined by x,y,z to the array of the points
32/// as its last element
33
38
39////////////////////////////////////////////////////////////////////////////////
40/// Compute distance from point px,py to an axis of the band defined.
41/// by pair points (x1,y1),(x2,y2) where lineWidth is the width of the band
42///
43/// Compute the closest distance of approach from point px,py to this line.
44/// The distance is computed in pixels units.
45///
46/// Algorithm:
47/// ~~~ {.cpp}
48///
49/// A(x1,y1) P B(x2,y2)
50/// ------------------------------------------------
51/// I
52/// I
53/// I
54/// I
55/// M(x,y)
56///
57/// Let us call a = distance AM a2=a**2
58/// b = distance BM b2=b**2
59/// c = distance AB c2=c**2
60/// d = distance PM d2=d**2
61/// u = distance AP u2=u**2
62/// v = distance BP v2=v**2 c = u + v
63///
64/// d2 = a2 - u2
65/// d2 = b2 - v2 = b2 -(c-u)**2
66/// ==> u = (a2 -b2 +c2)/2c
67///
68/// Float_t x1 = gPad->XtoAbsPixel(xp1);
69/// Float_t y1 = gPad->YtoAbsPixel(yp1);
70/// Float_t x2 = gPad->XtoAbsPixel(xp2);
71/// Float_t y2 = gPad->YtoAbsPixel(yp2);
72/// ~~~
73
75{
76 Float_t xl, xt, yl, yt;
77 Float_t x = px;
78 Float_t y = py;
79 if (x1 < x2) {xl = x1; xt = x2;}
80 else {xl = x2; xt = x1;}
81 if (y1 < y2) {yl = y1; yt = y2;}
82 else {yl = y2; yt = y1;}
83 if (x < xl-2 || x> xt+2) return 9999; //following algorithm only valid in the box
84 if (y < yl-2 || y> yt+2) return 9999; //surrounding the line
85 Float_t xx1 = x - x1;
86 Float_t xx2 = x - x2;
87 Float_t x1x2 = x1 - x2;
88 Float_t yy1 = y - y1;
89 Float_t yy2 = y - y2;
90 Float_t y1y2 = y1 - y2;
91 Float_t a2 = xx1*xx1 + yy1*yy1;
92 Float_t b2 = xx2*xx2 + yy2*yy2;
94 if (c2 <= 0) return 9999;
96 Float_t u = (a2 - b2 + c2)/(2*c);
98 if (d2 < 0) return 9999;
99
100 return Int_t(TMath::Sqrt(d2) - 0.5*float(lineWidth));
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Add one 3D point defined by x,y,z to the array of the points
105/// as its last element
106
111
112////////////////////////////////////////////////////////////////////////////////
113/// GetN() returns the number of allocated cells if any.
114/// GetN() > 0 shows how many cells
115/// can be available via GetP() method.
116/// GetN() == 0 then GetP() must return 0 as well
117
119{
120 return 0;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// GetP() returns the pointer to the float point array
125/// of points if available
126/// The number of the available cells can be found via
127/// GetN() method.
128/// GetN() > 0 shows how many cells
129
131{
132 return nullptr;
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// GetXYZ(Float_t *xyz,Int_t idx,Int_t num=1) fills the buffer supplied
137/// by the calling code with the points information.
138///
139/// Input parameters:
140///
141/// - Float_t *xyz : an external user supplied floating point array.
142/// - Int_t num : the total number of the points to be copied
143/// the dimension of that array the size of the
144/// array is num*sizeof(Float_t) at least
145/// - Int_t idx : The index of the first copy to be taken.
146///
147/// Return: The pointer to the buffer array supplied
148
150{
151 if (xyz) {
152 Int_t size = TMath::Min(idx+num,Size());
153 Int_t j=0;
154 for (Int_t i=idx;i<size;i++) {
155 xyz[j++] = GetX(i);
156 xyz[j++] = GetY(i);
157 xyz[j++] = GetZ(i);
158 }
159 }
160 return xyz;
161}
#define c(i)
Definition RSha256.hxx:101
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
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:673
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:199
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:124