ROOT  6.06/09
Reference Guide
TGeoHalfSpace.cxx
Go to the documentation of this file.
1 // @(#):$Id$
2 // Author: Mihaela Gheata 03/08/04
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 //_____________________________________________________________________________
13 // TGeoHalfSpace - A half-space defined by:
14 // p[3] - an arbitrary point on the plane
15 // n[3] - normal at the plane in point P
16 // A half-space is not really a shape, because it is infinite. The normal
17 // points "outside" the half-space
18 //_____________________________________________________________________________
19 
20 #include "Riostream.h"
21 #include "TGeoHalfSpace.h"
22 #include "TMath.h"
23 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Dummy constructor
28 
30 {
31  SetShapeBit(TGeoShape::kGeoHalfSpace);
32  SetShapeBit(TGeoShape::kGeoInvalidShape);
33  memset(fP, 0, 3*sizeof(Double_t));
34  memset(fN, 0, 3*sizeof(Double_t));
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Constructor with name, point on the plane and normal
39 
41  :TGeoBBox(name, 0,0,0)
42 {
45  Double_t param[6];
46  memcpy(param, p, 3*sizeof(Double_t));
47  memcpy(&param[3], n, 3*sizeof(Double_t));
48  SetDimensions(param);
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default constructor specifying minimum and maximum radius
53 
55  :TGeoBBox(0,0,0)
56 {
59  SetDimensions(param);
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// destructor
64 
66 {
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Compute normal to closest surface from POINT.
71 
72 void TGeoHalfSpace::ComputeNormal(const Double_t * /*point*/, const Double_t *dir, Double_t *norm)
73 {
74  memcpy(norm, fN, 3*sizeof(Double_t));
75  if (norm[0]*dir[0]+norm[1]*dir[1]+norm[2]*dir[2]<0) {
76  norm[0] = -norm[0];
77  norm[1] = -norm[1];
78  norm[2] = -norm[2];
79  }
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// test if point is inside the half-space
84 
86 {
87  Double_t r[3];
88  r[0] = fP[0]-point[0];
89  r[1] = fP[1]-point[1];
90  r[2] = fP[2]-point[2];
91  Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
92  if (rdotn < 0) return kFALSE;
93  return kTRUE;
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// A half-space does not have a mesh primitive
98 
100 {
101  return 999;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// compute distance from inside point to the plane
106 
107 Double_t TGeoHalfSpace::DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
108 {
109  Double_t r[3];
110  r[0] = fP[0]-point[0];
111  r[1] = fP[1]-point[1];
112  r[2] = fP[2]-point[2];
113  Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
114  if (iact<3 && safe) {
115  *safe = rdotn;
116  if (iact==0) return TGeoShape::Big();
117  if ((iact==1) && (*safe>step)) return TGeoShape::Big();
118  }
119  // compute distance to plane
120  Double_t snxt = TGeoShape::Big();
121  Double_t ddotn = dir[0]*fN[0]+dir[1]*fN[1]+dir[2]*fN[2];
122  if (TMath::Abs(ddotn)<TGeoShape::Tolerance()) return snxt;
123  snxt = rdotn/ddotn;
124  if (snxt<0) return TGeoShape::Big();
125  return snxt;
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// compute distance from inside point to the plane
130 
131 Double_t TGeoHalfSpace::DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
132 {
133  Double_t r[3];
134  r[0] = fP[0]-point[0];
135  r[1] = fP[1]-point[1];
136  r[2] = fP[2]-point[2];
137  Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
138  if (iact<3 && safe) {
139  *safe = -rdotn;
140  if (iact==0) return TGeoShape::Big();
141  if ((iact==1) && (step<*safe)) return TGeoShape::Big();
142  }
143  // compute distance to plane
144  Double_t snxt = TGeoShape::Big();
145  Double_t ddotn = dir[0]*fN[0]+dir[1]*fN[1]+dir[2]*fN[2];
146  if (TMath::Abs(ddotn)<TGeoShape::Tolerance()) return snxt;
147  snxt = rdotn/ddotn;
148  if (snxt<0) return TGeoShape::Big();
149  return snxt;
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Divide the shape along one axis.
154 
155 TGeoVolume *TGeoHalfSpace::Divide(TGeoVolume * /*voldiv*/, const char * /*divname*/, Int_t /*iaxis*/, Int_t /*ndiv*/,
156  Double_t /*start*/, Double_t /*step*/)
157 {
158  Error("Divide", "Half-spaces cannot be divided");
159  return 0;
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Returns numbers of vertices, segments and polygons composing the shape mesh.
164 
165 void TGeoHalfSpace::GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
166 {
167  nvert = 0;
168  nsegs = 0;
169  npols = 0;
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// print shape parameters
174 
176 {
177  printf("*** Shape %s: TGeoHalfSpace ***\n", GetName());
178  printf(" Point : %11.5f, %11.5f, %11.5f\n", fP[0], fP[1], fP[2]);
179  printf(" Normal : %11.5f, %11.5f, %11.5f\n", fN[0], fN[1], fN[2]);
180 }
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// computes the closest distance from given point to this shape, according
184 /// to option. The matching point on the shape is stored in spoint.
185 
186 Double_t TGeoHalfSpace::Safety(const Double_t *point, Bool_t /*in*/) const
187 {
188  Double_t r[3];
189  r[0] = fP[0]-point[0];
190  r[1] = fP[1]-point[1];
191  r[2] = fP[2]-point[2];
192  Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
193  return TMath::Abs(rdotn);
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Save a primitive as a C++ statement(s) on output stream "out".
198 
199 void TGeoHalfSpace::SavePrimitive(std::ostream &out, Option_t * /*option*/ /*= ""*/)
200 {
201  if (TObject::TestBit(kGeoSavePrimitive)) return;
202  out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
203  out << " point[0] = " << fP[0] << ";" << std::endl;
204  out << " point[1] = " << fP[1] << ";" << std::endl;
205  out << " point[2] = " << fP[2] << ";" << std::endl;
206  out << " norm[0] = " << fN[0] << ";" << std::endl;
207  out << " norm[1] = " << fN[1] << ";" << std::endl;
208  out << " norm[2] = " << fN[2] << ";" << std::endl;
209  out << " TGeoShape *" << GetPointerName() << " = new TGeoHalfSpace(\"" << GetName() << "\", point,norm);" << std::endl;
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Set half-space parameters as stored in an array.
215 
217 {
218  memcpy(fP, param, 3*sizeof(Double_t));
219  memcpy(fN, &param[3], 3*sizeof(Double_t));
220  Double_t nsq = TMath::Sqrt(fN[0]*fN[0]+fN[1]*fN[1]+fN[2]*fN[2]);
221  fN[0] /= nsq;
222  fN[1] /= nsq;
223  fN[2] /= nsq;
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Check the inside status for each of the points in the array.
228 /// Input: Array of point coordinates + vector size
229 /// Output: Array of Booleans for the inside of each point
230 
231 void TGeoHalfSpace::Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
232 {
233  for (Int_t i=0; i<vecsize; i++) inside[i] = Contains(&points[3*i]);
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Compute the normal for an array o points so that norm.dot.dir is positive
238 /// Input: Arrays of point coordinates and directions + vector size
239 /// Output: Array of normal directions
240 
241 void TGeoHalfSpace::ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
242 {
243  for (Int_t i=0; i<vecsize; i++) ComputeNormal(&points[3*i], &dirs[3*i], &norms[3*i]);
244 }
245 
246 ////////////////////////////////////////////////////////////////////////////////
247 /// Compute distance from array of input points having directions specisied by dirs. Store output in dists
248 
249 void TGeoHalfSpace::DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
250 {
251  for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromInside(&points[3*i], &dirs[3*i], 3, step[i]);
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Compute distance from array of input points having directions specisied by dirs. Store output in dists
256 
257 void TGeoHalfSpace::DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
258 {
259  for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromOutside(&points[3*i], &dirs[3*i], 3, step[i]);
260 }
261 
262 ////////////////////////////////////////////////////////////////////////////////
263 /// Compute safe distance from each of the points in the input array.
264 /// Input: Array of point coordinates, array of statuses for these points, size of the arrays
265 /// Output: Safety values
266 
267 void TGeoHalfSpace::Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
268 {
269  for (Int_t i=0; i<vecsize; i++) safe[i] = Safety(&points[3*i], inside[i]);
270 }
Double_t fN[3]
Definition: TGeoHalfSpace.h:34
virtual void ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
Compute the normal for an array o points so that norm.dot.dir is positive Input: Arrays of point coor...
virtual void InspectShape() const
print shape parameters
virtual void DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const
Compute distance from array of input points having directions specisied by dirs. Store output in dist...
const char Option_t
Definition: RtypesCore.h:62
ClassImp(TGeoHalfSpace) TGeoHalfSpace
Dummy constructor.
virtual void DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const
Compute distance from array of input points having directions specisied by dirs. Store output in dist...
virtual void GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
Returns numbers of vertices, segments and polygons composing the shape mesh.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
virtual Bool_t Contains(const Double_t *point) const
test if point is inside the half-space
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
Compute normal to closest surface from POINT.
static Double_t Tolerance()
Definition: TGeoShape.h:101
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
compute distance from inside point to the plane
virtual void Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
Compute safe distance from each of the points in the input array.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
char * out
Definition: TBase64.cxx:29
point * points
Definition: X3DBuffer.c:20
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const
computes the closest distance from given point to this shape, according to option.
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual void Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
Check the inside status for each of the points in the array.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
compute distance from inside point to the plane
virtual void SetDimensions(Double_t *param)
Set half-space parameters as stored in an array.
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:247
double Double_t
Definition: RtypesCore.h:55
virtual ~TGeoHalfSpace()
destructor
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
virtual TGeoVolume * Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step)
Divide the shape along one axis.
const char * GetPointerName() const
Provide a pointer name containing uid.
Definition: TGeoShape.cxx:697
static Double_t Big()
Definition: TGeoShape.h:98
#define name(a, b)
Definition: linkTestLib0.cpp:5
void SetShapeBit(UInt_t f, Bool_t set)
Equivalent of TObject::SetBit.
Definition: TGeoShape.cxx:522
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
A half-space does not have a mesh primitive.
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
const Bool_t kTRUE
Definition: Rtypes.h:91
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
const Int_t n
Definition: legend1.C:16
Double_t fP[3]
Definition: TGeoHalfSpace.h:33