Geant4  10.01.p03
UTrap.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * This Software is part of the AIDA Unified Solids Library package *
4 // * See: https://aidasoft.web.cern.ch/USolids *
5 // ********************************************************************
6 //
7 // $Id:$
8 //
9 // --------------------------------------------------------------------
10 //
11 // UTrap
12 //
13 // Class description:
14 //
15 // A UTrap is a general trapezoid: The faces perpendicular to the
16 // z planes are trapezia, and their centres are not necessarily on
17 // a line parallel to the z axis.
18 //
19 // Note that of the 11 parameters described below, only 9 are really
20 // independent - a check for planarity is made in the calculation of the
21 // equation for each plane. If the planes are not parallel, a call to
22 // UException is made.
23 //
24 // pDz Half-length along the z-axis
25 // pTheta Polar angle of the line joining the centres of the faces
26 // at -/+pDz
27 // pPhi Azimuthal angle of the line joing the centre of the face at
28 // -pDz to the centre of the face at +pDz
29 // pDy1 Half-length along y of the face at -pDz
30 // pDx1 Half-length along x of the side at y=-pDy1 of the face at -pDz
31 // pDx2 Half-length along x of the side at y=+pDy1 of the face at -pDz
32 // pAlp1 Angle with respect to the y axis from the centre of the side
33 // at y=-pDy1 to the centre at y=+pDy1 of the face at -pDz
34 //
35 // pDy2 Half-length along y of the face at +pDz
36 // pDx3 Half-length along x of the side at y=-pDy2 of the face at +pDz
37 // pDx4 Half-length along x of the side at y=+pDy2 of the face at +pDz
38 // pAlp2 Angle with respect to the y axis from the centre of the side
39 // at y=-pDy2 to the centre at y=+pDy2 of the face at +pDz
40 //
41 // Member Data:
42 //
43 // fDz Half-length along the z axis
44 // fTthetaCphi = std::tan(pTheta)*std::cos(pPhi)
45 // fTthetaSphi = std::tan(pTheta)*std::sin(pPhi)
46 // These combinations are suitable for creation of the trapezoid corners
47 //
48 // fDy1 Half-length along y of the face at -fDz
49 // fDx1 Half-length along x of the side at y=-fDy1 of the face at -fDz
50 // fDx2 Half-length along x of the side at y=+fDy1 of the face at -fDz
51 // fTalpha1 Tan of Angle with respect to the y axis from the centre of
52 // the side at y=-fDy1 to the centre at y=+fDy1 of the face
53 // at -fDz
54 //
55 // fDy2 Half-length along y of the face at +fDz
56 // fDx3 Half-length along x of the side at y=-fDy2 of the face at +fDz
57 // fDx4 Half-length along x of the side at y=+fDy2 of the face at +fDz
58 // fTalpha2 Tan of Angle with respect to the y axis from the centre of
59 // the side at y=-fDy2 to the centre at y=+fDy2 of the face
60 // at +fDz
61 //
62 // UTrapSidePlane fPlanes[4] Plane equations of the faces not at +/-fDz
63 // NOTE: order is important !!!
64 //
65 // 12.02.13 Marek Gayer
66 // Created from original implementation in Geant4
67 // --------------------------------------------------------------------
68 
69 #ifndef UTrap_HH
70 #define UTrap_HH
71 
72 #include "VUSolid.hh"
73 
75 {
76  double a, b, c, d; // Normal Unit vector (a,b,c) and offset (d)
77  // => Ax+By+Cz+D=0
78 };
79 
80 class UTrap : public VUSolid
81 {
82 
83  public: // with description
84 
85  UTrap(const std::string& pName,
86  double pDz,
87  double pTheta, double pPhi,
88  double pDy1, double pDx1, double pDx2,
89  double pAlp1,
90  double pDy2, double pDx3, double pDx4,
91  double pAlp2);
92  //
93  // The most general constructor for UTrap which prepares plane
94  // equations and corner coordinates from parameters
95 
96  UTrap(const std::string& pName,
97  const UVector3 pt[8]) ;
98  //
99  // Prepares plane equations and parameters from corner coordinates
100 
101  UTrap(const std::string& pName,
102  double pZ,
103  double pY,
104  double pX, double pLTX);
105  //
106  // Constructor for Right Angular Wedge from STEP (assumes pLTX<=pX)
107 
108  UTrap(const std::string& pName,
109  double pDx1, double pDx2,
110  double pDy1, double pDy2,
111  double pDz);
112  //
113  // Constructor for UTrd
114 
115  UTrap(const std::string& pName,
116  double pDx, double pDy, double pDz,
117  double pAlpha, double pTheta, double pPhi);
118  //
119  // Constructor for UPara
120 
121  UTrap(const std::string& pName);
122  //
123  // Constructor for "nominal" UTrap whose parameters are to be Set
124  // by a UVPVParamaterisation later
125 
126  virtual ~UTrap() ;
127  //
128  // Destructor
129 
130  // Accessors
131 
132  inline double GetZHalfLength() const;
133  inline double GetYHalfLength1() const;
134  inline double GetXHalfLength1() const;
135  inline double GetXHalfLength2() const;
136  inline double GetTanAlpha1() const;
137  inline double GetYHalfLength2() const;
138  inline double GetXHalfLength3() const;
139  inline double GetXHalfLength4() const;
140  inline double GetTanAlpha2() const;
141  //
142  // Returns coordinates of Unit vector along straight
143  // line joining centers of -/+fDz planes
144 
145  inline UTrapSidePlane GetSidePlane(int n) const;
146  inline UVector3 GetSymAxis() const;
147 
148  // Modifiers
149 
150  void SetAllParameters(double pDz,
151  double pTheta,
152  double pPhi,
153  double pDy1,
154  double pDx1,
155  double pDx2,
156  double pAlp1,
157  double pDy2,
158  double pDx3,
159  double pDx4,
160  double pAlp2);
161 
162  void SetPlanes(const UVector3 pt[8]);
163 
164  // Methods for solid
165 
166  inline double Capacity();
167  inline double SurfaceArea();
168 
169  VUSolid::EnumInside Inside(const UVector3& p) const;
170 
171  UVector3 SurfaceNormal(const UVector3& p) const;
172 
173  bool Normal(const UVector3& aPoint, UVector3& aNormal) const;
174 
175  double DistanceToIn(const UVector3& p, const UVector3& v,
176  double aPstep = UUtils::kInfinity) const;
177 
178  double SafetyFromOutside(const UVector3& p, bool precise = false) const;
179 
180  double DistanceToOut(const UVector3& p,
181  const UVector3& v,
182  UVector3& aNormalVector,
183  bool& aConvex,
184  double aPstep = UUtils::kInfinity) const;
185 
186  double SafetyFromInside(const UVector3& p, bool precise = false) const;
187 
189 
190  UVector3 GetPointOnSurface() const;
191 
192  VUSolid* Clone() const;
193 
194  virtual void Extent(UVector3& aMin, UVector3& aMax) const;
195 
196  std::ostream& StreamInfo(std::ostream& os) const;
197 
198  // Visualisation functions
199 
200  public: // without description
201 
202  UTrap(const UTrap& rhs);
203  UTrap& operator=(const UTrap& rhs);
204  // Copy constructor and assignment operator.
205 
206  inline double GetThetaCphi() const;
207  inline double GetThetaSphi() const;
208 
209  protected: // with description
210 
211  bool MakePlanes();
212  bool MakePlane(const UVector3& p1,
213  const UVector3& p2,
214  const UVector3& p3,
215  const UVector3& p4,
216  UTrapSidePlane& plane) ;
217 
218  private:
219 
220  UVector3 ApproxSurfaceNormal(const UVector3& p) const;
221  // Algorithm for SurfaceNormal() following the original
222  // specification for points not on the surface
223 
224  inline double GetFaceArea(const UVector3& p1,
225  const UVector3& p2,
226  const UVector3& p3,
227  const UVector3& p4);
228  //
229  // Provided four corners of plane in clockwise fashion,
230  // it returns the area of finite face
231 
233  UVector3 p2, UVector3 p3,
234  double& area) const;
235  //
236  // Returns a random point on the surface of one of the faces
237 
238  void GetParametersList(int /*aNumber*/, double* /*aArray*/) const {}
239 
240 
241  void ComputeBBox(UBBox* /*aBox*/, bool /*aStore = false*/) {}
242 
243  private:
244 
246  double fDy1, fDx1, fDx2, fTalpha1;
247  double fDy2, fDx3, fDx4, fTalpha2;
249 
250  double fCubicVolume;
251  double fSurfaceArea;
252 
253 };
254 
255 #include "UTrap.icc"
256 
257 #endif
bool MakePlane(const UVector3 &p1, const UVector3 &p2, const UVector3 &p3, const UVector3 &p4, UTrapSidePlane &plane)
Definition: UTrap.cc:704
double fDx1
Definition: UTrap.hh:246
UVector3 SurfaceNormal(const UVector3 &p) const
std::ostream & StreamInfo(std::ostream &os) const
Definition: UTrap.cc:1404
double d
Definition: UTrap.hh:76
double fTthetaSphi
Definition: UTrap.hh:245
UVector3 GetPointOnPlane(UVector3 p0, UVector3 p1, UVector3 p2, UVector3 p3, double &area) const
Definition: UTrap.cc:1444
void SetAllParameters(double pDz, double pTheta, double pPhi, double pDy1, double pDx1, double pDx2, double pAlp1, double pDy2, double pDx3, double pDx4, double pAlp2)
Definition: UTrap.cc:492
bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const
Definition: UTrap.cc:822
double SafetyFromOutside(const UVector3 &p, bool precise=false) const
Definition: UTrap.cc:1066
void ComputeBBox(UBBox *, bool)
Definition: UTrap.hh:241
UVector3 ApproxSurfaceNormal(const UVector3 &p) const
Definition: UTrap.cc:903
Definition: UTrap.hh:80
double Capacity()
double fDx2
Definition: UTrap.hh:246
double fTalpha2
Definition: UTrap.hh:247
double fDz
Definition: UTrap.hh:245
double GetYHalfLength2() const
double GetXHalfLength2() const
UTrap & operator=(const UTrap &rhs)
Definition: UTrap.cc:449
double GetXHalfLength4() const
virtual ~UTrap()
Definition: UTrap.cc:420
static const double kInfinity
Definition: UUtils.hh:54
double fSurfaceArea
Definition: UTrap.hh:251
double GetTanAlpha2() const
UTrapSidePlane GetSidePlane(int n) const
UVector3 GetSymAxis() const
UGeometryType GetEntityType() const
Definition: UTrap.cc:1386
const G4double p2
const G4double p1
double fDx4
Definition: UTrap.hh:247
double fTthetaCphi
Definition: UTrap.hh:245
EnumInside
Definition: VUSolid.hh:23
const G4int n
UTrapSidePlane fPlanes[4]
Definition: UTrap.hh:248
UTrap(const std::string &pName, double pDz, double pTheta, double pPhi, double pDy1, double pDx1, double pDx2, double pAlp1, double pDy2, double pDx3, double pDx4, double pAlp2)
Definition: UTrap.cc:42
virtual void Extent(UVector3 &aMin, UVector3 &aMax) const
Definition: UTrap.cc:1548
double SafetyFromInside(const UVector3 &p, bool precise=false) const
Definition: UTrap.cc:1345
double GetXHalfLength1() const
void SetPlanes(const UVector3 pt[8])
Definition: UTrap.cc:534
double c
Definition: UTrap.hh:76
UVector3 GetPointOnSurface() const
Definition: UTrap.cc:1491
const G4double p0
double GetYHalfLength1() const
double fDy1
Definition: UTrap.hh:246
double fDy2
Definition: UTrap.hh:247
VUSolid * Clone() const
Definition: UTrap.cc:1395
VUSolid::EnumInside Inside(const UVector3 &p) const
Definition: UTrap.cc:781
double b
Definition: UTrap.hh:76
double fCubicVolume
Definition: UTrap.hh:250
std::string UGeometryType
Definition: UTypes.hh:39
double DistanceToIn(const UVector3 &p, const UVector3 &v, double aPstep=UUtils::kInfinity) const
Definition: UTrap.cc:944
double GetFaceArea(const UVector3 &p1, const UVector3 &p2, const UVector3 &p3, const UVector3 &p4)
double GetXHalfLength3() const
double DistanceToOut(const UVector3 &p, const UVector3 &v, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
Definition: UTrap.cc:1086
double GetThetaSphi() const
void GetParametersList(int, double *) const
Definition: UTrap.hh:238
double SurfaceArea()
double fTalpha1
Definition: UTrap.hh:246
double a
Definition: UTrap.hh:76
bool MakePlanes()
Definition: UTrap.cc:625
double GetTanAlpha1() const
double GetZHalfLength() const
double GetThetaCphi() const
double fDx3
Definition: UTrap.hh:247