File indexing completed on 2026-10-03 09:10:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 struct Intersection
0034 {
0035 G4double phi ;
0036 G4double u ;
0037 G4ThreeVector xx ;
0038 G4double distance ;
0039 G4int areacode ;
0040 G4bool isvalid ;
0041
0042 };
0043
0044 inline
0045 G4bool DistanceSort( const Intersection& a, const Intersection& b)
0046 {
0047 return a.distance < b.distance ;
0048 }
0049
0050 inline
0051 G4bool EqualIntersection( const Intersection& a, const Intersection& b)
0052 {
0053 return ( ( a.xx - b.xx ).mag() < 1E-9*CLHEP::mm ) ;
0054 }
0055
0056
0057
0058
0059 inline
0060 G4double G4VTwistSurface::DistanceToPlaneWithV(const G4ThreeVector& p,
0061 const G4ThreeVector& v,
0062 const G4ThreeVector& x0,
0063 const G4ThreeVector& n0,
0064 G4ThreeVector& xx)
0065 {
0066 G4double q = n0 * v;
0067 G4double t = kInfinity;
0068 if (q != 0.0) { t = (n0 * (x0 - p)) / q; }
0069 xx = p + t * v;
0070 return t;
0071 }
0072
0073
0074
0075
0076 inline
0077 G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector& p,
0078 const G4ThreeVector& x0,
0079 const G4ThreeVector& n0,
0080 G4ThreeVector& xx)
0081 {
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 G4double t;
0102 G4ThreeVector n = n0.unit();
0103 t = n * (p - x0);
0104 xx = p - t * n;
0105 return t;
0106 }
0107
0108
0109
0110
0111 inline
0112 G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector& p,
0113 const G4ThreeVector& x0,
0114 const G4ThreeVector& t1,
0115 const G4ThreeVector& t2,
0116 G4ThreeVector& xx,
0117 G4ThreeVector& n)
0118 {
0119
0120
0121
0122
0123
0124
0125 n = (t1.cross(t2)).unit();
0126 return DistanceToPlane(p, x0, n, xx);
0127 }
0128
0129
0130
0131
0132 inline
0133 G4double G4VTwistSurface::DistanceToLine(const G4ThreeVector& p,
0134 const G4ThreeVector& x0,
0135 const G4ThreeVector& d,
0136 G4ThreeVector& xx)
0137 {
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161 G4double t;
0162 G4ThreeVector dir = d.unit();
0163 t = - dir * (x0 - p);
0164 xx = x0 + t * dir;
0165
0166 G4ThreeVector dist = xx - p;
0167 return dist.mag();
0168 }
0169
0170
0171
0172
0173 inline
0174 G4bool G4VTwistSurface::IsAxis0(G4int areacode) const
0175 {
0176 return (areacode & sAxis0) != 0;
0177 }
0178
0179
0180
0181
0182 inline
0183 G4bool G4VTwistSurface::IsAxis1(G4int areacode) const
0184 {
0185 return (areacode & sAxis1) != 0;
0186 }
0187
0188
0189
0190
0191 inline
0192 G4bool G4VTwistSurface::IsOutside(G4int areacode) const
0193 {
0194 return (areacode & sInside) == 0;
0195 }
0196
0197
0198
0199
0200 inline
0201 G4bool G4VTwistSurface::IsInside(G4int areacode, G4bool testbitmode) const
0202 {
0203 if ((areacode & sInside) != 0)
0204 {
0205 if (testbitmode) { return true; }
0206 if (((areacode & sBoundary) == 0)
0207 && ((areacode & sCorner) == 0)) { return true; }
0208 }
0209 return false;
0210 }
0211
0212
0213
0214
0215 inline
0216 G4bool G4VTwistSurface::IsBoundary(G4int areacode, G4bool testbitmode) const
0217 {
0218 if ((areacode & sBoundary) == sBoundary)
0219 {
0220 if (testbitmode) { return true; }
0221 if ((areacode & sInside) == sInside) { return true; }
0222 }
0223 return false;
0224 }
0225
0226
0227
0228
0229 inline
0230 G4bool G4VTwistSurface::IsCorner(G4int areacode, G4bool testbitmode) const
0231 {
0232 if ((areacode & sCorner) == sCorner)
0233 {
0234 if (testbitmode) { return true; }
0235 if ((areacode & sInside) == sInside) { return true; }
0236 }
0237 return false;
0238 }
0239
0240
0241
0242
0243 inline
0244 G4int G4VTwistSurface::GetAxisType(G4int areacode, G4int whichaxis) const
0245 {
0246 G4int axiscode = areacode & sAxisMask & whichaxis;
0247
0248 if (axiscode == (sAxisX & sAxis0) ||
0249 axiscode == (sAxisX & sAxis1))
0250 {
0251 return sAxisX;
0252 }
0253 if (axiscode == (sAxisY & sAxis0) ||
0254 axiscode == (sAxisY & sAxis1))
0255 {
0256 return sAxisY;
0257 }
0258 if (axiscode == (sAxisZ & sAxis0) ||
0259 axiscode == (sAxisZ & sAxis1))
0260 {
0261 return sAxisZ;
0262 }
0263 if (axiscode == (sAxisRho & sAxis0) ||
0264 axiscode == (sAxisRho & sAxis1))
0265 {
0266 return sAxisRho;
0267 }
0268 if (axiscode == (sAxisPhi & sAxis0) ||
0269 axiscode == (sAxisPhi & sAxis1))
0270 {
0271 return sAxisPhi;
0272 }
0273
0274 std::ostringstream message;
0275 message << "Configuration not supported." << G4endl
0276 << " areacode = " << areacode;
0277 G4Exception("G4VTwistSurface::GetAxisType()","GeomSolids0001",
0278 FatalException, message);
0279 return 1;
0280 }
0281
0282
0283
0284
0285 inline
0286 G4ThreeVector G4VTwistSurface::ComputeGlobalPoint(const G4ThreeVector& lp) const
0287 {
0288 return fRot * G4ThreeVector(lp) + fTrans;
0289 }
0290
0291
0292
0293
0294 inline
0295 G4ThreeVector G4VTwistSurface::ComputeLocalPoint(const G4ThreeVector& gp) const
0296 {
0297 return fRot.inverse() * ( G4ThreeVector(gp) - fTrans ) ;
0298 }
0299
0300
0301
0302
0303 inline G4ThreeVector
0304 G4VTwistSurface::ComputeGlobalDirection(const G4ThreeVector& lp) const
0305 {
0306 return fRot * G4ThreeVector(lp);
0307 }
0308
0309
0310
0311
0312 inline G4ThreeVector
0313 G4VTwistSurface::ComputeLocalDirection(const G4ThreeVector& gp) const
0314 {
0315 return fRot.inverse() * G4ThreeVector(gp);
0316 }
0317
0318
0319
0320
0321 inline void
0322 G4VTwistSurface::SetNeighbours(G4VTwistSurface* ax0min, G4VTwistSurface* ax1min,
0323 G4VTwistSurface* ax0max, G4VTwistSurface* ax1max)
0324 {
0325 fNeighbours[0] = ax0min;
0326 fNeighbours[1] = ax1min;
0327 fNeighbours[2] = ax0max;
0328 fNeighbours[3] = ax1max;
0329 }
0330
0331
0332
0333
0334 inline G4int
0335 G4VTwistSurface::GetNeighbours(G4int areacode, G4VTwistSurface** surfaces)
0336 {
0337
0338 G4int sAxis0Min = sAxis0 & sAxisMin ;
0339 G4int sAxis1Min = sAxis1 & sAxisMin ;
0340 G4int sAxis0Max = sAxis0 & sAxisMax ;
0341 G4int sAxis1Max = sAxis1 & sAxisMax ;
0342
0343 G4int i = 0;
0344
0345 if ( (areacode & sAxis0Min ) == sAxis0Min )
0346 {
0347 surfaces[i] = fNeighbours[0] ;
0348 ++i ;
0349 }
0350
0351 if ( ( areacode & sAxis1Min ) == sAxis1Min )
0352 {
0353 surfaces[i] = fNeighbours[1] ;
0354 ++i ;
0355 if ( i == 2 ) { return i ; }
0356 }
0357
0358 if ( ( areacode & sAxis0Max ) == sAxis0Max )
0359 {
0360 surfaces[i] = fNeighbours[2] ;
0361 ++i ;
0362 if ( i == 2 ) { return i ; }
0363 }
0364
0365 if ( ( areacode & sAxis1Max ) == sAxis1Max )
0366 {
0367 surfaces[i] = fNeighbours[3] ;
0368 ++i ;
0369 if ( i == 2 ) { return i ; }
0370 }
0371
0372 return i ;
0373 }
0374
0375
0376
0377
0378 inline
0379 G4ThreeVector G4VTwistSurface::GetCorner(G4int areacode) const
0380 {
0381 if ((areacode & sCorner) == 0)
0382 {
0383 std::ostringstream message;
0384 message << "Area code must represent corner." << G4endl
0385 << " areacode = " << areacode;
0386 G4Exception("G4VTwistSurface::GetCorner()","GeomSolids0002",
0387 FatalException, message);
0388 }
0389
0390 if ((areacode & sC0Min1Min) == sC0Min1Min)
0391 {
0392 return fCorners[0];
0393 }
0394 if ((areacode & sC0Max1Min) == sC0Max1Min)
0395 {
0396 return fCorners[1];
0397 }
0398 if ((areacode & sC0Max1Max) == sC0Max1Max)
0399 {
0400 return fCorners[2];
0401 }
0402 if ((areacode & sC0Min1Max) == sC0Min1Max)
0403 {
0404 return fCorners[3];
0405 }
0406
0407 std::ostringstream message;
0408 message << "Configuration not supported." << G4endl
0409 << " areacode = " << areacode;
0410 G4Exception("G4VTwistSurface::GetCorner()", "GeomSolids0001",
0411 FatalException, message);
0412
0413 return fCorners[0];
0414 }