47 #if !defined(G4GEOM_USE_UCONS)
61 using namespace CLHEP;
83 :
G4CSGSolid(pName), fRmin1(pRmin1), fRmin2(pRmin2),
84 fRmax1(pRmax1), fRmax2(pRmax2), fDz(pDz), fSPhi(0.), fDPhi(0.)
97 std::ostringstream message;
98 message <<
"Invalid Z half-length for Solid: " <<
GetName() <<
G4endl
106 if (((pRmin1>=pRmax1) || (pRmin2>=pRmax2) || (pRmin1<0)) && (pRmin2<0))
108 std::ostringstream message;
109 message <<
"Invalid values of radii for Solid: " <<
GetName() <<
G4endl
110 <<
" pRmin1 = " << pRmin1 <<
", pRmin2 = " << pRmin2
111 <<
", pRmax1 = " << pRmax1 <<
", pRmax2 = " << pRmax2;
129 :
G4CSGSolid(a), kRadTolerance(0.), kAngTolerance(0.),
130 fRmin1(0.), fRmin2(0.), fRmax1(0.), fRmax2(0.), fDz(0.),
131 fSPhi(0.), fDPhi(0.), sinCPhi(0.), cosCPhi(0.), cosHDPhiOT(0.),
132 cosHDPhiIT(0.), sinSPhi(0.), cosSPhi(0.), sinEPhi(0.), cosEPhi(0.),
133 fPhiFullCone(false), halfCarTolerance(0.), halfRadTolerance(0.),
152 :
G4CSGSolid(rhs), kRadTolerance(rhs.kRadTolerance),
153 kAngTolerance(rhs.kAngTolerance), fRmin1(rhs.fRmin1), fRmin2(rhs.fRmin2),
154 fRmax1(rhs.fRmax1), fRmax2(rhs.fRmax2), fDz(rhs.fDz), fSPhi(rhs.fSPhi),
155 fDPhi(rhs.fDPhi), sinCPhi(rhs.sinCPhi), cosCPhi(rhs.cosCPhi),
156 cosHDPhiOT(rhs.cosHDPhiOT), cosHDPhiIT(rhs.cosHDPhiIT),
157 sinSPhi(rhs.sinSPhi), cosSPhi(rhs.cosSPhi), sinEPhi(rhs.sinEPhi),
158 cosEPhi(rhs.cosEPhi), fPhiFullCone(rhs.fPhiFullCone),
159 halfCarTolerance(rhs.halfCarTolerance),
160 halfRadTolerance(rhs.halfRadTolerance),
161 halfAngTolerance(rhs.halfAngTolerance)
174 if (
this == &rhs) {
return *
this; }
206 G4double r2, rl, rh, pPhi, tolRMin, tolRMax;
213 r2 = p.x()*p.x() + p.y()*p.y() ;
220 if ( tolRMin < 0 ) { tolRMin = 0; }
223 if ( (r2<tolRMin*tolRMin) || (r2>tolRMax*tolRMax) ) {
return in =
kOutside; }
226 else { tolRMin = 0.0; }
231 if ( (r2 < tolRMin*tolRMin) || (r2 >= tolRMax*tolRMax) ) { in =
kSurface; }
233 if ( !
fPhiFullCone && ((p.x() != 0.0) || (p.y() != 0.0)) )
235 pPhi = std::atan2(p.y(),p.x()) ;
289 G4double diff1, diff2, delta, maxDiff, newMin, newMax, RMax ;
290 G4double xoff1, xoff2, yoff1, yoff2 ;
293 zMin = zoffset -
fDz ;
294 zMax = zoffset +
fDz ;
319 xMin = 2*xoffset-xMax ;
343 yMin = 2*yoffset-yMax ;
344 RMax = yMax - yoffset ;
368 yoff1 = yoffset - yMin ;
369 yoff2 = yMax - yoffset ;
371 if ((yoff1 >= 0) && (yoff2 >= 0))
380 delta=RMax*RMax-yoff1*yoff1;
381 diff1=(delta>0.) ? std::sqrt(delta) : 0.;
382 delta=RMax*RMax-yoff2*yoff2;
383 diff2=(delta>0.) ? std::sqrt(delta) : 0.;
384 maxDiff = (diff1>diff2) ? diff1:diff2 ;
385 newMin = xoffset - maxDiff ;
386 newMax = xoffset + maxDiff ;
387 pMin = ( newMin < xMin ) ? xMin : newMin ;
388 pMax = ( newMax > xMax) ? xMax : newMax ;
393 xoff1 = xoffset - xMin ;
394 xoff2 = xMax - xoffset ;
396 if ((xoff1 >= 0) && (xoff2 >= 0) )
405 delta=RMax*RMax-xoff1*xoff1;
406 diff1=(delta>0.) ? std::sqrt(delta) : 0.;
407 delta=RMax*RMax-xoff2*xoff2;
408 diff2=(delta>0.) ? std::sqrt(delta) : 0.;
409 maxDiff = (diff1 > diff2) ? diff1:diff2 ;
410 newMin = yoffset - maxDiff ;
411 newMax = yoffset + maxDiff ;
412 pMin = (newMin < yMin) ? yMin : newMin ;
413 pMax = (newMax > yMax) ? yMax : newMax ;
432 G4int i, noEntries, noBetweenSections4 ;
433 G4bool existsAfterClip = false ;
439 noEntries = vertices->size() ;
440 noBetweenSections4 = noEntries-4 ;
442 for ( i = 0 ; i < noEntries ; i += 4 )
446 for ( i = 0 ; i < noBetweenSections4 ; i += 4 )
452 existsAfterClip = true ;
473 existsAfterClip = true ;
479 return existsAfterClip ;
491 G4int noSurfaces = 0;
495 G4double tanRMin, secRMin, pRMin, widRMin;
496 G4double tanRMax, secRMax, pRMax, widRMax;
501 distZ = std::fabs(std::fabs(p.z()) -
fDz);
502 rho = std::sqrt(p.x()*p.x() + p.y()*p.y());
505 secRMin = std::sqrt(1 + tanRMin*tanRMin);
506 pRMin = rho - p.z()*tanRMin;
508 distRMin = std::fabs(pRMin - widRMin)/secRMin;
511 secRMax = std::sqrt(1+tanRMax*tanRMax);
512 pRMax = rho - p.z()*tanRMax;
514 distRMax = std::fabs(pRMax - widRMax)/secRMax;
520 pPhi = std::atan2(p.y(),p.x());
525 distSPhi = std::fabs( pPhi -
fSPhi );
538 nR =
G4ThreeVector(p.x()/rho/secRMax, p.y()/rho/secRMax, -tanRMax/secRMax);
541 nr =
G4ThreeVector(-p.x()/rho/secRMin,-p.y()/rho/secRMin,tanRMin/secRMin);
571 if ( p.z() >= 0.) { sumnorm += nZ; }
572 else { sumnorm -= nZ; }
574 if ( noSurfaces == 0 )
577 G4Exception(
"G4Cons::SurfaceNormal(p)",
"GeomSolids1002",
582 else if ( noSurfaces == 1 ) { norm = sumnorm; }
583 else { norm = sumnorm.unit(); }
598 G4double distZ, distRMin, distRMax, distSPhi, distEPhi, distMin ;
599 G4double tanRMin, secRMin, pRMin, widRMin ;
600 G4double tanRMax, secRMax, pRMax, widRMax ;
602 distZ = std::fabs(std::fabs(p.z()) -
fDz) ;
603 rho = std::sqrt(p.x()*p.x() + p.y()*p.y()) ;
606 secRMin = std::sqrt(1 + tanRMin*tanRMin) ;
607 pRMin = rho - p.z()*tanRMin ;
609 distRMin = std::fabs(pRMin - widRMin)/secRMin ;
612 secRMax = std::sqrt(1+tanRMax*tanRMax) ;
613 pRMax = rho - p.z()*tanRMax ;
615 distRMax = std::fabs(pRMax - widRMax)/secRMax ;
617 if (distRMin < distRMax)
619 if (distZ < distRMin)
632 if (distZ < distRMax)
645 phi = std::atan2(p.y(),p.x()) ;
647 if (phi < 0) { phi += twopi; }
649 if (
fSPhi < 0) { distSPhi = std::fabs(phi - (
fSPhi + twopi))*rho; }
650 else { distSPhi = std::fabs(phi -
fSPhi)*rho; }
652 distEPhi = std::fabs(phi -
fSPhi -
fDPhi)*rho ;
656 if (distSPhi < distEPhi)
658 if (distSPhi < distMin) { side =
kNSPhi; }
662 if (distEPhi < distMin) { side =
kNEPhi; }
669 norm =
G4ThreeVector(-p.x()/rho, -p.y()/rho, tanRMin/secRMin) ;
673 norm =
G4ThreeVector(p.x()/rho, p.y()/rho, -tanRMax/secRMax) ;
689 "Undefined side for valid surface normal to solid.");
725 G4double tanRMax,secRMax,rMaxAv,rMaxOAv ;
726 G4double tanRMin,secRMin,rMinAv,rMinOAv ;
729 G4double tolORMin,tolORMin2,tolIRMin,tolIRMin2 ;
730 G4double tolORMax2,tolIRMax,tolIRMax2 ;
733 G4double Dist,sd,xi,yi,zi,ri=0.,risec,rhoi2,cosPsi ;
744 secRMin = std::sqrt(1.0 + tanRMin*tanRMin) ;
756 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
765 if (std::fabs(p.z()) >= tolIDz)
767 if ( p.z()*v.z() < 0 )
769 sd = (std::fabs(p.z()) -
fDz)/std::fabs(v.z()) ;
771 if( sd < 0.0 ) { sd = 0.0; }
773 xi = p.x() + sd*v.x() ;
774 yi = p.y() + sd*v.y() ;
775 rhoi2 = xi*xi + yi*yi ;
782 tolORMin =
fRmin1 - halfRadTolerance*secRMin ;
783 tolIRMin =
fRmin1 + halfRadTolerance*secRMin ;
784 tolIRMax =
fRmax1 - halfRadTolerance*secRMin ;
785 tolORMax2 = (
fRmax1 + halfRadTolerance*secRMax)*
786 (
fRmax1 + halfRadTolerance*secRMax) ;
790 tolORMin =
fRmin2 - halfRadTolerance*secRMin ;
791 tolIRMin =
fRmin2 + halfRadTolerance*secRMin ;
792 tolIRMax =
fRmax2 - halfRadTolerance*secRMin ;
793 tolORMax2 = (
fRmax2 + halfRadTolerance*secRMax)*
794 (
fRmax2 + halfRadTolerance*secRMax) ;
798 tolORMin2 = tolORMin*tolORMin ;
799 tolIRMin2 = tolIRMin*tolIRMin ;
806 if ( tolIRMax > 0 ) { tolIRMax2 = tolIRMax*tolIRMax; }
807 else { tolIRMax2 = 0.0; }
809 if ( (tolIRMin2 <= rhoi2) && (rhoi2 <= tolIRMax2) )
850 t1 = 1.0 - v.z()*v.z() ;
851 t2 = p.x()*v.x() + p.y()*v.y() ;
852 t3 = p.x()*p.x() + p.y()*p.y() ;
853 rin = tanRMin*p.z() + rMinAv ;
854 rout = tanRMax*p.z() + rMaxAv ;
859 nt1 = t1 - (tanRMax*v.z())*(tanRMax*v.z()) ;
860 nt2 = t2 - tanRMax*v.z()*rout ;
861 nt3 = t3 - rout*rout ;
877 if ((rout < 0) && (nt3 <= 0))
882 if (b>0) { sd = c/(-b-std::sqrt(d)); }
883 else { sd = -b + std::sqrt(d); }
887 if ((b <= 0) && (c >= 0))
889 sd=c/(-b+std::sqrt(d));
895 sd = -b + std::sqrt(d) ;
896 if((sd<0) & (sd>-halfRadTolerance)) sd=0;
908 G4double fTerm = sd-std::fmod(sd,dRmax);
911 zi = p.z() + sd*v.z() ;
913 if (std::fabs(zi) <= tolODz)
920 xi = p.x() + sd*v.x() ;
921 yi = p.y() + sd*v.y() ;
922 ri = rMaxAv + zi*tanRMax ;
936 if ( ( t3 > (rin + halfRadTolerance*secRMin)*
937 (rin + halfRadTolerance*secRMin) )
938 && (nt2 < 0) && (d >= 0) && (std::fabs(p.z()) <= tolIDz) )
945 risec = std::sqrt(xi*xi + yi*yi)*secRMax ;
952 if ( Normal.dot(v) <= 0 ) {
return 0.0; }
957 if ( Normal.dot(v) <= 0 ) {
return 0.0; }
971 zi = p.z() + sd*v.z() ;
973 if ((std::fabs(zi) <= tolODz) && (nt2 < 0))
980 xi = p.x() + sd*v.x() ;
981 yi = p.y() + sd*v.y() ;
982 ri = rMaxAv + zi*tanRMax ;
1007 nt1 = t1 - (tanRMin*v.z())*(tanRMin*v.z()) ;
1008 nt2 = t2 - tanRMin*v.z()*rin ;
1009 nt3 = t3 - rin*rin ;
1023 if(b>0){sd = c/( -b-std::sqrt(d));}
1024 else {sd = -b + std::sqrt(d) ;}
1030 G4double fTerm = sd-std::fmod(sd,dRmax);
1033 zi = p.z() + sd*v.z() ;
1035 if ( std::fabs(zi) <= tolODz )
1039 xi = p.x() + sd*v.x() ;
1040 yi = p.y() + sd*v.y() ;
1041 ri = rMinAv + zi*tanRMin ;
1046 if ( sd > halfRadTolerance ) { snxt=sd; }
1051 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1052 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin);
1053 if ( Normal.dot(v) <= 0 ) { snxt = sd; }
1059 if ( sd > halfRadTolerance ) {
return sd; }
1064 xi = p.x() + sd*v.x() ;
1065 yi = p.y() + sd*v.y() ;
1066 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1067 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1068 if ( Normal.dot(v) <= 0 ) {
return sd; }
1088 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1089 else { sd = -b + std::sqrt(d); }
1090 zi = p.z() + sd*v.z() ;
1091 ri = rMinAv + zi*tanRMin ;
1095 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1099 G4double fTerm = sd-std::fmod(sd,dRmax);
1104 xi = p.x() + sd*v.x() ;
1105 yi = p.y() + sd*v.y() ;
1110 if ( sd > halfRadTolerance ) { snxt=sd; }
1115 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1116 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin);
1117 if ( Normal.dot(v) <= 0 ) { snxt = sd; }
1123 if( sd > halfRadTolerance ) {
return sd; }
1128 xi = p.x() + sd*v.x() ;
1129 yi = p.y() + sd*v.y() ;
1130 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1131 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1132 if ( Normal.dot(v) <= 0 ) {
return sd; }
1139 if (b>0) { sd = -b - std::sqrt(d); }
1140 else { sd = c/(-b+std::sqrt(d)); }
1141 zi = p.z() + sd*v.z() ;
1142 ri = rMinAv + zi*tanRMin ;
1144 if ( (sd >= 0) && (ri > 0) && (std::fabs(zi) <= tolODz) )
1148 G4double fTerm = sd-std::fmod(sd,dRmax);
1153 xi = p.x() + sd*v.x() ;
1154 yi = p.y() + sd*v.y() ;
1159 if ( sd > halfRadTolerance ) { snxt=sd; }
1164 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1165 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin);
1166 if ( Normal.dot(v) <= 0 ) { snxt = sd; }
1172 if ( sd > halfRadTolerance ) {
return sd; }
1177 xi = p.x() + sd*v.x() ;
1178 yi = p.y() + sd*v.y() ;
1179 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1180 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1181 if ( Normal.dot(v) <= 0 ) {
return sd; }
1195 if ( std::fabs(p.z()) <= tolODz )
1207 else {
return 0.0; }
1220 if (b>0) { sd = -b - std::sqrt(d); }
1221 else { sd = c/(-b+std::sqrt(d)); }
1222 zi = p.z() + sd*v.z() ;
1223 ri = rMinAv + zi*tanRMin ;
1227 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1228 else { sd = -b + std::sqrt(d); }
1230 zi = p.z() + sd*v.z() ;
1232 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1236 G4double fTerm = sd-std::fmod(sd,dRmax);
1241 xi = p.x() + sd*v.x() ;
1242 yi = p.y() + sd*v.y() ;
1243 ri = rMinAv + zi*tanRMin ;
1263 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1264 else { sd = -b + std::sqrt(d) ; }
1265 zi = p.z() + sd*v.z() ;
1267 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1271 G4double fTerm = sd-std::fmod(sd,dRmax);
1276 xi = p.x() + sd*v.x();
1277 yi = p.y() + sd*v.y();
1278 ri = rMinAv + zi*tanRMin ;
1310 if (Dist < halfCarTolerance)
1316 if ( sd < 0 ) { sd = 0.0; }
1318 zi = p.z() + sd*v.z() ;
1320 if ( std::fabs(zi) <= tolODz )
1322 xi = p.x() + sd*v.x() ;
1323 yi = p.y() + sd*v.y() ;
1324 rhoi2 = xi*xi + yi*yi ;
1325 tolORMin2 = (rMinOAv + zi*tanRMin)*(rMinOAv + zi*tanRMin) ;
1326 tolORMax2 = (rMaxOAv + zi*tanRMax)*(rMaxOAv + zi*tanRMax) ;
1328 if ( (rhoi2 >= tolORMin2) && (rhoi2 <= tolORMax2) )
1347 if (Dist < halfCarTolerance)
1353 if ( sd < 0 ) { sd = 0.0; }
1355 zi = p.z() + sd*v.z() ;
1357 if (std::fabs(zi) <= tolODz)
1359 xi = p.x() + sd*v.x() ;
1360 yi = p.y() + sd*v.y() ;
1361 rhoi2 = xi*xi + yi*yi ;
1362 tolORMin2 = (rMinOAv + zi*tanRMin)*(rMinOAv + zi*tanRMin) ;
1363 tolORMax2 = (rMaxOAv + zi*tanRMax)*(rMaxOAv + zi*tanRMax) ;
1365 if ( (rhoi2 >= tolORMin2) && (rhoi2 <= tolORMax2) )
1377 if (snxt < halfCarTolerance) { snxt = 0.; }
1391 G4double safe=0.0, rho, safeR1, safeR2, safeZ, safePhi, cosPsi ;
1395 rho = std::sqrt(p.x()*p.x() + p.y()*p.y()) ;
1396 safeZ = std::fabs(p.z()) -
fDz ;
1401 secRMin = std::sqrt(1.0 + tanRMin*tanRMin) ;
1403 safeR1 = (pRMin - rho)/secRMin ;
1406 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
1408 safeR2 = (rho - pRMax)/secRMax ;
1410 if ( safeR1 > safeR2) { safe = safeR1; }
1411 else { safe = safeR2; }
1416 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
1418 safe = (rho - pRMax)/secRMax ;
1420 if ( safeZ > safe ) { safe = safeZ; }
1428 if ( cosPsi < std::cos(
fDPhi*0.5) )
1432 safePhi = std::fabs(p.x()*std::sin(
fSPhi)-p.y()*std::cos(
fSPhi));
1438 if ( safePhi > safe ) { safe = safePhi; }
1441 if ( safe < 0.0 ) { safe = 0.0; }
1461 G4double tanRMax, secRMax, rMaxAv ;
1462 G4double tanRMin, secRMin, rMinAv ;
1464 G4double t1, t2, t3, rout, rin, nt1, nt2, nt3 ;
1474 G4double pDistS, compS, pDistE, compE, sphi2, xi, yi, risec, vphi ;
1481 pdist =
fDz - p.z() ;
1485 snxt = pdist/v.z() ;
1498 else if ( v.z() < 0.0 )
1500 pdist =
fDz + p.z() ;
1504 snxt = -pdist/v.z() ;
1541 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
1545 t1 = 1.0 - v.z()*v.z() ;
1546 t2 = p.x()*v.x() + p.y()*v.y() ;
1547 t3 = p.x()*p.x() + p.y()*p.y() ;
1548 rout = tanRMax*p.z() + rMaxAv ;
1550 nt1 = t1 - (tanRMax*v.z())*(tanRMax*v.z()) ;
1551 nt2 = t2 - tanRMax*v.z()*rout ;
1552 nt3 = t3 - rout*rout ;
1556 deltaRoi2 = snxt*snxt*t1 + 2*snxt*t2 + t3
1559 else if ( v.z() < 0.0 )
1561 deltaRoi2 = snxt*snxt*t1 + 2*snxt*t2 + t3
1569 if ( nt1 && (deltaRoi2 > 0.0) )
1586 risec = std::sqrt(t3)*secRMax ;
1588 *n =
G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax);
1595 if (b>0) { srd = -b - std::sqrt(d); }
1596 else { srd = c/(-b+std::sqrt(d)) ; }
1598 zi = p.z() + srd*v.z() ;
1599 ri = tanRMax*zi + rMaxAv ;
1614 if (b>0) { sr2 = c/(-b-std::sqrt(d)); }
1615 else { sr2 = -b + std::sqrt(d); }
1616 zi = p.z() + sr2*v.z() ;
1617 ri = tanRMax*zi + rMaxAv ;
1646 risec = std::sqrt(t3)*secRMax;
1648 *n =
G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax);
1653 else if ( nt2 && (deltaRoi2 > 0.0) )
1659 risec = std::sqrt(t3)*secRMax;
1661 *n =
G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax);
1686 xi = p.x() + slentol*v.x();
1687 yi = p.y() + slentol*v.y();
1688 risec = std::sqrt(xi*xi + yi*yi)*secRMax;
1691 if ( Normal.dot(v) > 0 )
1695 *n = Normal.unit() ;
1711 nt1 = t1 - (tanRMin*v.z())*(tanRMin*v.z()) ;
1715 secRMin = std::sqrt(1.0 + tanRMin*tanRMin) ;
1717 rin = tanRMin*p.z() + rMinAv ;
1718 nt2 = t2 - tanRMin*v.z()*rin ;
1719 nt3 = t3 - rin*rin ;
1736 if (calcNorm) { *validNorm =
false; }
1742 if (b>0) { sr2 = -b - std::sqrt(d); }
1743 else { sr2 = c/(-b+std::sqrt(d)); }
1744 zi = p.z() + sr2*v.z() ;
1745 ri = tanRMin*zi + rMinAv ;
1757 if (b>0) { sr3 = c/(-b-std::sqrt(d)); }
1758 else { sr3 = -b + std::sqrt(d) ; }
1767 zi = p.z() + sr3*v.z() ;
1768 ri = tanRMin*zi + rMinAv ;
1806 xi = p.x() + slentol*v.x() ;
1807 yi = p.y() + slentol*v.y() ;
1808 if( sidetol==
kRMax )
1810 risec = std::sqrt(xi*xi + yi*yi)*secRMax ;
1811 Normal =
G4ThreeVector(xi/risec,yi/risec,-tanRMax/secRMax) ;
1815 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1816 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1818 if( Normal.dot(v) > 0 )
1824 *n = Normal.unit() ;
1851 vphi = std::atan2(v.y(),v.x()) ;
1856 if ( p.x() || p.y() )
1878 sphi = pDistS/compS ;
1881 xi = p.x() + sphi*v.x() ;
1882 yi = p.y() + sphi*v.y() ;
1923 sphi2 = pDistE/compE ;
1929 xi = p.x() + sphi2*v.x() ;
1930 yi = p.y() + sphi2*v.y() ;
1944 else { sphi = 0.0; }
1954 else { sphi = 0.0; }
1996 xi = p.x() + snxt*v.x() ;
1997 yi = p.y() + snxt*v.y() ;
1998 risec = std::sqrt(xi*xi + yi*yi)*secRMax ;
2003 *validNorm = false ;
2013 *validNorm = false ;
2024 *validNorm = false ;
2038 std::ostringstream message;
2039 G4int oldprc = message.precision(16) ;
2040 message <<
"Undefined side for valid surface normal to solid."
2042 <<
"Position:" << G4endl << G4endl
2043 <<
"p.x() = " << p.x()/
mm <<
" mm" << G4endl
2044 <<
"p.y() = " << p.y()/
mm <<
" mm" << G4endl
2045 <<
"p.z() = " << p.z()/
mm <<
" mm" << G4endl << G4endl
2046 <<
"pho at z = " << std::sqrt( p.x()*p.x()+p.y()*p.y() )/
mm
2047 <<
" mm" << G4endl << G4endl ;
2048 if( p.x() != 0. || p.y() != 0.)
2050 message <<
"point phi = " << std::atan2(p.y(),p.x())/
degree
2051 <<
" degree" << G4endl << G4endl ;
2053 message <<
"Direction:" << G4endl << G4endl
2054 <<
"v.x() = " << v.x() << G4endl
2055 <<
"v.y() = " << v.y() << G4endl
2056 <<
"v.z() = " << v.z() << G4endl<< G4endl
2057 <<
"Proposed distance :" << G4endl<< G4endl
2058 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl ;
2059 message.precision(oldprc) ;
2060 G4Exception(
"G4Cons::DistanceToOut(p,v,..)",
"GeomSolids1002",
2076 G4double safe=0.0, rho, safeR1, safeR2, safeZ, safePhi;
2090 G4cout <<
"pho at z = " << std::sqrt( p.x()*p.x()+p.y()*p.y() )/
mm
2091 <<
" mm" << G4endl << G4endl ;
2092 if( (p.x() != 0.) || (p.x() != 0.) )
2094 G4cout <<
"point phi = " << std::atan2(p.y(),p.x())/
degree
2095 <<
" degree" << G4endl << G4endl ;
2097 G4cout.precision(oldprc) ;
2098 G4Exception(
"G4Cons::DistanceToOut(p)",
"GeomSolids1002",
2103 rho = std::sqrt(p.x()*p.x() + p.y()*p.y()) ;
2104 safeZ =
fDz - std::fabs(p.z()) ;
2109 secRMin = std::sqrt(1.0 + tanRMin*tanRMin) ;
2111 safeR1 = (rho - pRMin)/secRMin ;
2119 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
2121 safeR2 = (pRMax - rho)/secRMax ;
2123 if (safeR1 < safeR2) { safe = safeR1; }
2124 else { safe = safeR2; }
2125 if (safeZ < safe) { safe = safeZ ; }
2141 if (safePhi < safe) { safe = safePhi; }
2143 if ( safe < 0 ) { safe = 0; }
2164 G4double meshAngle, meshRMax1, meshRMax2, crossAngle;
2165 G4double cosCrossAngle, sinCrossAngle, sAngle ;
2166 G4double rMaxX1, rMaxX2, rMaxY1, rMaxY2, rMinX1, rMinX2, rMinY1, rMinY2 ;
2167 G4int crossSection, noCrossSections ;
2181 meshAngle =
fDPhi/(noCrossSections - 1) ;
2183 meshRMax1 =
fRmax1/std::cos(meshAngle*0.5) ;
2184 meshRMax2 =
fRmax2/std::cos(meshAngle*0.5) ;
2191 sAngle = -meshAngle*0.5 ;
2201 vertices->reserve(noCrossSections*4) ;
2202 for (crossSection = 0 ; crossSection < noCrossSections ; crossSection++)
2206 crossAngle = sAngle + crossSection*meshAngle ;
2207 cosCrossAngle = std::cos(crossAngle) ;
2208 sinCrossAngle = std::sin(crossAngle) ;
2210 rMaxX1 = meshRMax1*cosCrossAngle ;
2211 rMaxY1 = meshRMax1*sinCrossAngle ;
2212 rMaxX2 = meshRMax2*cosCrossAngle ;
2213 rMaxY2 = meshRMax2*sinCrossAngle ;
2215 rMinX1 =
fRmin1*cosCrossAngle ;
2216 rMinY1 =
fRmin1*sinCrossAngle ;
2217 rMinX2 =
fRmin2*cosCrossAngle ;
2218 rMinY2 =
fRmin2*sinCrossAngle ;
2236 "Error in allocation of vertices. Out of memory !");
2257 return new G4Cons(*
this);
2266 G4int oldprc = os.precision(16);
2267 os <<
"-----------------------------------------------------------\n"
2268 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
2269 <<
" ===================================================\n"
2270 <<
" Solid type: G4Cons\n"
2271 <<
" Parameters: \n"
2272 <<
" inside -fDz radius: " <<
fRmin1/
mm <<
" mm \n"
2273 <<
" outside -fDz radius: " <<
fRmax1/
mm <<
" mm \n"
2274 <<
" inside +fDz radius: " <<
fRmin2/
mm <<
" mm \n"
2275 <<
" outside +fDz radius: " <<
fRmax2/
mm <<
" mm \n"
2276 <<
" half length in Z : " <<
fDz/
mm <<
" mm \n"
2277 <<
" starting angle of segment: " <<
fSPhi/
degree <<
" degrees \n"
2278 <<
" delta angle of segment : " <<
fDPhi/
degree <<
" degrees \n"
2279 <<
"-----------------------------------------------------------\n";
2280 os.precision(oldprc);
2295 G4double Aone, Atwo, Athree, Afour, Afive, slin, slout, phi;
2296 G4double zRand, cosu, sinu, rRand1, rRand2, chose, rone, rtwo, qone, qtwo;
2311 cosu = std::cos(phi); sinu = std::sin(phi);
2318 if( (chose >= 0.) && (chose < Aone) )
2324 rtwo*sinu*(qtwo-zRand), zRand);
2332 else if( (chose >= Aone) && (chose <= Aone + Atwo) )
2338 rone*sinu*(qone-zRand), zRand);
2346 else if( (chose >= Aone + Atwo) && (chose < Aone + Atwo + Athree) )
2350 else if( (chose >= Aone + Atwo + Athree)
2351 && (chose < Aone + Atwo + Athree + Afour) )
2355 else if( (chose >= Aone + Atwo + Athree + Afour)
2356 && (chose < Aone + Atwo + Athree + Afour + Afive) )
2362 rRand1*std::sin(
fSPhi), zRand);
G4Cons(const G4String &pName, G4double pRmin1, G4double pRmax1, G4double pRmin2, G4double pRmax2, G4double pDz, G4double pSPhi, G4double pDPhi)
void ClipCrossSection(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
ThreeVector shoot(const G4int Ap, const G4int Af)
G4double halfRadTolerance
static const G4double kInfinity
G4double GetMinYExtent() const
CLHEP::Hep3Vector G4ThreeVector
G4ThreeVectorList * CreateRotatedVertices(const G4AffineTransform &pTransform) const
G4Cons & operator=(const G4Cons &rhs)
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4bool IsYLimited() const
G4double GetRadiusInRing(G4double rmin, G4double rmax) const
EInside Inside(const G4ThreeVector &p) const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=G4bool(false), G4bool *validNorm=0, G4ThreeVector *n=0) const
G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector &p) const
std::ostream & StreamInfo(std::ostream &os) const
G4bool IsXLimited() const
const G4int kMinMeshSections
virtual void AddSolid(const G4Box &)=0
G4GeometryType GetEntityType() const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
void CheckPhiAngles(G4double sPhi, G4double dPhi)
G4double GetMaxXExtent() const
G4double GetMinZExtent() const
G4GLOB_DLL std::ostream G4cout
G4Polyhedron * fpPolyhedron
G4double GetRadialTolerance() const
G4double halfCarTolerance
virtual G4Polyhedron * GetPolyhedron() const
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4double GetMinXExtent() const
G4double GetMaxZExtent() const
G4double halfAngTolerance
G4Polyhedron * CreatePolyhedron() const
static const double degree
void DescribeYourselfTo(G4VGraphicsScene &scene) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
G4double GetMaxYExtent() const
G4ThreeVector GetPointOnSurface() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4double GetMaxExtent(const EAxis pAxis) const
G4CSGSolid & operator=(const G4CSGSolid &rhs)
G4bool IsZLimited() const
G4double GetAngularTolerance() const
void ClipBetweenSections(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
G4double GetMinExtent(const EAxis pAxis) const
const G4double kMeshAngleDefault
static G4GeometryTolerance * GetInstance()
const G4int kMaxMeshSections