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