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