Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 69788 2013-05-15 12:06:57Z 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 "G4CSGSolid.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 class G4Trap : public G4CSGSolid
108 {
109 
110  public: // with description
111 
112  G4Trap( const G4String& pName,
113  G4double pDz,
114  G4double pTheta, G4double pPhi,
115  G4double pDy1, G4double pDx1, G4double pDx2,
116  G4double pAlp1,
117  G4double pDy2, G4double pDx3, G4double pDx4,
118  G4double pAlp2 );
119  //
120  // The most general constructor for G4Trap which prepares plane
121  // equations and corner coordinates from parameters
122 
123  G4Trap( const G4String& pName,
124  const G4ThreeVector pt[8] ) ;
125  //
126  // Prepares plane equations and parameters from corner coordinates
127 
128  G4Trap( const G4String& pName,
129  G4double pZ,
130  G4double pY,
131  G4double pX, G4double pLTX );
132  //
133  // Constructor for Right Angular Wedge from STEP (assumes pLTX<=pX)
134 
135  G4Trap( const G4String& pName,
136  G4double pDx1, G4double pDx2,
137  G4double pDy1, G4double pDy2,
138  G4double pDz );
139  //
140  // Constructor for G4Trd
141 
142  G4Trap(const G4String& pName,
143  G4double pDx, G4double pDy, G4double pDz,
144  G4double pAlpha, G4double pTheta, G4double pPhi );
145  //
146  // Constructor for G4Para
147 
148  G4Trap( const G4String& pName );
149  //
150  // Constructor for "nominal" G4Trap whose parameters are to be set
151  // by a G4VPVParamaterisation later
152 
153  virtual ~G4Trap() ;
154  //
155  // Destructor
156 
157  // Accessors
158 
159  inline G4double GetZHalfLength() const;
160  inline G4double GetYHalfLength1() const;
161  inline G4double GetXHalfLength1() const;
162  inline G4double GetXHalfLength2() const;
163  inline G4double GetTanAlpha1() const;
164  inline G4double GetYHalfLength2() const;
165  inline G4double GetXHalfLength3() const;
166  inline G4double GetXHalfLength4() const;
167  inline G4double GetTanAlpha2() const;
168  //
169  // Returns coordinates of unit vector along straight
170  // line joining centers of -/+fDz planes
171 
172  inline TrapSidePlane GetSidePlane( G4int n ) const;
173  inline G4ThreeVector GetSymAxis() const;
174 
175  // Modifiers
176 
177  void SetAllParameters ( G4double pDz,
178  G4double pTheta,
179  G4double pPhi,
180  G4double pDy1,
181  G4double pDx1,
182  G4double pDx2,
183  G4double pAlp1,
184  G4double pDy2,
185  G4double pDx3,
186  G4double pDx4,
187  G4double pAlp2 );
188 
189  // Methods for solid
190 
191  inline G4double GetCubicVolume();
192  inline G4double GetSurfaceArea();
193 
195  const G4int n,
196  const G4VPhysicalVolume* pRep );
197 
198  G4bool CalculateExtent( const EAxis pAxis,
199  const G4VoxelLimits& pVoxelLimit,
200  const G4AffineTransform& pTransform,
201  G4double& pMin, G4double& pMax ) const;
202 
203  EInside Inside( const G4ThreeVector& p ) const;
204 
205  G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const;
206 
207  G4double DistanceToIn(const G4ThreeVector& p, const G4ThreeVector& v) const;
208 
209  G4double DistanceToIn( const G4ThreeVector& p ) const;
210 
212  const G4bool calcNorm=false,
213  G4bool *validNorm=0, G4ThreeVector *n=0) const;
214 
215  G4double DistanceToOut( const G4ThreeVector& p ) const;
216 
218 
220 
221  G4VSolid* Clone() const;
222 
223  std::ostream& StreamInfo( std::ostream& os ) const;
224 
225  // Visualisation functions
226 
227  void DescribeYourselfTo ( G4VGraphicsScene& scene ) const;
228  G4Polyhedron* CreatePolyhedron () const;
229  G4NURBS* CreateNURBS () const;
230 
231  public: // without description
232 
233  G4Trap(__void__&);
234  // Fake default constructor for usage restricted to direct object
235  // persistency for clients requiring preallocation of memory for
236  // persistifiable objects.
237 
238  G4Trap(const G4Trap& rhs);
239  G4Trap& operator=(const G4Trap& rhs);
240  // Copy constructor and assignment operator.
241 
242  protected: // with description
243 
244  G4bool MakePlanes();
245  G4bool MakePlane( const G4ThreeVector& p1,
246  const G4ThreeVector& p2,
247  const G4ThreeVector& p3,
248  const G4ThreeVector& p4,
249  TrapSidePlane& plane ) ;
250 
252  CreateRotatedVertices( const G4AffineTransform& pTransform ) const;
253  //
254  // Creates the List of transformed vertices in the format required
255  // for G4CSGSolid:: ClipCrossSection and ClipBetweenSections
256 
257  private:
258 
259  G4ThreeVector ApproxSurfaceNormal( const G4ThreeVector& p ) const;
260  // Algorithm for SurfaceNormal() following the original
261  // specification for points not on the surface
262 
263  inline G4double GetFaceArea(const G4ThreeVector& p1,
264  const G4ThreeVector& p2,
265  const G4ThreeVector& p3,
266  const G4ThreeVector& p4);
267  //
268  // Provided four corners of plane in clockwise fashion,
269  // it returns the area of finite face
270 
271  G4ThreeVector GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1,
273  G4double& area) const;
274  //
275  // Returns a random point on the surface of one of the faces
276 
277  private:
278 
279  G4double fDz,fTthetaCphi,fTthetaSphi;
280  G4double fDy1,fDx1,fDx2,fTalpha1;
281  G4double fDy2,fDx3,fDx4,fTalpha2;
282  TrapSidePlane fPlanes[4];
283 
284 };
285 
286 #include "G4Trap.icc"
287 
288 #endif