[831] | 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,v 1.17 2006/10/19 15:33:37 gcosmo Exp $ |
---|
[1337] | 28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
[831] | 29 | // |
---|
| 30 | // |
---|
| 31 | // -------------------------------------------------------------------- |
---|
| 32 | // GEANT 4 class header file |
---|
| 33 | // |
---|
| 34 | // G4Trap |
---|
| 35 | // |
---|
| 36 | // Class description: |
---|
| 37 | // |
---|
| 38 | // A G4Trap is a general trapezoid: The faces perpendicular to the |
---|
| 39 | // z planes are trapezia, and their centres are not necessarily on |
---|
| 40 | // a line parallel to the z axis. |
---|
| 41 | // |
---|
| 42 | // Note that of the 11 parameters described below, only 9 are really |
---|
| 43 | // independent - a check for planarity is made in the calculation of the |
---|
| 44 | // equation for each plane. If the planes are not parallel, a call to |
---|
| 45 | // G4Exception is made. |
---|
| 46 | // |
---|
| 47 | // pDz Half-length along the z-axis |
---|
| 48 | // pTheta Polar angle of the line joining the centres of the faces |
---|
| 49 | // at -/+pDz |
---|
| 50 | // pPhi Azimuthal angle of the line joing the centre of the face at |
---|
| 51 | // -pDz to the centre of the face at +pDz |
---|
| 52 | // pDy1 Half-length along y of the face at -pDz |
---|
| 53 | // pDx1 Half-length along x of the side at y=-pDy1 of the face at -pDz |
---|
| 54 | // pDx2 Half-length along x of the side at y=+pDy1 of the face at -pDz |
---|
| 55 | // pAlp1 Angle with respect to the y axis from the centre of the side |
---|
| 56 | // at y=-pDy1 to the centre at y=+pDy1 of the face at -pDz |
---|
| 57 | // |
---|
| 58 | // pDy2 Half-length along y of the face at +pDz |
---|
| 59 | // pDx3 Half-length along x of the side at y=-pDy2 of the face at +pDz |
---|
| 60 | // pDx4 Half-length along x of the side at y=+pDy2 of the face at +pDz |
---|
| 61 | // pAlp2 Angle with respect to the y axis from the centre of the side |
---|
| 62 | // at y=-pDy2 to the centre at y=+pDy2 of the face at +pDz |
---|
| 63 | // |
---|
| 64 | // |
---|
| 65 | // Member Data: |
---|
| 66 | // |
---|
| 67 | // fDz Half-length along the z axis |
---|
| 68 | // fTthetaCphi = std::tan(pTheta)*std::cos(pPhi) |
---|
| 69 | // fTthetaSphi = std::tan(pTheta)*std::sin(pPhi) |
---|
| 70 | // These combinations are suitable for creation of the trapezoid corners |
---|
| 71 | // |
---|
| 72 | // fDy1 Half-length along y of the face at -fDz |
---|
| 73 | // fDx1 Half-length along x of the side at y=-fDy1 of the face at -fDz |
---|
| 74 | // fDx2 Half-length along x of the side at y=+fDy1 of the face at -fDz |
---|
| 75 | // fTalpha1 Tan of Angle with respect to the y axis from the centre of |
---|
| 76 | // the side at y=-fDy1 to the centre at y=+fDy1 of the face |
---|
| 77 | // at -fDz |
---|
| 78 | // |
---|
| 79 | // fDy2 Half-length along y of the face at +fDz |
---|
| 80 | // fDx3 Half-length along x of the side at y=-fDy2 of the face at +fDz |
---|
| 81 | // fDx4 Half-length along x of the side at y=+fDy2 of the face at +fDz |
---|
| 82 | // fTalpha2 Tan of Angle with respect to the y axis from the centre of |
---|
| 83 | // the side at y=-fDy2 to the centre at y=+fDy2 of the face |
---|
| 84 | // at +fDz |
---|
| 85 | // |
---|
| 86 | // TrapSidePlane fPlanes[4] Plane equations of the faces not at +/-fDz |
---|
| 87 | // NOTE: order is important !!! |
---|
| 88 | |
---|
| 89 | // History: |
---|
| 90 | // |
---|
| 91 | // 23.3.94 P.Kent: Old C++ code converted to tolerant geometry |
---|
| 92 | // 9.9.96 V.Grichine: Final modifications before to commit |
---|
| 93 | // 1.11.96 V.Grichine: Costructors for Right Angular Wedge from STEP, G4Trd/Para |
---|
| 94 | // 8.12.97 J.Allison: Added "nominal" contructor and method SetAllParameters. |
---|
| 95 | // -------------------------------------------------------------------- |
---|
| 96 | |
---|
| 97 | #ifndef G4Trap_HH |
---|
| 98 | #define G4Trap_HH |
---|
| 99 | |
---|
| 100 | #include "G4CSGSolid.hh" |
---|
| 101 | |
---|
| 102 | struct TrapSidePlane |
---|
| 103 | { |
---|
| 104 | G4double a,b,c,d; // Normal unit vector (a,b,c) and offset (d) |
---|
| 105 | // => Ax+By+Cz+D=0 |
---|
| 106 | }; |
---|
| 107 | |
---|
| 108 | class G4Trap : public G4CSGSolid |
---|
| 109 | { |
---|
| 110 | |
---|
| 111 | public: // with description |
---|
| 112 | |
---|
| 113 | G4Trap( const G4String& pName, |
---|
| 114 | G4double pDz, |
---|
| 115 | G4double pTheta, G4double pPhi, |
---|
| 116 | G4double pDy1, G4double pDx1, G4double pDx2, |
---|
| 117 | G4double pAlp1, |
---|
| 118 | G4double pDy2, G4double pDx3, G4double pDx4, |
---|
| 119 | G4double pAlp2 ); |
---|
| 120 | // |
---|
| 121 | // The most general constructor for G4Trap which prepares plane |
---|
| 122 | // equations and corner coordinates from parameters |
---|
| 123 | |
---|
| 124 | G4Trap( const G4String& pName, |
---|
| 125 | const G4ThreeVector pt[8] ) ; |
---|
| 126 | // |
---|
| 127 | // Prepares plane equations and parameters from corner coordinates |
---|
| 128 | |
---|
| 129 | G4Trap( const G4String& pName, |
---|
| 130 | G4double pZ, |
---|
| 131 | G4double pY, |
---|
| 132 | G4double pX, G4double pLTX ); |
---|
| 133 | // |
---|
| 134 | // Constructor for Right Angular Wedge from STEP (assumes pLTX<=pX) |
---|
| 135 | |
---|
| 136 | G4Trap( const G4String& pName, |
---|
| 137 | G4double pDx1, G4double pDx2, |
---|
| 138 | G4double pDy1, G4double pDy2, |
---|
| 139 | G4double pDz ); |
---|
| 140 | // |
---|
| 141 | // Constructor for G4Trd |
---|
| 142 | |
---|
| 143 | G4Trap(const G4String& pName, |
---|
| 144 | G4double pDx, G4double pDy, G4double pDz, |
---|
| 145 | G4double pAlpha, G4double pTheta, G4double pPhi ); |
---|
| 146 | // |
---|
| 147 | // Constructor for G4Para |
---|
| 148 | |
---|
| 149 | G4Trap( const G4String& pName ); |
---|
| 150 | // |
---|
| 151 | // Constructor for "nominal" G4Trap whose parameters are to be set |
---|
| 152 | // by a G4VPVParamaterisation later |
---|
| 153 | |
---|
| 154 | virtual ~G4Trap() ; |
---|
| 155 | // |
---|
| 156 | // Destructor |
---|
| 157 | |
---|
| 158 | // Accessors |
---|
| 159 | |
---|
| 160 | inline G4double GetZHalfLength() const; |
---|
| 161 | inline G4double GetYHalfLength1() const; |
---|
| 162 | inline G4double GetXHalfLength1() const; |
---|
| 163 | inline G4double GetXHalfLength2() const; |
---|
| 164 | inline G4double GetTanAlpha1() const; |
---|
| 165 | inline G4double GetYHalfLength2() const; |
---|
| 166 | inline G4double GetXHalfLength3() const; |
---|
| 167 | inline G4double GetXHalfLength4() const; |
---|
| 168 | inline G4double GetTanAlpha2() const; |
---|
| 169 | // |
---|
| 170 | // Returns coordinates of unit vector along straight |
---|
| 171 | // line joining centers of -/+fDz planes |
---|
| 172 | |
---|
| 173 | inline TrapSidePlane GetSidePlane( G4int n ) const; |
---|
| 174 | inline G4ThreeVector GetSymAxis() const; |
---|
| 175 | |
---|
| 176 | // Modifiers |
---|
| 177 | |
---|
| 178 | void SetAllParameters ( G4double pDz, |
---|
| 179 | G4double pTheta, |
---|
| 180 | G4double pPhi, |
---|
| 181 | G4double pDy1, |
---|
| 182 | G4double pDx1, |
---|
| 183 | G4double pDx2, |
---|
| 184 | G4double pAlp1, |
---|
| 185 | G4double pDy2, |
---|
| 186 | G4double pDx3, |
---|
| 187 | G4double pDx4, |
---|
| 188 | G4double pAlp2 ); |
---|
| 189 | |
---|
| 190 | // Methods for solid |
---|
| 191 | |
---|
| 192 | inline G4double GetCubicVolume(); |
---|
| 193 | inline G4double GetSurfaceArea(); |
---|
| 194 | |
---|
| 195 | void ComputeDimensions( G4VPVParameterisation* p, |
---|
| 196 | const G4int n, |
---|
| 197 | const G4VPhysicalVolume* pRep ); |
---|
| 198 | |
---|
| 199 | G4bool CalculateExtent( const EAxis pAxis, |
---|
| 200 | const G4VoxelLimits& pVoxelLimit, |
---|
| 201 | const G4AffineTransform& pTransform, |
---|
| 202 | G4double& pMin, G4double& pMax ) const; |
---|
| 203 | |
---|
| 204 | EInside Inside( const G4ThreeVector& p ) const; |
---|
| 205 | |
---|
| 206 | G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const; |
---|
| 207 | |
---|
| 208 | G4double DistanceToIn(const G4ThreeVector& p, const G4ThreeVector& v) const; |
---|
| 209 | |
---|
| 210 | G4double DistanceToIn( const G4ThreeVector& p ) const; |
---|
| 211 | |
---|
| 212 | G4double DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v, |
---|
| 213 | const G4bool calcNorm=false, |
---|
| 214 | G4bool *validNorm=0, G4ThreeVector *n=0) const; |
---|
| 215 | |
---|
| 216 | G4double DistanceToOut( const G4ThreeVector& p ) const; |
---|
| 217 | |
---|
| 218 | G4GeometryType GetEntityType() const; |
---|
| 219 | |
---|
| 220 | G4ThreeVector GetPointOnSurface() const; |
---|
| 221 | |
---|
| 222 | std::ostream& StreamInfo( std::ostream& os ) const; |
---|
| 223 | |
---|
| 224 | // Visualisation functions |
---|
| 225 | |
---|
| 226 | void DescribeYourselfTo ( G4VGraphicsScene& scene ) const; |
---|
| 227 | G4Polyhedron* CreatePolyhedron () const; |
---|
| 228 | G4NURBS* CreateNURBS () const; |
---|
| 229 | |
---|
| 230 | public: // without description |
---|
| 231 | |
---|
| 232 | G4Trap(__void__&); |
---|
| 233 | // Fake default constructor for usage restricted to direct object |
---|
| 234 | // persistency for clients requiring preallocation of memory for |
---|
| 235 | // persistifiable objects. |
---|
| 236 | |
---|
| 237 | protected: // with description |
---|
| 238 | |
---|
| 239 | G4bool MakePlanes(); |
---|
| 240 | G4bool MakePlane( const G4ThreeVector& p1, |
---|
| 241 | const G4ThreeVector& p2, |
---|
| 242 | const G4ThreeVector& p3, |
---|
| 243 | const G4ThreeVector& p4, |
---|
| 244 | TrapSidePlane& plane ) ; |
---|
| 245 | |
---|
| 246 | G4ThreeVectorList* |
---|
| 247 | CreateRotatedVertices( const G4AffineTransform& pTransform ) const; |
---|
| 248 | // |
---|
| 249 | // Creates the List of transformed vertices in the format required |
---|
| 250 | // for G4CSGSolid:: ClipCrossSection and ClipBetweenSections |
---|
| 251 | |
---|
| 252 | private: |
---|
| 253 | |
---|
| 254 | G4ThreeVector ApproxSurfaceNormal( const G4ThreeVector& p ) const; |
---|
| 255 | // Algorithm for SurfaceNormal() following the original |
---|
| 256 | // specification for points not on the surface |
---|
| 257 | |
---|
| 258 | inline G4double GetFaceArea(const G4ThreeVector& p1, |
---|
| 259 | const G4ThreeVector& p2, |
---|
| 260 | const G4ThreeVector& p3, |
---|
| 261 | const G4ThreeVector& p4); |
---|
| 262 | // |
---|
| 263 | // Provided four corners of plane in clockwise fashion, |
---|
| 264 | // it returns the area of finite face |
---|
| 265 | |
---|
| 266 | G4ThreeVector GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, |
---|
| 267 | G4ThreeVector p2, G4ThreeVector p3, |
---|
| 268 | G4double& area) const; |
---|
| 269 | // |
---|
| 270 | // Returns a random point on the surface of one of the faces |
---|
| 271 | |
---|
| 272 | private: |
---|
| 273 | |
---|
| 274 | G4double fDz,fTthetaCphi,fTthetaSphi; |
---|
| 275 | G4double fDy1,fDx1,fDx2,fTalpha1; |
---|
| 276 | G4double fDy2,fDx3,fDx4,fTalpha2; |
---|
| 277 | TrapSidePlane fPlanes[4]; |
---|
| 278 | |
---|
| 279 | }; |
---|
| 280 | |
---|
| 281 | #include "G4Trap.icc" |
---|
| 282 | |
---|
| 283 | #endif |
---|