Logo ROOT  
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
15A half-space defined by:
16 - p[3] - an arbitrary point on the plane
17 - n[3] - normal at the plane in point P
18A half-space is not really a shape, because it is infinite. The normal
19points "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{
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
74void 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
109Double_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
133Double_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
157TGeoVolume *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
167void 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
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
201void TGeoHalfSpace::SavePrimitive(std::ostream &out, Option_t * /*option*/ /*= ""*/)
202{
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
233void 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
243void 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
251void 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
259void 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
269void 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}
ROOT::R::TRInterface & r
Definition: Object.C:4
const Bool_t kFALSE
Definition: RtypesCore.h:90
double Double_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
char name[80]
Definition: TGX11.cxx:109
point * points
Definition: X3DBuffer.c:22
Box class.
Definition: TGeoBBox.h:18
A half-space defined by:
Definition: TGeoHalfSpace.h:18
Double_t fN[3]
Definition: TGeoHalfSpace.h:21
virtual void SetDimensions(Double_t *param)
Set half-space parameters as stored in an array.
virtual void GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
Returns numbers of vertices, segments and polygons composing the shape mesh.
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 Int_t DistancetoPrimitive(Int_t px, Int_t py)
A half-space does not have a mesh primitive.
virtual ~TGeoHalfSpace()
destructor
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 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 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 InspectShape() const
print shape parameters
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 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 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 ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
Compute normal to closest surface from POINT.
Double_t fP[3]
Definition: TGeoHalfSpace.h:20
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.
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
TGeoHalfSpace()
Dummy constructor.
virtual Bool_t Contains(const Double_t *point) const
test if point is inside the half-space
static Double_t Big()
Definition: TGeoShape.h:88
void SetShapeBit(UInt_t f, Bool_t set)
Equivalent of TObject::SetBit.
Definition: TGeoShape.cxx:524
const char * GetPointerName() const
Provide a pointer name containing uid.
Definition: TGeoShape.cxx:699
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:248
@ kGeoSavePrimitive
Definition: TGeoShape.h:65
@ kGeoHalfSpace
Definition: TGeoShape.h:63
@ kGeoInvalidShape
Definition: TGeoShape.h:42
static Double_t Tolerance()
Definition: TGeoShape.h:91
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:47
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
const Int_t n
Definition: legend1.C:16
Double_t Sqrt(Double_t x)
Definition: TMath.h:681
Short_t Abs(Short_t d)
Definition: TMathBase.h:120