00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 inline
00045 G4double G4VTwistSurface::DistanceToPlaneWithV(const G4ThreeVector &p,
00046 const G4ThreeVector &v,
00047 const G4ThreeVector &x0,
00048 const G4ThreeVector &n0,
00049 G4ThreeVector &xx)
00050 {
00051 G4double q = n0 * v;
00052 G4double t = kInfinity;
00053 if (q) { t = (n0 * (x0 - p)) / q; }
00054 xx = p + t * v;
00055 return t;
00056 }
00057
00058
00059
00060
00061 inline
00062 G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector &p,
00063 const G4ThreeVector &x0,
00064 const G4ThreeVector &n0,
00065 G4ThreeVector &xx)
00066 {
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 G4double t;
00087 G4ThreeVector n = n0.unit();
00088 t = n * (p - x0);
00089 xx = p - t * n;
00090 return t;
00091 }
00092
00093
00094
00095
00096 inline
00097 G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector &p,
00098 const G4ThreeVector &x0,
00099 const G4ThreeVector &t1,
00100 const G4ThreeVector &t2,
00101 G4ThreeVector &xx,
00102 G4ThreeVector &n)
00103 {
00104
00105
00106
00107
00108
00109
00110 n = (t1.cross(t2)).unit();
00111 return DistanceToPlane(p, x0, n, xx);
00112 }
00113
00114
00115
00116
00117 inline
00118 G4double G4VTwistSurface::DistanceToLine(const G4ThreeVector &p,
00119 const G4ThreeVector &x0,
00120 const G4ThreeVector &d,
00121 G4ThreeVector &xx)
00122 {
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 G4double t;
00147 G4ThreeVector dir = d.unit();
00148 t = - dir * (x0 - p);
00149 xx = x0 + t * dir;
00150
00151 G4ThreeVector dist = xx - p;
00152 return dist.mag();
00153 }
00154
00155
00156
00157
00158 inline
00159 G4bool G4VTwistSurface::IsAxis0(G4int areacode) const
00160 {
00161 if (areacode & sAxis0) return true;
00162 return false;
00163 }
00164
00165
00166
00167
00168 inline
00169 G4bool G4VTwistSurface::IsAxis1(G4int areacode) const
00170 {
00171 if (areacode & sAxis1) return true;
00172 return false;
00173 }
00174
00175
00176
00177
00178 inline
00179 G4bool G4VTwistSurface::IsOutside(G4int areacode) const
00180 {
00181 if (areacode & sInside) return false;
00182 return true;
00183 }
00184
00185
00186
00187
00188 inline
00189 G4bool G4VTwistSurface::IsInside(G4int areacode, G4bool testbitmode) const
00190 {
00191 if (areacode & sInside) {
00192 if (testbitmode) {
00193 return true;
00194 } else {
00195 if (!((areacode & sBoundary) || (areacode & sCorner))) return true;
00196 }
00197 }
00198 return false;
00199 }
00200
00201
00202
00203
00204 inline
00205 G4bool G4VTwistSurface::IsBoundary(G4int areacode, G4bool testbitmode) const
00206 {
00207 if ((areacode & sBoundary) == sBoundary) {
00208 if (testbitmode) {
00209 return true;
00210 } else {
00211 if ((areacode & sInside) == sInside) return true;
00212 }
00213 }
00214 return false;
00215 }
00216
00217
00218
00219
00220 inline
00221 G4bool G4VTwistSurface::IsCorner(G4int areacode, G4bool testbitmode) const
00222 {
00223 if ((areacode & sCorner) == sCorner) {
00224 if (testbitmode) {
00225 return true;
00226 } else {
00227 if ((areacode & sInside) == sInside) return true;
00228 }
00229 }
00230 return false;
00231 }
00232
00233
00234
00235
00236 inline
00237 G4int G4VTwistSurface::GetAxisType(G4int areacode, G4int whichaxis) const
00238 {
00239 G4int axiscode = areacode & sAxisMask & whichaxis;
00240
00241 if (axiscode == (sAxisX & sAxis0) ||
00242 axiscode == (sAxisX & sAxis1)) {
00243 return sAxisX;
00244 } else if (axiscode == (sAxisY & sAxis0) ||
00245 axiscode == (sAxisY & sAxis1)) {
00246 return sAxisY;
00247 } else if (axiscode == (sAxisZ & sAxis0) ||
00248 axiscode == (sAxisZ & sAxis1)) {
00249 return sAxisZ;
00250 } else if (axiscode == (sAxisRho & sAxis0) ||
00251 axiscode == (sAxisRho & sAxis1)) {
00252 return sAxisRho;
00253 } else if (axiscode == (sAxisPhi & sAxis0) ||
00254 axiscode == (sAxisPhi & sAxis1)) {
00255 return sAxisPhi;
00256 } else {
00257 std::ostringstream message;
00258 message << "Configuration not supported." << G4endl
00259 << " areacode = " << areacode;
00260 G4Exception("G4VTwistSurface::GetAxisType()","GeomSolids0001",
00261 FatalException, message);
00262 }
00263 return 1;
00264 }
00265
00266
00267
00268
00269 inline
00270 G4ThreeVector G4VTwistSurface::ComputeGlobalPoint(const G4ThreeVector &lp) const
00271 {
00272 return fRot * G4ThreeVector(lp) + fTrans;
00273 }
00274
00275
00276
00277
00278 inline
00279 G4ThreeVector G4VTwistSurface::ComputeLocalPoint(const G4ThreeVector &gp) const
00280 {
00281 return fRot.inverse() * ( G4ThreeVector(gp) - fTrans ) ;
00282 }
00283
00284
00285
00286
00287 inline
00288 G4ThreeVector G4VTwistSurface::ComputeGlobalDirection(const G4ThreeVector &lp) const
00289 {
00290 return fRot * G4ThreeVector(lp);
00291 }
00292
00293
00294
00295
00296 inline
00297 G4ThreeVector G4VTwistSurface::ComputeLocalDirection(const G4ThreeVector &gp) const
00298 {
00299 return fRot.inverse() * G4ThreeVector(gp);
00300 }
00301
00302
00303
00304
00305 inline
00306 void G4VTwistSurface::SetNeighbours(G4VTwistSurface* axis0min, G4VTwistSurface* axis1min,
00307 G4VTwistSurface* axis0max, G4VTwistSurface* axis1max)
00308 {
00309 fNeighbours[0] = axis0min;
00310 fNeighbours[1] = axis1min;
00311 fNeighbours[2] = axis0max;
00312 fNeighbours[3] = axis1max;
00313 }
00314
00315
00316
00317
00318 inline
00319 G4int G4VTwistSurface::GetNeighbours(G4int areacode, G4VTwistSurface** surfaces)
00320 {
00321
00322 int sAxis0Min = sAxis0 & sAxisMin ;
00323 int sAxis1Min = sAxis1 & sAxisMin ;
00324 int sAxis0Max = sAxis0 & sAxisMax ;
00325 int sAxis1Max = sAxis1 & sAxisMax ;
00326
00327 G4int i = 0;
00328
00329 if ( (areacode & sAxis0Min ) == sAxis0Min ) {
00330 surfaces[i] = fNeighbours[0] ;
00331 i++ ;
00332 }
00333
00334 if ( ( areacode & sAxis1Min ) == sAxis1Min ) {
00335 surfaces[i] = fNeighbours[1] ;
00336 i++ ;
00337 if ( i == 2 ) return i ;
00338 }
00339
00340 if ( ( areacode & sAxis0Max ) == sAxis0Max ) {
00341 surfaces[i] = fNeighbours[2] ;
00342 i++ ;
00343 if ( i == 2 ) return i ;
00344 }
00345
00346 if ( ( areacode & sAxis1Max ) == sAxis1Max ) {
00347 surfaces[i] = fNeighbours[3] ;
00348 i++ ;
00349 if ( i == 2 ) return i ;
00350 }
00351
00352 return i ;
00353 }
00354
00355
00356
00357
00358 inline
00359 G4ThreeVector G4VTwistSurface::GetCorner(G4int areacode) const
00360 {
00361 if (!(areacode & sCorner)){
00362 std::ostringstream message;
00363 message << "Area code must represent corner." << G4endl
00364 << " areacode = " << areacode;
00365 G4Exception("G4VTwistSurface::GetCorner()","GeomSolids0002",
00366 FatalException, message);
00367 }
00368
00369 if ((areacode & sC0Min1Min) == sC0Min1Min) {
00370 return fCorners[0];
00371 } else if ((areacode & sC0Max1Min) == sC0Max1Min) {
00372 return fCorners[1];
00373 } else if ((areacode & sC0Max1Max) == sC0Max1Max) {
00374 return fCorners[2];
00375 } else if ((areacode & sC0Min1Max) == sC0Min1Max) {
00376 return fCorners[3];
00377 } else {
00378 std::ostringstream message;
00379 message << "Configuration not supported." << G4endl
00380 << " areacode = " << areacode;
00381 G4Exception("G4VTwistSurface::GetCorner()", "GeomSolids0001",
00382 FatalException, message);
00383 }
00384 return fCorners[0];
00385 }