Geant4  10.02.p02
G4Trap.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4Trap.hh 83851 2014-09-19 10:12:12Z gcosmo $
28 //
29 //
30 // --------------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 // G4Trap
34 //
35 // Class description:
36 //
37 // A G4Trap is a general trapezoid: The faces perpendicular to the
38 // z planes are trapezia, and their centres are not necessarily on
39 // a line parallel to the z axis.
40 //
41 // Note that of the 11 parameters described below, only 9 are really
42 // independent - a check for planarity is made in the calculation of the
43 // equation for each plane. If the planes are not parallel, a call to
44 // G4Exception is made.
45 //
46 // pDz Half-length along the z-axis
47 // pTheta Polar angle of the line joining the centres of the faces
48 // at -/+pDz
49 // pPhi Azimuthal angle of the line joing the centre of the face at
50 // -pDz to the centre of the face at +pDz
51 // pDy1 Half-length along y of the face at -pDz
52 // pDx1 Half-length along x of the side at y=-pDy1 of the face at -pDz
53 // pDx2 Half-length along x of the side at y=+pDy1 of the face at -pDz
54 // pAlp1 Angle with respect to the y axis from the centre of the side
55 // at y=-pDy1 to the centre at y=+pDy1 of the face at -pDz
56 //
57 // pDy2 Half-length along y of the face at +pDz
58 // pDx3 Half-length along x of the side at y=-pDy2 of the face at +pDz
59 // pDx4 Half-length along x of the side at y=+pDy2 of the face at +pDz
60 // pAlp2 Angle with respect to the y axis from the centre of the side
61 // at y=-pDy2 to the centre at y=+pDy2 of the face at +pDz
62 //
63 //
64 // Member Data:
65 //
66 // fDz Half-length along the z axis
67 // fTthetaCphi = std::tan(pTheta)*std::cos(pPhi)
68 // fTthetaSphi = std::tan(pTheta)*std::sin(pPhi)
69 // These combinations are suitable for creation of the trapezoid corners
70 //
71 // fDy1 Half-length along y of the face at -fDz
72 // fDx1 Half-length along x of the side at y=-fDy1 of the face at -fDz
73 // fDx2 Half-length along x of the side at y=+fDy1 of the face at -fDz
74 // fTalpha1 Tan of Angle with respect to the y axis from the centre of
75 // the side at y=-fDy1 to the centre at y=+fDy1 of the face
76 // at -fDz
77 //
78 // fDy2 Half-length along y of the face at +fDz
79 // fDx3 Half-length along x of the side at y=-fDy2 of the face at +fDz
80 // fDx4 Half-length along x of the side at y=+fDy2 of the face at +fDz
81 // fTalpha2 Tan of Angle with respect to the y axis from the centre of
82 // the side at y=-fDy2 to the centre at y=+fDy2 of the face
83 // at +fDz
84 //
85 // TrapSidePlane fPlanes[4] Plane equations of the faces not at +/-fDz
86 // NOTE: order is important !!!
87 
88 // History:
89 //
90 // 23.3.94 P.Kent: Old C++ code converted to tolerant geometry
91 // 9.9.96 V.Grichine: Final modifications before to commit
92 // 1.11.96 V.Grichine: Costructors for Right Angular Wedge from STEP, G4Trd/Para
93 // 8.12.97 J.Allison: Added "nominal" contructor and method SetAllParameters.
94 // --------------------------------------------------------------------
95 
96 #ifndef G4Trap_HH
97 #define G4Trap_HH
98 
99 #include "G4Types.hh"
100 
102 {
103  G4double a,b,c,d; // Normal unit vector (a,b,c) and offset (d)
104  // => Ax+By+Cz+D=0
105 };
106 
107 #if defined(G4GEOM_USE_USOLIDS)
108 #define G4GEOM_USE_UTRAP 1
109 #endif
110 
111 #if defined(G4GEOM_USE_UTRAP)
112  #define G4UTrap G4Trap
113  #include "G4UTrap.hh"
114 #else
115 
116 #include "G4CSGSolid.hh"
117 
118 class G4Trap : public G4CSGSolid
119 {
120 
121  public: // with description
122 
123  G4Trap( const G4String& pName,
124  G4double pDz,
125  G4double pTheta, G4double pPhi,
126  G4double pDy1, G4double pDx1, G4double pDx2,
127  G4double pAlp1,
128  G4double pDy2, G4double pDx3, G4double pDx4,
129  G4double pAlp2 );
130  //
131  // The most general constructor for G4Trap which prepares plane
132  // equations and corner coordinates from parameters
133 
134  G4Trap( const G4String& pName,
135  const G4ThreeVector pt[8] ) ;
136  //
137  // Prepares plane equations and parameters from corner coordinates
138 
139  G4Trap( const G4String& pName,
140  G4double pZ,
141  G4double pY,
142  G4double pX, G4double pLTX );
143  //
144  // Constructor for Right Angular Wedge from STEP (assumes pLTX<=pX)
145 
146  G4Trap( const G4String& pName,
147  G4double pDx1, G4double pDx2,
148  G4double pDy1, G4double pDy2,
149  G4double pDz );
150  //
151  // Constructor for G4Trd
152 
153  G4Trap(const G4String& pName,
154  G4double pDx, G4double pDy, G4double pDz,
155  G4double pAlpha, G4double pTheta, G4double pPhi );
156  //
157  // Constructor for G4Para
158 
159  G4Trap( const G4String& pName );
160  //
161  // Constructor for "nominal" G4Trap whose parameters are to be set
162  // by a G4VPVParamaterisation later
163 
164  virtual ~G4Trap() ;
165  //
166  // Destructor
167 
168  // Accessors
169 
170  inline G4double GetZHalfLength() const;
171  inline G4double GetYHalfLength1() const;
172  inline G4double GetXHalfLength1() const;
173  inline G4double GetXHalfLength2() const;
174  inline G4double GetTanAlpha1() const;
175  inline G4double GetYHalfLength2() const;
176  inline G4double GetXHalfLength3() const;
177  inline G4double GetXHalfLength4() const;
178  inline G4double GetTanAlpha2() const;
179  //
180  // Returns coordinates of unit vector along straight
181  // line joining centers of -/+fDz planes
182 
183  inline TrapSidePlane GetSidePlane( G4int n ) const;
184  inline G4ThreeVector GetSymAxis() const;
185 
186  // Modifiers
187 
188  void SetAllParameters ( G4double pDz,
189  G4double pTheta,
190  G4double pPhi,
191  G4double pDy1,
192  G4double pDx1,
193  G4double pDx2,
194  G4double pAlp1,
195  G4double pDy2,
196  G4double pDx3,
197  G4double pDx4,
198  G4double pAlp2 );
199 
200  // Methods for solid
201 
202  inline G4double GetCubicVolume();
203  inline G4double GetSurfaceArea();
204 
206  const G4int n,
207  const G4VPhysicalVolume* pRep );
208 
209  G4bool CalculateExtent( const EAxis pAxis,
210  const G4VoxelLimits& pVoxelLimit,
211  const G4AffineTransform& pTransform,
212  G4double& pMin, G4double& pMax ) const;
213 
214  EInside Inside( const G4ThreeVector& p ) const;
215 
216  G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const;
217 
218  G4double DistanceToIn(const G4ThreeVector& p, const G4ThreeVector& v) const;
219 
220  G4double DistanceToIn( const G4ThreeVector& p ) const;
221 
223  const G4bool calcNorm=false,
224  G4bool *validNorm=0, G4ThreeVector *n=0) const;
225 
226  G4double DistanceToOut( const G4ThreeVector& p ) const;
227 
229 
231 
232  G4VSolid* Clone() const;
233 
234  std::ostream& StreamInfo( std::ostream& os ) const;
235 
236  // Visualisation functions
237 
238  void DescribeYourselfTo ( G4VGraphicsScene& scene ) const;
239  G4Polyhedron* CreatePolyhedron () const;
240 
241  public: // without description
242 
243  G4Trap(__void__&);
244  // Fake default constructor for usage restricted to direct object
245  // persistency for clients requiring preallocation of memory for
246  // persistifiable objects.
247 
248  G4Trap(const G4Trap& rhs);
249  G4Trap& operator=(const G4Trap& rhs);
250  // Copy constructor and assignment operator.
251 
252  protected: // with description
253 
254  G4bool MakePlanes();
255  G4bool MakePlane( const G4ThreeVector& p1,
256  const G4ThreeVector& p2,
257  const G4ThreeVector& p3,
258  const G4ThreeVector& p4,
259  TrapSidePlane& plane ) ;
260 
262  CreateRotatedVertices( const G4AffineTransform& pTransform ) const;
263  //
264  // Creates the List of transformed vertices in the format required
265  // for G4CSGSolid:: ClipCrossSection and ClipBetweenSections
266 
267  private:
268 
270  // Algorithm for SurfaceNormal() following the original
271  // specification for points not on the surface
272 
273  inline G4double GetFaceArea(const G4ThreeVector& p1,
274  const G4ThreeVector& p2,
275  const G4ThreeVector& p3,
276  const G4ThreeVector& p4);
277  //
278  // Provided four corners of plane in clockwise fashion,
279  // it returns the area of finite face
280 
283  G4double& area) const;
284  //
285  // Returns a random point on the surface of one of the faces
286 
287  private:
288 
293 
294 };
295 
296 #include "G4Trap.icc"
297 
298 #endif
299 
300 #endif
G4double fDz
Definition: G4Trap.hh:289
G4double fDx1
Definition: G4Trap.hh:290
G4double b
Definition: G4Trap.hh:103
G4double GetXHalfLength4() const
G4double fTthetaCphi
Definition: G4Trap.hh:289
G4double GetSurfaceArea()
G4ThreeVector GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, G4ThreeVector p2, G4ThreeVector p3, G4double &area) const
Definition: G4Trap.cc:1858
G4GeometryType GetEntityType() const
Definition: G4Trap.cc:1800
TrapSidePlane GetSidePlane(G4int n) const
G4double GetYHalfLength2() const
CLHEP::Hep3Vector G4ThreeVector
G4Trap(const G4String &pName, G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pAlp1, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlp2)
Definition: G4Trap.cc:85
G4double GetZHalfLength() const
G4Trap & operator=(const G4Trap &rhs)
Definition: G4Trap.cc:572
G4double fDx2
Definition: G4Trap.hh:290
int G4int
Definition: G4Types.hh:78
G4double a
Definition: G4Trap.hh:103
G4double fTalpha2
Definition: G4Trap.hh:291
G4double GetXHalfLength2() const
G4double fDx4
Definition: G4Trap.hh:291
G4double GetTanAlpha2() const
G4double fDy2
Definition: G4Trap.hh:291
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
Definition: G4Trap.cc:1413
G4double GetXHalfLength1() const
virtual ~G4Trap()
Definition: G4Trap.cc:545
G4double GetXHalfLength3() const
G4VSolid * Clone() const
Definition: G4Trap.cc:1809
bool G4bool
Definition: G4Types.hh:79
G4double d
Definition: G4Trap.hh:103
void SetAllParameters(G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pAlp1, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlp2)
Definition: G4Trap.cc:604
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
Definition: G4Trap.cc:817
G4double fTalpha1
Definition: G4Trap.hh:290
std::vector< G4ThreeVector > G4ThreeVectorList
Definition: G4VSolid.hh:79
G4double GetFaceArea(const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3, const G4ThreeVector &p4)
const G4int n
G4ThreeVectorList * CreateRotatedVertices(const G4AffineTransform &pTransform) const
Definition: G4Trap.cc:1753
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
Definition: G4Trap.cc:805
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
Definition: G4Trap.cc:1150
G4double fTthetaSphi
Definition: G4Trap.hh:289
std::ostream & StreamInfo(std::ostream &os) const
Definition: G4Trap.cc:1818
EInside
Definition: geomdefs.hh:58
G4double fDx3
Definition: G4Trap.hh:291
EAxis
Definition: geomdefs.hh:54
G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector &p) const
Definition: G4Trap.cc:1230
G4double fDy1
Definition: G4Trap.hh:290
G4ThreeVector GetSymAxis() const
G4double c
Definition: G4Trap.hh:103
TrapSidePlane fPlanes[4]
Definition: G4Trap.hh:292
G4ThreeVector GetPointOnSurface() const
Definition: G4Trap.cc:1905
G4double GetCubicVolume()
G4double GetYHalfLength1() const
G4Polyhedron * CreatePolyhedron() const
Definition: G4Trap.cc:1961
double G4double
Definition: G4Types.hh:76
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
Definition: G4Trap.cc:1271
G4bool MakePlanes()
Definition: G4Trap.cc:651
G4bool MakePlane(const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3, const G4ThreeVector &p4, TrapSidePlane &plane)
Definition: G4Trap.cc:730
G4double GetTanAlpha1() const
EInside Inside(const G4ThreeVector &p) const
Definition: G4Trap.cc:1109
void DescribeYourselfTo(G4VGraphicsScene &scene) const
Definition: G4Trap.cc:1956