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{
53 Double_t param[6];
54 memcpy(param, p, 3 * sizeof(Double_t));
55 memcpy(&param[3], n, 3 * sizeof(Double_t));
56 SetDimensions(param);
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Default constructor specifying minimum and maximum radius
61
63{
66 SetDimensions(param);
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// destructor
71
73
74////////////////////////////////////////////////////////////////////////////////
75/// Compute normal to closest surface from POINT.
76
77void TGeoHalfSpace::ComputeNormal(const Double_t * /*point*/, const Double_t *dir, Double_t *norm)
78{
79 memcpy(norm, fN, 3 * sizeof(Double_t));
80 if (norm[0] * dir[0] + norm[1] * dir[1] + norm[2] * dir[2] < 0) {
81 norm[0] = -norm[0];
82 norm[1] = -norm[1];
83 norm[2] = -norm[2];
84 }
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// test if point is inside the half-space
89
91{
92 Double_t r[3];
93 r[0] = fP[0] - point[0];
94 r[1] = fP[1] - point[1];
95 r[2] = fP[2] - point[2];
96 Double_t rdotn = r[0] * fN[0] + r[1] * fN[1] + r[2] * fN[2];
97 if (rdotn < 0)
98 return kFALSE;
99 return kTRUE;
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// A half-space does not have a mesh primitive
104
106{
107 return 999;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// compute distance from inside point to the plane
112
114 Double_t *safe) const
115{
116 Double_t r[3];
117 r[0] = fP[0] - point[0];
118 r[1] = fP[1] - point[1];
119 r[2] = fP[2] - point[2];
120 Double_t rdotn = r[0] * fN[0] + r[1] * fN[1] + r[2] * fN[2];
121 if (iact < 3 && safe) {
122 *safe = rdotn;
123 if (iact == 0)
124 return TGeoShape::Big();
125 if ((iact == 1) && (*safe > step))
126 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())
132 return snxt;
133 snxt = rdotn / ddotn;
134 if (snxt < 0)
135 return TGeoShape::Big();
136 return snxt;
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// compute distance from inside point to the plane
141
143 Double_t *safe) const
144{
145 Double_t r[3];
146 r[0] = fP[0] - point[0];
147 r[1] = fP[1] - point[1];
148 r[2] = fP[2] - point[2];
149 Double_t rdotn = r[0] * fN[0] + r[1] * fN[1] + r[2] * fN[2];
150 if (iact < 3 && safe) {
151 *safe = -rdotn;
152 if (iact == 0)
153 return TGeoShape::Big();
154 if ((iact == 1) && (step < *safe))
155 return TGeoShape::Big();
156 }
157 // compute distance to plane
158 Double_t snxt = TGeoShape::Big();
159 Double_t ddotn = dir[0] * fN[0] + dir[1] * fN[1] + dir[2] * fN[2];
160 if (TMath::Abs(ddotn) < TGeoShape::Tolerance())
161 return snxt;
162 snxt = rdotn / ddotn;
163 if (snxt < 0)
164 return TGeoShape::Big();
165 return snxt;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Divide the shape along one axis.
170
171TGeoVolume *TGeoHalfSpace::Divide(TGeoVolume * /*voldiv*/, const char * /*divname*/, Int_t /*iaxis*/, Int_t /*ndiv*/,
172 Double_t /*start*/, Double_t /*step*/)
173{
174 Error("Divide", "Half-spaces cannot be divided");
175 return nullptr;
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Returns numbers of vertices, segments and polygons composing the shape mesh.
180
181void TGeoHalfSpace::GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
182{
183 nvert = 0;
184 nsegs = 0;
185 npols = 0;
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// print shape parameters
190
192{
193 printf("*** Shape %s: TGeoHalfSpace ***\n", GetName());
194 printf(" Point : %11.5f, %11.5f, %11.5f\n", fP[0], fP[1], fP[2]);
195 printf(" Normal : %11.5f, %11.5f, %11.5f\n", fN[0], fN[1], fN[2]);
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// computes the closest distance from given point to this shape, according
200/// to option. The matching point on the shape is stored in spoint.
201
203{
204 Double_t r[3];
205 r[0] = fP[0] - point[0];
206 r[1] = fP[1] - point[1];
207 r[2] = fP[2] - point[2];
208 Double_t rdotn = r[0] * fN[0] + r[1] * fN[1] + r[2] * fN[2];
209 return TMath::Abs(rdotn);
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Save a primitive as a C++ statement(s) on output stream "out".
214
215void TGeoHalfSpace::SavePrimitive(std::ostream &out, Option_t * /*option*/ /*= ""*/)
216{
218 return;
219 out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
220 out << " point[0] = " << fP[0] << ";" << std::endl;
221 out << " point[1] = " << fP[1] << ";" << std::endl;
222 out << " point[2] = " << fP[2] << ";" << std::endl;
223 out << " norm[0] = " << fN[0] << ";" << std::endl;
224 out << " norm[1] = " << fN[1] << ";" << std::endl;
225 out << " norm[2] = " << fN[2] << ";" << std::endl;
226 out << " TGeoShape *" << GetPointerName() << " = new TGeoHalfSpace(\"" << GetName() << "\", point,norm);"
227 << std::endl;
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Set half-space parameters as stored in an array.
233
235{
236 memcpy(fP, param, 3 * sizeof(Double_t));
237 memcpy(fN, &param[3], 3 * sizeof(Double_t));
238 Double_t nsq = TMath::Sqrt(fN[0] * fN[0] + fN[1] * fN[1] + fN[2] * fN[2]);
239 fN[0] /= nsq;
240 fN[1] /= nsq;
241 fN[2] /= nsq;
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Check the inside status for each of the points in the array.
246/// Input: Array of point coordinates + vector size
247/// Output: Array of Booleans for the inside of each point
248
249void TGeoHalfSpace::Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
250{
251 for (Int_t i = 0; i < vecsize; i++)
252 inside[i] = Contains(&points[3 * i]);
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// Compute the normal for an array o points so that norm.dot.dir is positive
257/// Input: Arrays of point coordinates and directions + vector size
258/// Output: Array of normal directions
259
260void TGeoHalfSpace::ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
261{
262 for (Int_t i = 0; i < vecsize; i++)
263 ComputeNormal(&points[3 * i], &dirs[3 * i], &norms[3 * i]);
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Compute distance from array of input points having directions specified by dirs. Store output in dists
268
269void TGeoHalfSpace::DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize,
270 Double_t *step) const
271{
272 for (Int_t i = 0; i < vecsize; i++)
273 dists[i] = DistFromInside(&points[3 * i], &dirs[3 * i], 3, step[i]);
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Compute distance from array of input points having directions specified by dirs. Store output in dists
278
279void TGeoHalfSpace::DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize,
280 Double_t *step) const
281{
282 for (Int_t i = 0; i < vecsize; i++)
283 dists[i] = DistFromOutside(&points[3 * i], &dirs[3 * i], 3, step[i]);
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Compute safe distance from each of the points in the input array.
288/// Input: Array of point coordinates, array of statuses for these points, size of the arrays
289/// Output: Safety values
290
291void TGeoHalfSpace::Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
292{
293 for (Int_t i = 0; i < vecsize; i++)
294 safe[i] = Safety(&points[3 * i], inside[i]);
295}
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:17
A half space is limited just by a plane, defined by a point and the normal direction.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
A half-space does not have a mesh primitive.
Double_t fN[3]
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) override
Compute normal to closest surface from POINT.
void DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const override
Compute distance from array of input points having directions specified by dirs. Store output in dist...
void Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const override
Compute safe distance from each of the points in the input array.
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
computes the closest distance from given point to this shape, according to option.
void SetDimensions(Double_t *param) override
Set half-space parameters as stored in an array.
void InspectShape() const override
print shape parameters
void ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize) override
Compute the normal for an array o points so that norm.dot.dir is positive Input: Arrays of point coor...
Bool_t Contains(const Double_t *point) const override
test if point is inside the half-space
TGeoVolume * Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step) override
Divide the shape along one axis.
~TGeoHalfSpace() override
destructor
void GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const override
Returns numbers of vertices, segments and polygons composing the shape mesh.
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 override
compute distance from inside point to the plane
void Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const override
Check the inside status for each of the points in the array.
Double_t fP[3]
TGeoHalfSpace()
Dummy constructor.
void DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const override
Compute distance from array of input points having directions specified by dirs. Store output in dist...
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 override
compute distance from inside point to the plane
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
static Double_t Big()
Definition TGeoShape.h:87
void SetShapeBit(UInt_t f, Bool_t set)
Equivalent of TObject::SetBit.
const char * GetPointerName() const
Provide a pointer name containing uid.
const char * GetName() const override
Get the shape name.
@ kGeoSavePrimitive
Definition TGeoShape.h:64
@ kGeoHalfSpace
Definition TGeoShape.h:62
@ kGeoInvalidShape
Definition TGeoShape.h:41
static Double_t Tolerance()
Definition TGeoShape.h:90
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
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:780
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:976
const Int_t n
Definition legend1.C:16
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123