Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 Shapes_classes
14
15A half space is limited just by a plane, defined by a point and the
16normal direction. The point lies on the plane and the normal vector
17points outside the half space. The half space is the only shape
18which is infinite and can be used only in Boolean operations that
19result in non-infinite composite shapes (see also TGeoCompositeShape).
20A half space has to be defined using the constructor:
21
22~~~{.cpp}
23TGeoHalfSpace (const char *name, Double_t *point[3],
24Double_t *norm[3]);
25~~~
26
27*/
28
29#include <iostream>
30#include "TGeoHalfSpace.h"
31#include "TMath.h"
32
34
35////////////////////////////////////////////////////////////////////////////////
36/// Dummy constructor
37
39{
42 memset(fP, 0, 3*sizeof(Double_t));
43 memset(fN, 0, 3*sizeof(Double_t));
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Constructor with name, point on the plane and normal
48
50 :TGeoBBox(name, 0,0,0)
51{
54 Double_t param[6];
55 memcpy(param, p, 3*sizeof(Double_t));
56 memcpy(&param[3], n, 3*sizeof(Double_t));
57 SetDimensions(param);
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Default constructor specifying minimum and maximum radius
62
64 :TGeoBBox(0,0,0)
65{
68 SetDimensions(param);
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// destructor
73
75{
76}
77
78////////////////////////////////////////////////////////////////////////////////
79/// Compute normal to closest surface from POINT.
80
81void TGeoHalfSpace::ComputeNormal(const Double_t * /*point*/, const Double_t *dir, Double_t *norm)
82{
83 memcpy(norm, fN, 3*sizeof(Double_t));
84 if (norm[0]*dir[0]+norm[1]*dir[1]+norm[2]*dir[2]<0) {
85 norm[0] = -norm[0];
86 norm[1] = -norm[1];
87 norm[2] = -norm[2];
88 }
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// test if point is inside the half-space
93
95{
96 Double_t r[3];
97 r[0] = fP[0]-point[0];
98 r[1] = fP[1]-point[1];
99 r[2] = fP[2]-point[2];
100 Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
101 if (rdotn < 0) return kFALSE;
102 return kTRUE;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// A half-space does not have a mesh primitive
107
109{
110 return 999;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// compute distance from inside point to the plane
115
116Double_t TGeoHalfSpace::DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
117{
118 Double_t r[3];
119 r[0] = fP[0]-point[0];
120 r[1] = fP[1]-point[1];
121 r[2] = fP[2]-point[2];
122 Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
123 if (iact<3 && safe) {
124 *safe = rdotn;
125 if (iact==0) return TGeoShape::Big();
126 if ((iact==1) && (*safe>step)) return TGeoShape::Big();
127 }
128 // compute distance to plane
129 Double_t snxt = TGeoShape::Big();
130 Double_t ddotn = dir[0]*fN[0]+dir[1]*fN[1]+dir[2]*fN[2];
131 if (TMath::Abs(ddotn)<TGeoShape::Tolerance()) return snxt;
132 snxt = rdotn/ddotn;
133 if (snxt<0) return TGeoShape::Big();
134 return snxt;
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// compute distance from inside point to the plane
139
140Double_t TGeoHalfSpace::DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
141{
142 Double_t r[3];
143 r[0] = fP[0]-point[0];
144 r[1] = fP[1]-point[1];
145 r[2] = fP[2]-point[2];
146 Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
147 if (iact<3 && safe) {
148 *safe = -rdotn;
149 if (iact==0) return TGeoShape::Big();
150 if ((iact==1) && (step<*safe)) return TGeoShape::Big();
151 }
152 // compute distance to plane
153 Double_t snxt = TGeoShape::Big();
154 Double_t ddotn = dir[0]*fN[0]+dir[1]*fN[1]+dir[2]*fN[2];
155 if (TMath::Abs(ddotn)<TGeoShape::Tolerance()) return snxt;
156 snxt = rdotn/ddotn;
157 if (snxt<0) return TGeoShape::Big();
158 return snxt;
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Divide the shape along one axis.
163
164TGeoVolume *TGeoHalfSpace::Divide(TGeoVolume * /*voldiv*/, const char * /*divname*/, Int_t /*iaxis*/, Int_t /*ndiv*/,
165 Double_t /*start*/, Double_t /*step*/)
166{
167 Error("Divide", "Half-spaces cannot be divided");
168 return 0;
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// Returns numbers of vertices, segments and polygons composing the shape mesh.
173
174void TGeoHalfSpace::GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
175{
176 nvert = 0;
177 nsegs = 0;
178 npols = 0;
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// print shape parameters
183
185{
186 printf("*** Shape %s: TGeoHalfSpace ***\n", GetName());
187 printf(" Point : %11.5f, %11.5f, %11.5f\n", fP[0], fP[1], fP[2]);
188 printf(" Normal : %11.5f, %11.5f, %11.5f\n", fN[0], fN[1], fN[2]);
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// computes the closest distance from given point to this shape, according
193/// to option. The matching point on the shape is stored in spoint.
194
196{
197 Double_t r[3];
198 r[0] = fP[0]-point[0];
199 r[1] = fP[1]-point[1];
200 r[2] = fP[2]-point[2];
201 Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
202 return TMath::Abs(rdotn);
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Save a primitive as a C++ statement(s) on output stream "out".
207
208void TGeoHalfSpace::SavePrimitive(std::ostream &out, Option_t * /*option*/ /*= ""*/)
209{
211 out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
212 out << " point[0] = " << fP[0] << ";" << std::endl;
213 out << " point[1] = " << fP[1] << ";" << std::endl;
214 out << " point[2] = " << fP[2] << ";" << std::endl;
215 out << " norm[0] = " << fN[0] << ";" << std::endl;
216 out << " norm[1] = " << fN[1] << ";" << std::endl;
217 out << " norm[2] = " << fN[2] << ";" << std::endl;
218 out << " TGeoShape *" << GetPointerName() << " = new TGeoHalfSpace(\"" << GetName() << "\", point,norm);" << std::endl;
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Set half-space parameters as stored in an array.
224
226{
227 memcpy(fP, param, 3*sizeof(Double_t));
228 memcpy(fN, &param[3], 3*sizeof(Double_t));
229 Double_t nsq = TMath::Sqrt(fN[0]*fN[0]+fN[1]*fN[1]+fN[2]*fN[2]);
230 fN[0] /= nsq;
231 fN[1] /= nsq;
232 fN[2] /= nsq;
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Check the inside status for each of the points in the array.
237/// Input: Array of point coordinates + vector size
238/// Output: Array of Booleans for the inside of each point
239
240void TGeoHalfSpace::Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
241{
242 for (Int_t i=0; i<vecsize; i++) inside[i] = Contains(&points[3*i]);
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Compute the normal for an array o points so that norm.dot.dir is positive
247/// Input: Arrays of point coordinates and directions + vector size
248/// Output: Array of normal directions
249
250void TGeoHalfSpace::ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
251{
252 for (Int_t i=0; i<vecsize; i++) ComputeNormal(&points[3*i], &dirs[3*i], &norms[3*i]);
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// Compute distance from array of input points having directions specified by dirs. Store output in dists
257
258void TGeoHalfSpace::DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
259{
260 for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromInside(&points[3*i], &dirs[3*i], 3, step[i]);
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Compute distance from array of input points having directions specified by dirs. Store output in dists
265
266void TGeoHalfSpace::DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
267{
268 for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromOutside(&points[3*i], &dirs[3*i], 3, step[i]);
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Compute safe distance from each of the points in the input array.
273/// Input: Array of point coordinates, array of statuses for these points, size of the arrays
274/// Output: Safety values
275
276void TGeoHalfSpace::Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
277{
278 for (Int_t i=0; i<vecsize; i++) safe[i] = Safety(&points[3*i], inside[i]);
279}
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
char name[80]
Definition TGX11.cxx:110
Box class.
Definition TGeoBBox.h:18
A half space is limited just by a plane, defined by a point and the normal direction.
Double_t fN[3]
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) 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 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 Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const
compute distance from inside point to the plane
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 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]
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.
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.
const char * GetPointerName() const
Provide a pointer name containing uid.
virtual const char * GetName() const
Get the shape name.
@ 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:49
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:201
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:774
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:970
const Int_t n
Definition legend1.C:16
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:660
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123