305 if (
true)
return bbox.
CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
309 return exist = pMin < pMax;
322 const G4int NSTEPS = 24;
324 G4int ksteps = (dphi <= astep) ? 1 : (
G4int)((dphi-deg)/astep) + 1;
327 G4double sinHalf = std::sin(0.5*ang);
328 G4double cosHalf = std::cos(0.5*ang);
329 G4double sinStep = 2.*sinHalf*cosHalf;
330 G4double cosStep = 1. - 2.*sinHalf*sinHalf;
336 if (rmin1 == 0 && rmin2 == 0 && dphi == twopi)
342 for (
G4int k=0; k<NSTEPS; ++k)
344 baseA[k].set(rext1*cosCur,rext1*sinCur,-dz);
345 baseB[k].set(rext2*cosCur,rext2*sinCur, dz);
348 sinCur = sinCur*cosStep + cosCur*sinStep;
349 cosCur = cosCur*cosStep - sinTmp*sinStep;
351 std::vector<const G4ThreeVectorList *> polygons(2);
352 polygons[0] = &baseA;
353 polygons[1] = &baseB;
363 G4double sinCur = sinStart*cosHalf + cosStart*sinHalf;
364 G4double cosCur = cosStart*cosHalf - sinStart*sinHalf;
368 for (
G4int k=0; k<ksteps+2; ++k) pols[k].resize(4);
369 pols[0][0].set(rmin2*cosStart,rmin2*sinStart, dz);
370 pols[0][1].set(rmin1*cosStart,rmin1*sinStart,-dz);
371 pols[0][2].set(rmax1*cosStart,rmax1*sinStart,-dz);
372 pols[0][3].set(rmax2*cosStart,rmax2*sinStart, dz);
373 for (
G4int k=1; k<ksteps+1; ++k)
375 pols[k][0].set(rmin2*cosCur,rmin2*sinCur, dz);
376 pols[k][1].set(rmin1*cosCur,rmin1*sinCur,-dz);
377 pols[k][2].set(rext1*cosCur,rext1*sinCur,-dz);
378 pols[k][3].set(rext2*cosCur,rext2*sinCur, dz);
381 sinCur = sinCur*cosStep + cosCur*sinStep;
382 cosCur = cosCur*cosStep - sinTmp*sinStep;
384 pols[ksteps+1][0].set(rmin2*cosEnd,rmin2*sinEnd, dz);
385 pols[ksteps+1][1].set(rmin1*cosEnd,rmin1*sinEnd,-dz);
386 pols[ksteps+1][2].set(rmax1*cosEnd,rmax1*sinEnd,-dz);
387 pols[ksteps+1][3].set(rmax2*cosEnd,rmax2*sinEnd, dz);
390 std::vector<const G4ThreeVectorList *> polygons;
391 polygons.resize(ksteps+2);
392 for (
G4int k=0; k<ksteps+2; ++k) polygons[k] = &pols[k];
407 G4int noSurfaces = 0;
410 G4double distSPhi = kInfinity, distEPhi = kInfinity;
411 G4double tanRMin, secRMin, pRMin, widRMin;
412 G4double tanRMax, secRMax, pRMax, widRMax;
417 distZ = std::fabs(std::fabs(p.
z()) - fDz);
418 rho = std::sqrt(p.
x()*p.
x() + p.
y()*p.
y());
420 tanRMin = (fRmin2 - fRmin1)*0.5/fDz;
421 secRMin = std::sqrt(1 + tanRMin*tanRMin);
422 pRMin = rho - p.
z()*tanRMin;
423 widRMin = fRmin2 - fDz*tanRMin;
424 distRMin = std::fabs(pRMin - widRMin)/secRMin;
426 tanRMax = (fRmax2 - fRmax1)*0.5/fDz;
427 secRMax = std::sqrt(1+tanRMax*tanRMax);
428 pRMax = rho - p.
z()*tanRMax;
429 widRMax = fRmax2 - fDz*tanRMax;
430 distRMax = std::fabs(pRMax - widRMax)/secRMax;
436 pPhi = std::atan2(p.
y(),p.
x());
438 if (pPhi < fSPhi-halfCarTolerance) { pPhi += twopi; }
439 else if (pPhi > fSPhi+fDPhi+halfCarTolerance) { pPhi -= twopi; }
441 distSPhi = std::fabs( pPhi - fSPhi );
442 distEPhi = std::fabs( pPhi - fSPhi - fDPhi );
444 else if( ((fRmin1) == 0.0) || ((fRmin2) == 0.0) )
452 if ( rho > halfCarTolerance )
454 nR =
G4ThreeVector(p.
x()/rho/secRMax, p.
y()/rho/secRMax, -tanRMax/secRMax);
455 if ((fRmin1 != 0.0) || (fRmin2 != 0.0))
457 nr =
G4ThreeVector(-p.
x()/rho/secRMin,-p.
y()/rho/secRMin,tanRMin/secRMin);
461 if( distRMax <= halfCarTolerance )
466 if( ((fRmin1 != 0.0) || (fRmin2 != 0.0)) && (distRMin <= halfCarTolerance) )
473 if (distSPhi <= halfAngTolerance)
478 if (distEPhi <= halfAngTolerance)
484 if (distZ <= halfCarTolerance)
487 if ( p.
z() >= 0.) { sumnorm += nZ; }
488 else { sumnorm -= nZ; }
490 if ( noSurfaces == 0 )
493 G4Exception(
"G4Cons::SurfaceNormal(p)",
"GeomSolids1002",
496 norm = ApproxSurfaceNormal(p);
498 else if ( noSurfaces == 1 ) { norm = sumnorm; }
499 else { norm = sumnorm.
unit(); }
651 const G4double dRmax = 50*(fRmax1+fRmax2);
653 G4double tanRMax,secRMax,rMaxAv,rMaxOAv ;
654 G4double tanRMin,secRMin,rMinAv,rMinOAv ;
657 G4double tolORMin,tolORMin2,tolIRMin,tolIRMin2 ;
658 G4double tolORMax2,tolIRMax,tolIRMax2 ;
661 G4double Dist,sd,xi,yi,zi,ri=0.,risec,rhoi2,cosPsi ;
671 tanRMin = (fRmin2 - fRmin1)*0.5/fDz ;
672 secRMin = std::sqrt(1.0 + tanRMin*tanRMin) ;
673 rMinAv = (fRmin1 + fRmin2)*0.5 ;
675 if (rMinAv > halfRadTolerance)
677 rMinOAv = rMinAv - halfRadTolerance ;
683 tanRMax = (fRmax2 - fRmax1)*0.5/fDz ;
684 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
685 rMaxAv = (fRmax1 + fRmax2)*0.5 ;
686 rMaxOAv = rMaxAv + halfRadTolerance ;
690 tolIDz = fDz - halfCarTolerance ;
691 tolODz = fDz + halfCarTolerance ;
693 if (std::fabs(p.
z()) >= tolIDz)
695 if ( p.
z()*v.
z() < 0 )
697 sd = (std::fabs(p.
z()) - fDz)/std::fabs(v.
z()) ;
699 if( sd < 0.0 ) { sd = 0.0; }
701 xi = p.
x() + sd*v.
x() ;
702 yi = p.
y() + sd*v.
y() ;
703 rhoi2 = xi*xi + yi*yi ;
710 tolORMin = fRmin1 - halfRadTolerance*secRMin ;
711 tolIRMin = fRmin1 + halfRadTolerance*secRMin ;
712 tolIRMax = fRmax1 - halfRadTolerance*secRMin ;
718 tolORMin = fRmin2 - halfRadTolerance*secRMin ;
719 tolIRMin = fRmin2 + halfRadTolerance*secRMin ;
720 tolIRMax = fRmax2 - halfRadTolerance*secRMin ;
727 tolIRMin2 = tolIRMin*tolIRMin ;
734 if ( tolIRMax > 0 ) { tolIRMax2 = tolIRMax*tolIRMax; }
735 else { tolIRMax2 = 0.0; }
737 if ( (tolIRMin2 <= rhoi2) && (rhoi2 <= tolIRMax2) )
739 if ( !fPhiFullCone && (rhoi2 != 0.0) )
743 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
745 if (cosPsi >= cosHDPhiIT) {
return sd; }
778 t1 = 1.0 - v.
z()*v.
z() ;
779 t2 = p.
x()*v.
x() + p.
y()*v.
y() ;
780 t3 = p.
x()*p.
x() + p.
y()*p.
y() ;
781 rin = tanRMin*p.
z() + rMinAv ;
782 rout = tanRMax*p.
z() + rMaxAv ;
787 nt1 = t1 - (tanRMax*v.
z())*(tanRMax*v.
z()) ;
788 nt2 = t2 - tanRMax*v.
z()*rout ;
789 nt3 = t3 - rout*rout ;
791 if (std::fabs(nt1) > kRadTolerance)
796 if ( (nt3 > rout*rout*kRadTolerance*kRadTolerance*secRMax*secRMax)
805 if ((rout < 0) && (nt3 <= 0))
810 if (b>0) { sd = c/(-b-std::sqrt(d)); }
811 else { sd = -b + std::sqrt(d); }
815 if ((b <= 0) && (c >= 0))
817 sd=c/(-b+std::sqrt(d));
823 sd = -b + std::sqrt(d) ;
824 if((sd<0.0) && (sd>-halfRadTolerance)) { sd = 0.0; }
836 G4double fTerm = sd-std::fmod(sd,dRmax);
839 zi = p.
z() + sd*v.
z() ;
841 if (std::fabs(zi) <= tolODz)
845 if ( fPhiFullCone ) {
return sd; }
848 xi = p.
x() + sd*v.
x() ;
849 yi = p.
y() + sd*v.
y() ;
850 ri = rMaxAv + zi*tanRMax ;
851 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
853 if ( cosPsi >= cosHDPhiIT ) {
return sd; }
864 if ( ( t3 > (rin + halfRadTolerance*secRMin)*
865 (rin + halfRadTolerance*secRMin) )
866 && (nt2 < 0) && (d >= 0) && (std::fabs(p.
z()) <= tolIDz) )
873 risec = std::sqrt(xi*xi + yi*yi)*secRMax ;
877 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(t3) ;
878 if ( cosPsi >= cosHDPhiIT )
880 if ( Normal.
dot(v) <= 0 ) {
return 0.0; }
885 if ( Normal.
dot(v) <= 0 ) {
return 0.0; }
892 if ( std::fabs(nt2) > kRadTolerance )
896 if ( sd < 0 ) {
return kInfinity; }
899 zi = p.
z() + sd*v.
z() ;
901 if ((std::fabs(zi) <= tolODz) && (nt2 < 0))
905 if ( fPhiFullCone ) {
return sd; }
908 xi = p.
x() + sd*v.
x() ;
909 yi = p.
y() + sd*v.
y() ;
910 ri = rMaxAv + zi*tanRMax ;
911 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
913 if (cosPsi >= cosHDPhiIT) {
return sd; }
935 nt1 = t1 - (tanRMin*v.
z())*(tanRMin*v.
z()) ;
936 nt2 = t2 - tanRMin*v.
z()*rin ;
941 if ( nt3 > rin*kRadTolerance*secRMin )
951 if(b>0){sd = c/( -b-std::sqrt(d));}
952 else {sd = -b + std::sqrt(d) ;}
958 G4double fTerm = sd-std::fmod(sd,dRmax);
961 zi = p.
z() + sd*v.
z() ;
963 if ( std::fabs(zi) <= tolODz )
967 xi = p.
x() + sd*v.
x() ;
968 yi = p.
y() + sd*v.
y() ;
969 ri = rMinAv + zi*tanRMin ;
970 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
972 if (cosPsi >= cosHDPhiIT)
974 if ( sd > halfRadTolerance ) { snxt=sd; }
979 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
981 if ( Normal.
dot(v) <= 0 ) { snxt = sd; }
987 if ( sd > halfRadTolerance ) {
return sd; }
992 xi = p.
x() + sd*v.
x() ;
993 yi = p.
y() + sd*v.
y() ;
994 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
995 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
996 if ( Normal.
dot(v) <= 0 ) {
return sd; }
1003 else if ( nt3 < -rin*kRadTolerance*secRMin )
1016 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1017 else { sd = -b + std::sqrt(d); }
1018 zi = p.
z() + sd*v.
z() ;
1019 ri = rMinAv + zi*tanRMin ;
1023 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1027 G4double fTerm = sd-std::fmod(sd,dRmax);
1030 if ( !fPhiFullCone )
1032 xi = p.
x() + sd*v.
x() ;
1033 yi = p.
y() + sd*v.
y() ;
1034 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
1036 if (cosPsi >= cosHDPhiOT)
1038 if ( sd > halfRadTolerance ) { snxt=sd; }
1043 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1044 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin);
1045 if ( Normal.
dot(v) <= 0 ) { snxt = sd; }
1051 if( sd > halfRadTolerance ) {
return sd; }
1056 xi = p.
x() + sd*v.
x() ;
1057 yi = p.
y() + sd*v.
y() ;
1058 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1059 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1060 if ( Normal.
dot(v) <= 0 ) {
return sd; }
1067 if (b>0) { sd = -b - std::sqrt(d); }
1068 else { sd = c/(-b+std::sqrt(d)); }
1069 zi = p.
z() + sd*v.
z() ;
1070 ri = rMinAv + zi*tanRMin ;
1072 if ( (sd >= 0) && (ri > 0) && (std::fabs(zi) <= tolODz) )
1076 G4double fTerm = sd-std::fmod(sd,dRmax);
1079 if ( !fPhiFullCone )
1081 xi = p.
x() + sd*v.
x() ;
1082 yi = p.
y() + sd*v.
y() ;
1083 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
1085 if (cosPsi >= cosHDPhiIT)
1087 if ( sd > halfRadTolerance ) { snxt=sd; }
1092 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1093 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin);
1094 if ( Normal.
dot(v) <= 0 ) { snxt = sd; }
1100 if ( sd > halfRadTolerance ) {
return sd; }
1105 xi = p.
x() + sd*v.
x() ;
1106 yi = p.
y() + sd*v.
y() ;
1107 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1108 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1109 if ( Normal.
dot(v) <= 0 ) {
return sd; }
1123 if ( std::fabs(p.
z()) <= tolODz )
1129 if ( !fPhiFullCone )
1131 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(t3) ;
1133 if (cosPsi >= cosHDPhiIT) {
return 0.0; }
1135 else {
return 0.0; }
1148 if (b>0) { sd = -b - std::sqrt(d); }
1149 else { sd = c/(-b+std::sqrt(d)); }
1150 zi = p.
z() + sd*v.
z() ;
1151 ri = rMinAv + zi*tanRMin ;
1155 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1156 else { sd = -b + std::sqrt(d); }
1158 zi = p.
z() + sd*v.
z() ;
1160 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1164 G4double fTerm = sd-std::fmod(sd,dRmax);
1167 if ( !fPhiFullCone )
1169 xi = p.
x() + sd*v.
x() ;
1170 yi = p.
y() + sd*v.
y() ;
1171 ri = rMinAv + zi*tanRMin ;
1172 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
1174 if ( cosPsi >= cosHDPhiIT ) { snxt = sd; }
1179 else {
return kInfinity; }
1191 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1192 else { sd = -b + std::sqrt(d) ; }
1193 zi = p.
z() + sd*v.
z() ;
1195 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1199 G4double fTerm = sd-std::fmod(sd,dRmax);
1202 if ( !fPhiFullCone )
1204 xi = p.
x() + sd*v.
x();
1205 yi = p.
y() + sd*v.
y();
1206 ri = rMinAv + zi*tanRMin ;
1207 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri;
1209 if (cosPsi >= cosHDPhiIT) { snxt = sd; }
1228 if ( !fPhiFullCone )
1232 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1236 Dist = (p.
y()*cosSPhi - p.
x()*sinSPhi) ;
1238 if (Dist < halfCarTolerance)
1244 if ( sd < 0 ) { sd = 0.0; }
1246 zi = p.
z() + sd*v.
z() ;
1248 if ( std::fabs(zi) <= tolODz )
1250 xi = p.
x() + sd*v.
x() ;
1251 yi = p.
y() + sd*v.
y() ;
1252 rhoi2 = xi*xi + yi*yi ;
1253 tolORMin2 = (rMinOAv + zi*tanRMin)*(rMinOAv + zi*tanRMin) ;
1254 tolORMax2 = (rMaxOAv + zi*tanRMax)*(rMaxOAv + zi*tanRMax) ;
1256 if ( (rhoi2 >= tolORMin2) && (rhoi2 <= tolORMax2) )
1261 if ((yi*cosCPhi - xi*sinCPhi) <= 0 ) { snxt = sd; }
1270 Comp = -(v.
x()*sinEPhi - v.
y()*cosEPhi) ;
1274 Dist = -(p.
y()*cosEPhi - p.
x()*sinEPhi) ;
1275 if (Dist < halfCarTolerance)
1281 if ( sd < 0 ) { sd = 0.0; }
1283 zi = p.
z() + sd*v.
z() ;
1285 if (std::fabs(zi) <= tolODz)
1287 xi = p.
x() + sd*v.
x() ;
1288 yi = p.
y() + sd*v.
y() ;
1289 rhoi2 = xi*xi + yi*yi ;
1290 tolORMin2 = (rMinOAv + zi*tanRMin)*(rMinOAv + zi*tanRMin) ;
1291 tolORMax2 = (rMaxOAv + zi*tanRMax)*(rMaxOAv + zi*tanRMax) ;
1293 if ( (rhoi2 >= tolORMin2) && (rhoi2 <= tolORMax2) )
1298 if ( (yi*cosCPhi - xi*sinCPhi) >= 0.0 ) { snxt = sd; }
1305 if (snxt < halfCarTolerance) { snxt = 0.; }
1319 G4double safe=0.0, rho, safeR1, safeR2, safeZ, safePhi, cosPsi ;
1323 rho = std::sqrt(p.
x()*p.
x() + p.
y()*p.
y()) ;
1324 safeZ = std::fabs(p.
z()) - fDz ;
1326 if ( (fRmin1 != 0.0) || (fRmin2 != 0.0) )
1328 tanRMin = (fRmin2 - fRmin1)*0.5/fDz ;
1329 secRMin = std::sqrt(1.0 + tanRMin*tanRMin) ;
1330 pRMin = tanRMin*p.
z() + (fRmin1 + fRmin2)*0.5 ;
1331 safeR1 = (pRMin - rho)/secRMin ;
1333 tanRMax = (fRmax2 - fRmax1)*0.5/fDz ;
1334 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
1335 pRMax = tanRMax*p.
z() + (fRmax1 + fRmax2)*0.5 ;
1336 safeR2 = (rho - pRMax)/secRMax ;
1338 if ( safeR1 > safeR2) { safe = safeR1; }
1339 else { safe = safeR2; }
1343 tanRMax = (fRmax2 - fRmax1)*0.5/fDz ;
1344 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
1345 pRMax = tanRMax*p.
z() + (fRmax1 + fRmax2)*0.5 ;
1346 safe = (rho - pRMax)/secRMax ;
1348 if ( safeZ > safe ) { safe = safeZ; }
1350 if ( !fPhiFullCone && (rho != 0.0) )
1354 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/rho ;
1356 if ( cosPsi < cosHDPhi )
1358 if ( (p.
y()*cosCPhi - p.
x()*sinCPhi) <= 0.0 )
1360 safePhi = std::fabs(p.
x()*sinSPhi-p.
y()*cosSPhi);
1364 safePhi = std::fabs(p.
x()*sinEPhi-p.
y()*cosEPhi);
1366 if ( safePhi > safe ) { safe = safePhi; }
1369 if ( safe < 0.0 ) { safe = 0.0; }
1385 ESide side = kNull, sider = kNull, sidephi = kNull;
1389 G4double tanRMax, secRMax, rMaxAv ;
1390 G4double tanRMin, secRMin, rMinAv ;
1392 G4double t1, t2, t3, rout, rin, nt1, nt2, nt3 ;
1397 ESide sidetol = kNull ;
1402 G4double pDistS, compS, pDistE, compE, sphi2, xi, yi, risec, vphi ;
1409 pdist = fDz - p.
z() ;
1411 if (pdist > halfCarTolerance)
1413 snxt = pdist/v.
z() ;
1426 else if ( v.
z() < 0.0 )
1428 pdist = fDz + p.
z() ;
1430 if ( pdist > halfCarTolerance)
1432 snxt = -pdist/v.
z() ;
1468 tanRMax = (fRmax2 - fRmax1)*0.5/fDz ;
1469 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
1470 rMaxAv = (fRmax1 + fRmax2)*0.5 ;
1473 t1 = 1.0 - v.
z()*v.
z() ;
1474 t2 = p.
x()*v.
x() + p.
y()*v.
y() ;
1475 t3 = p.
x()*p.
x() + p.
y()*p.
y() ;
1476 rout = tanRMax*p.
z() + rMaxAv ;
1478 nt1 = t1 - (tanRMax*v.
z())*(tanRMax*v.
z()) ;
1479 nt2 = t2 - tanRMax*v.
z()*rout ;
1480 nt3 = t3 - rout*rout ;
1484 deltaRoi2 = snxt*snxt*t1 + 2*snxt*t2 + t3
1485 - fRmax2*(fRmax2 + kRadTolerance*secRMax);
1487 else if (v.
z() < 0.0)
1489 deltaRoi2 = snxt*snxt*t1 + 2*snxt*t2 + t3
1490 - fRmax1*(fRmax1 + kRadTolerance*secRMax);
1497 if ( (nt1 != 0.0) && (deltaRoi2 > 0.0) )
1510 if (nt3 > -halfRadTolerance && nt2 >= 0 )
1514 risec = std::sqrt(t3)*secRMax ;
1523 if (b>0) { srd = -b - std::sqrt(d); }
1524 else { srd = c/(-b+std::sqrt(d)) ; }
1526 zi = p.
z() + srd*v.
z() ;
1527 ri = tanRMax*zi + rMaxAv ;
1529 if ((ri >= 0) && (-halfRadTolerance <= srd) && (srd <= halfRadTolerance))
1537 if ( (ri < 0) || (srd < halfRadTolerance) )
1542 if (b>0) { sr2 = c/(-b-std::sqrt(d)); }
1543 else { sr2 = -b + std::sqrt(d); }
1544 zi = p.
z() + sr2*v.
z() ;
1545 ri = tanRMax*zi + rMaxAv ;
1547 if ((ri >= 0) && (sr2 > halfRadTolerance))
1555 if( (-halfRadTolerance <= sr2) && ( sr2 <= halfRadTolerance) )
1574 risec = std::sqrt(t3)*secRMax;
1581 else if ( (nt2 != 0.0) && (deltaRoi2 > 0.0) )
1587 risec = std::sqrt(t3)*secRMax;
1603 if ( slentol <= halfCarTolerance )
1614 xi = p.
x() + slentol*v.
x();
1615 yi = p.
y() + slentol*v.
y();
1616 risec = std::sqrt(xi*xi + yi*yi)*secRMax;
1619 if ( Normal.
dot(v) > 0 )
1623 *n = Normal.
unit() ;
1630 slentol = kInfinity ;
1636 if ( (fRmin1 != 0.0) || (fRmin2 != 0.0) )
1638 tanRMin = (fRmin2 - fRmin1)*0.5/fDz ;
1639 nt1 = t1 - (tanRMin*v.
z())*(tanRMin*v.
z()) ;
1643 secRMin = std::sqrt(1.0 + tanRMin*tanRMin) ;
1644 rMinAv = (fRmin1 + fRmin2)*0.5 ;
1645 rin = tanRMin*p.
z() + rMinAv ;
1646 nt2 = t2 - tanRMin*v.
z()*rin ;
1647 nt3 = t3 - rin*rin ;
1660 if (nt3 < kRadTolerance*(rin + kRadTolerance*0.25))
1664 if (calcNorm) { *validNorm =
false; }
1670 if (b>0) { sr2 = -b - std::sqrt(d); }
1671 else { sr2 = c/(-b+std::sqrt(d)); }
1672 zi = p.
z() + sr2*v.
z() ;
1673 ri = tanRMin*zi + rMinAv ;
1675 if( (ri>=0.0)&&(-halfRadTolerance<=sr2)&&(sr2<=halfRadTolerance) )
1683 if( (ri<0) || (sr2 < halfRadTolerance) )
1685 if (b>0) { sr3 = c/(-b-std::sqrt(d)); }
1686 else { sr3 = -b + std::sqrt(d) ; }
1691 if ( sr3 > halfRadTolerance )
1695 zi = p.
z() + sr3*v.
z() ;
1696 ri = tanRMin*zi + rMinAv ;
1705 else if ( sr3 > -halfRadTolerance )
1713 else if ( (sr2 < srd) && (sr2 > halfCarTolerance) )
1718 else if (sr2 > -halfCarTolerance)
1725 if( slentol <= halfCarTolerance )
1734 xi = p.
x() + slentol*v.
x() ;
1735 yi = p.
y() + slentol*v.
y() ;
1736 if( sidetol==kRMax )
1738 risec = std::sqrt(xi*xi + yi*yi)*secRMax ;
1739 Normal =
G4ThreeVector(xi/risec,yi/risec,-tanRMax/secRMax) ;
1743 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1744 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1746 if( Normal.
dot(v) > 0 )
1752 *n = Normal.
unit() ;
1762 slentol = kInfinity ;
1774 if ( !fPhiFullCone )
1779 vphi = std::atan2(v.
y(),v.
x()) ;
1781 if ( vphi < fSPhi - halfAngTolerance ) { vphi += twopi; }
1782 else if ( vphi > fSPhi + fDPhi + halfAngTolerance ) { vphi -= twopi; }
1784 if ( (p.
x() != 0.0) || (p.
y() != 0.0) )
1788 pDistS = p.
x()*sinSPhi - p.
y()*cosSPhi ;
1789 pDistE = -p.
x()*sinEPhi + p.
y()*cosEPhi ;
1793 compS = -sinSPhi*v.
x() + cosSPhi*v.
y() ;
1794 compE = sinEPhi*v.
x() - cosEPhi*v.
y() ;
1798 if( ( (fDPhi <= pi) && ( (pDistS <= halfCarTolerance)
1799 && (pDistE <= halfCarTolerance) ) )
1800 || ( (fDPhi > pi) && ((pDistS <= halfCarTolerance)
1801 || (pDistE <= halfCarTolerance) ) ) )
1806 sphi = pDistS/compS ;
1807 if (sphi >= -halfCarTolerance)
1809 xi = p.
x() + sphi*v.
x() ;
1810 yi = p.
y() + sphi*v.
y() ;
1819 if ( ( fSPhi-halfAngTolerance <= vphi )
1820 && ( fSPhi+fDPhi+halfAngTolerance >=vphi ) )
1826 if ( (yi*cosCPhi-xi*sinCPhi)>=0 )
1833 if ( pDistS > -halfCarTolerance )
1851 sphi2 = pDistE/compE ;
1855 if ( (sphi2 > -halfCarTolerance) && (sphi2 < sphi) )
1857 xi = p.
x() + sphi2*v.
x() ;
1858 yi = p.
y() + sphi2*v.
y() ;
1867 if( (fSPhi-halfAngTolerance > vphi)
1868 || (fSPhi+fDPhi+halfAngTolerance < vphi) )
1871 if ( pDistE <= -halfCarTolerance ) { sphi = sphi2; }
1872 else { sphi = 0.0; }
1876 if ( yi*cosCPhi-xi*sinCPhi >= 0 )
1881 if ( pDistE <= -halfCarTolerance ) { sphi = sphi2; }
1882 else { sphi = 0.0; }
1897 if ( (fSPhi-halfAngTolerance <= vphi)
1898 && (vphi <= fSPhi+fDPhi+halfAngTolerance) )
1924 xi = p.
x() + snxt*v.
x() ;
1925 yi = p.
y() + snxt*v.
y() ;
1926 risec = std::sqrt(xi*xi + yi*yi)*secRMax ;
1931 *validNorm = false ;
1941 *validNorm = false ;
1952 *validNorm = false ;
1966 std::ostringstream message;
1967 G4long oldprc = message.precision(16) ;
1968 message <<
"Undefined side for valid surface normal to solid."
1971 <<
"p.x() = " << p.
x()/mm <<
" mm" <<
G4endl
1972 <<
"p.y() = " << p.
y()/mm <<
" mm" <<
G4endl
1974 <<
"pho at z = " << std::sqrt( p.
x()*p.
x()+p.
y()*p.
y() )/mm
1976 if( p.
x() != 0. || p.
y() != 0.)
1978 message <<
"point phi = " << std::atan2(p.
y(),p.
x())/degree
1982 <<
"v.x() = " << v.
x() <<
G4endl
1983 <<
"v.y() = " << v.
y() <<
G4endl
1986 <<
"snxt = " << snxt/mm <<
" mm" <<
G4endl ;
1987 message.precision(oldprc) ;
1988 G4Exception(
"G4Cons::DistanceToOut(p,v,..)",
"GeomSolids1002",
1993 if (snxt < halfCarTolerance) { snxt = 0.; }
2129 G4double rone = (fRmax1-fRmax2)/(2.*fDz);
2130 G4double rtwo = (fRmin1-fRmin2)/(2.*fDz);
2131 G4double qone = (fRmax1 == fRmax2) ? 0. : fDz*(fRmax1+fRmax2)/(fRmax1-fRmax2);
2132 G4double qtwo = (fRmin1 == fRmin2) ? 0. : fDz*(fRmin1+fRmin2)/(fRmin1-fRmin2);
2134 G4double slin = std::hypot(fRmin1-fRmin2, 2.*fDz);
2135 G4double slout = std::hypot(fRmax1-fRmax2, 2.*fDz);
2136 G4double Aone = 0.5*fDPhi*(fRmax2 + fRmax1)*slout;
2137 G4double Atwo = 0.5*fDPhi*(fRmin2 + fRmin1)*slin;
2138 G4double Athree = 0.5*fDPhi*(fRmax1*fRmax1-fRmin1*fRmin1);
2139 G4double Afour = 0.5*fDPhi*(fRmax2*fRmax2-fRmin2*fRmin2);
2140 G4double Afive = fDz*(fRmax1-fRmin1+fRmax2-fRmin2);
2142 G4double phi = G4RandFlat::shoot(fSPhi,fSPhi+fDPhi);
2148 if ( (fSPhi == 0.) && fPhiFullCone ) { Afive = 0.; }
2149 G4double chose = G4RandFlat::shoot(0.,Aone+Atwo+Athree+Afour+2.*Afive);
2151 if( (chose >= 0.) && (chose < Aone) )
2153 if(fRmax1 != fRmax2)
2155 G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
2156 return { rone*cosu*(qone-zRand), rone*sinu*(qone-zRand), zRand };
2160 return { fRmax1*cosu, fRmax2*sinu, G4RandFlat::shoot(-1.*fDz,fDz) };
2163 else if( (chose >= Aone) && (chose < Aone + Atwo) )
2165 if(fRmin1 != fRmin2)
2167 G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
2168 return { rtwo*cosu*(qtwo-zRand), rtwo*sinu*(qtwo-zRand), zRand };
2172 return { fRmin1*cosu, fRmin2*sinu, G4RandFlat::shoot(-1.*fDz,fDz) };
2175 else if( (chose >= Aone + Atwo) && (chose < Aone + Atwo + Athree) )
2177 return {rRand1*cosu, rRand1*sinu, -1*fDz};
2179 else if( (chose >= Aone + Atwo + Athree)
2180 && (chose < Aone + Atwo + Athree + Afour) )
2182 return { rRand2*cosu, rRand2*sinu, fDz };
2184 else if( (chose >= Aone + Atwo + Athree + Afour)
2185 && (chose < Aone + Atwo + Athree + Afour + Afive) )
2187 G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
2188 rRand1 = G4RandFlat::shoot(fRmin2-((zRand-fDz)/(2.*fDz))*(fRmin1-fRmin2),
2189 fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2));
2190 return { rRand1*cosSPhi, rRand1*sinSPhi, zRand };
2194 G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
2195 rRand1 = G4RandFlat::shoot(fRmin2-((zRand-fDz)/(2.*fDz))*(fRmin1-fRmin2),
2196 fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2));
2197 return { rRand1*cosEPhi, rRand1*sinEPhi, zRand };