40#if !(defined(G4GEOM_USE_UTORUS) && defined(G4GEOM_USE_SYS_USOLIDS))
97 halfAngTolerance = 0.5*kAngTolerance;
105 std::ostringstream message;
106 message <<
"Invalid swept radius for Solid: " <<
GetName() <<
G4endl
107 <<
" pRtor = " << pRtor <<
", pRmax = " << pRmax;
114 if ( pRmin < pRmax - 1.e2*kCarTolerance && pRmin >= 0 )
117 else { fRmin = 0.0 ; }
122 std::ostringstream message;
123 message <<
"Invalid values of radii for Solid: " <<
GetName() <<
G4endl
124 <<
" pRmin = " << pRmin <<
", pRmax = " << pRmax;
131 fRminTolerance = (fRmin) != 0.0
132 ? 0.5*std::max( kRadTolerance, fEpsilon*(fRtor-fRmin )) : 0;
133 fRmaxTolerance = 0.5*std::max( kRadTolerance, fEpsilon*(fRtor+fRmax) );
137 if ( pDPhi >= twopi ) { fDPhi = twopi ; }
140 if (pDPhi > 0) { fDPhi = pDPhi ; }
143 std::ostringstream message;
144 message <<
"Invalid Z delta-Phi for Solid: " <<
GetName() <<
G4endl
145 <<
" pDPhi = " << pDPhi;
155 if (fSPhi < 0) { fSPhi = twopi-std::fmod(std::fabs(fSPhi),twopi) ; }
156 else { fSPhi = std::fmod(fSPhi,twopi) ; }
158 if (fSPhi+fDPhi > twopi) { fSPhi-=twopi ; }
191 if (
this == &rhs) {
return *
this; }
199 fRmin = rhs.fRmin; fRmax = rhs.fRmax;
200 fRtor = rhs.fRtor; fSPhi = rhs.fSPhi; fDPhi = rhs.fDPhi;
201 fRminTolerance = rhs.fRminTolerance; fRmaxTolerance = rhs.fRmaxTolerance;
202 kRadTolerance = rhs.kRadTolerance; kAngTolerance = rhs.kAngTolerance;
203 halfCarTolerance = rhs.halfCarTolerance;
204 halfAngTolerance = rhs.halfAngTolerance;
231 std::vector<G4double>& roots )
const
237 G4double Rtor2 = fRtor*fRtor, r2 = r*r ;
245 c[2] = 2*( (d + 2*pDotV*pDotV - r2) + 2*Rtor2*v.
z()*v.
z());
246 c[3] = 4*(pDotV*(d - r2) + 2*Rtor2*p.
z()*v.
z()) ;
247 c[4] = (d-r2)*(d-r2) +4*Rtor2*(p.
z()*p.
z()-r2);
251 num = torusEq.
FindRoots( c, 4, srd, si );
253 for ( i = 0; i < num; ++i )
255 if( si[i] == 0. ) { roots.push_back(srd[i]) ; }
258 std::sort(roots.begin() , roots.end() ) ;
271 G4bool IsDistanceToIn )
const
280 std::vector<G4double> roots ;
281 std::vector<G4double> rootsrefined ;
282 TorusRootsJT(p,v,r,roots) ;
288 for ( std::size_t k = 0 ; k<roots.size() ; ++k )
292 if ( t < -halfCarTolerance ) { continue ; }
294 if ( t > bigdist && t<kInfinity )
297 TorusRootsJT(ptmp,v,r,rootsrefined) ;
298 if ( rootsrefined.size()==roots.size() )
300 t = t + rootsrefined[k] ;
306 G4double theta = std::atan2(ptmp.
y(),ptmp.
x());
310 if ( theta < - halfAngTolerance ) { theta += twopi; }
311 if ( (std::fabs(theta) < halfAngTolerance)
312 && (std::fabs(fSPhi + fDPhi - twopi) < halfAngTolerance) )
317 if ((fSPhi <= -pi )&&(theta>halfAngTolerance)) { theta = theta-twopi; }
322 if ( (theta - fSPhi >= - halfAngTolerance)
323 && (theta - (fSPhi + fDPhi) <= halfAngTolerance) )
328 if ( IsDistanceToIn )
330 if (std::fabs(t) < halfCarTolerance )
336 p.
y()*(1-fRtor/std::hypot(p.
x(),p.
y())),
341 if ( r ==
GetRmin() ) { scal = -scal ; }
342 if ( scal < 0 ) {
return 0.0 ; }
349 if ( !IsDistanceToIn )
351 if (std::fabs(t) < halfCarTolerance )
356 p.
y()*(1-fRtor/std::hypot(p.
x(),p.
y())),
361 if ( r ==
GetRmin() ) { scal = -scal ; }
362 if ( scal > 0 ) {
return 0.0 ; }
368 if( t > halfCarTolerance )
395 pMin.
set(-rext,-rext,-dz);
396 pMax.
set( rext, rext, dz);
405 pMin.
set(vmin.
x(),vmin.
y(),-dz);
406 pMax.
set(vmax.
x(),vmax.
y(), dz);
411 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
413 std::ostringstream message;
414 message <<
"Bad bounding box (min >= max) for solid: "
416 <<
"\npMin = " << pMin
417 <<
"\npMax = " << pMax;
418 G4Exception(
"G4Torus::BoundingLimits()",
"GeomMgt0001",
446 return exist = pMin < pMax;
463 static const G4int NPHI = 24;
464 static const G4int NDISK = 16;
465 static const G4double sinHalfDisk = std::sin(pi/NDISK);
466 static const G4double cosHalfDisk = std::cos(pi/NDISK);
467 static const G4double sinStepDisk = 2.*sinHalfDisk*cosHalfDisk;
468 static const G4double cosStepDisk = 1. - 2.*sinHalfDisk*sinHalfDisk;
471 G4int kphi = (dphi <= astep) ? 1 : (
G4int)((dphi-deg)/astep) + 1;
474 G4double sinHalf = std::sin(0.5*ang);
475 G4double cosHalf = std::cos(0.5*ang);
476 G4double sinStep = 2.*sinHalf*cosHalf;
477 G4double cosStep = 1. - 2.*sinHalf*sinHalf;
481 for (
auto & pol : pols) pol.resize(4);
483 std::vector<const G4ThreeVectorList *> polygons;
484 polygons.resize(NDISK+1);
485 for (
G4int k=0; k<NDISK+1; ++k) polygons[k] = &pols[k];
491 if ((rtor-rmin*sinHalfDisk)/cosHalf > (rtor+rmin*sinHalfDisk)) rmin = 0;
495 for (
G4int k=0; k<NDISK; ++k)
497 G4double rmincur = rtor + rmin*cosCurDisk;
498 if (cosCurDisk < 0 && rmin > 0) rmincur /= cosHalf;
499 rzmin[k].
set(rmincur,rmin*sinCurDisk);
501 G4double rmaxcur = rtor + rmax*cosCurDisk;
502 if (cosCurDisk > 0) rmaxcur /= cosHalf;
503 rzmax[k].
set(rmaxcur,rmax*sinCurDisk);
506 sinCurDisk = sinCurDisk*cosStepDisk + cosCurDisk*sinStepDisk;
507 cosCurDisk = cosCurDisk*cosStepDisk - sinTmpDisk*sinStepDisk;
516 G4double sinCur1 = 0, cosCur1 = 0, sinCur2 = 0, cosCur2 = 0;
517 for (
G4int i=0; i<kphi+1; ++i)
523 sinCur2 = sinCur1*cosHalf + cosCur1*sinHalf;
524 cosCur2 = cosCur1*cosHalf - sinCur1*sinHalf;
530 sinCur2 = (i == kphi) ? sinEnd : sinCur1*cosStep + cosCur1*sinStep;
531 cosCur2 = (i == kphi) ? cosEnd : cosCur1*cosStep - sinCur1*sinStep;
533 for (
G4int k=0; k<NDISK; ++k)
535 G4double r1 = rzmin[k].
x(), r2 = rzmax[k].
x();
536 G4double z1 = rzmin[k].
y(), z2 = rzmax[k].
y();
537 pols[k][0].set(r1*cosCur1,r1*sinCur1,z1);
538 pols[k][1].set(r2*cosCur1,r2*sinCur1,z2);
539 pols[k][2].set(r2*cosCur2,r2*sinCur2,z2);
540 pols[k][3].set(r1*cosCur2,r1*sinCur2,z1);
542 pols[NDISK] = pols[0];
547 DiskExtent(rint,rext,sinCur1,cosCur1,sinCur2,cosCur2,vmin,vmax);
554 if (!benv.
CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
continue;
555 if (emin < pMin) pMin = emin;
556 if (emax > pMax) pMax = emax;
557 if (eminlim > pMin && emaxlim < pMax)
break;
559 return (pMin < pMax);
568 G4double r, pt2, pPhi, tolRMin, tolRMax ;
574 r = std::hypot(p.
x(),p.
y());
575 pt2 = p.
z()*p.
z() + (r-fRtor)*(r-fRtor);
577 if (fRmin != 0.0) tolRMin = fRmin + fRminTolerance ;
580 tolRMax = fRmax - fRmaxTolerance;
582 if (pt2 >= tolRMin*tolRMin && pt2 <= tolRMax*tolRMax )
584 if ( fDPhi == twopi || pt2 == 0 )
593 pPhi = std::atan2(p.
y(),p.
x()) ;
595 if ( pPhi < -halfAngTolerance ) { pPhi += twopi ; }
598 if ( (std::fabs(pPhi) < halfAngTolerance)
599 && (std::fabs(fSPhi + fDPhi - twopi) < halfAngTolerance) )
603 if ( (pPhi >= fSPhi + halfAngTolerance)
604 && (pPhi <= fSPhi + fDPhi - halfAngTolerance) )
608 else if ( (pPhi >= fSPhi - halfAngTolerance)
609 && (pPhi <= fSPhi + fDPhi + halfAngTolerance) )
616 if ( (pPhi <= fSPhi + twopi - halfAngTolerance)
617 && (pPhi >= fSPhi + fDPhi + halfAngTolerance) ) {;}
627 tolRMin = fRmin - fRminTolerance ;
628 tolRMax = fRmax + fRmaxTolerance ;
630 if (tolRMin < 0 ) { tolRMin = 0 ; }
632 if ( (pt2 >= tolRMin*tolRMin) && (pt2 <= tolRMax*tolRMax) )
634 if ( (fDPhi == twopi) || (pt2 == 0) )
640 pPhi = std::atan2(p.
y(),p.
x()) ;
642 if ( pPhi < -halfAngTolerance ) { pPhi += twopi ; }
645 if ( (std::fabs(pPhi) < halfAngTolerance)
646 && (std::fabs(fSPhi + fDPhi - twopi) < halfAngTolerance) )
650 if ( (pPhi >= fSPhi - halfAngTolerance)
651 && (pPhi <= fSPhi + fDPhi + halfAngTolerance) )
658 if ( (pPhi <= fSPhi + twopi - halfAngTolerance)
659 && (pPhi >= fSPhi + fDPhi + halfAngTolerance) ) {;}
679 G4int noSurfaces = 0;
682 G4double distSPhi = kInfinity, distEPhi = kInfinity;
687 1.0e-8*(fRtor+fRmax));
688 const G4double dAngle = 10.0*kAngTolerance;
693 rho = std::hypot(p.
x(),p.
y());
694 pt = std::hypot(p.
z(),rho-fRtor);
696 G4double distRMax = std::fabs(pt - fRmax);
697 if(fRmin != 0.0) distRMin = std::fabs(pt - fRmin);
699 if( rho > delta && pt != 0.0 )
701 G4double redFactor= (rho-fRtor)/rho;
712 pPhi = std::atan2(p.
y(),p.
x());
714 if(pPhi < fSPhi-delta) { pPhi += twopi; }
715 else if(pPhi > fSPhi+fDPhi+delta) { pPhi -= twopi; }
717 distSPhi = std::fabs( pPhi - fSPhi );
718 distEPhi = std::fabs(pPhi-fSPhi-fDPhi);
721 nPe =
G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0);
723 if( distRMax <= delta )
728 else if( (fRmin != 0.0) && (distRMin <= delta) )
737 if( (fDPhi < twopi) && (fRmin-delta <= pt) && (pt <= (fRmax+delta)) )
739 if (distSPhi <= dAngle)
744 if (distEPhi <= dAngle)
750 if ( noSurfaces == 0 )
760 ed <<
" ERROR> Surface Normal was called for Torus,"
761 <<
" with point not on surface." <<
G4endl;
765 ed <<
" ERROR> Surface Normal has not found a surface, "
766 <<
" despite the point being on the surface. " <<
G4endl;
777 ed <<
" Coordinates of point : " << p <<
G4endl;
778 ed <<
" Parameters of solid : " <<
G4endl << *
this <<
G4endl;
782 G4Exception(
"G4Torus::SurfaceNormal(p)",
"GeomSolids1002",
784 "Failing to find normal, even though point is on surface!");
788 static const char* NameInside[3]= {
"Inside",
"Surface",
"Outside" };
789 ed <<
" The point is " << NameInside[inIt] <<
" the solid. "<<
G4endl;
790 G4Exception(
"G4Torus::SurfaceNormal(p)",
"GeomSolids1002",
794 norm = ApproxSurfaceNormal(p);
796 else if ( noSurfaces == 1 ) { norm = sumnorm; }
797 else { norm = sumnorm.
unit(); }
812 G4double distRMin,distRMax,distSPhi,distEPhi,distMin;
814 rho = std::hypot(p.
x(),p.
y());
815 pt = std::hypot(p.
z(),rho-fRtor);
818 G4cout <<
" G4Torus::ApproximateSurfaceNormal called for point " << p
822 distRMax = std::fabs(pt - fRmax) ;
826 distRMin = std::fabs(pt - fRmin) ;
828 if (distRMin < distRMax)
844 if ( (fDPhi < twopi) && (rho != 0.0) )
846 phi = std::atan2(p.
y(),p.
x()) ;
848 if (phi < 0) { phi += twopi ; }
850 if (fSPhi < 0 ) { distSPhi = std::fabs(phi-(fSPhi+twopi))*rho ; }
851 else { distSPhi = std::fabs(phi-fSPhi)*rho ; }
853 distEPhi = std::fabs(phi - fSPhi - fDPhi)*rho ;
855 if (distSPhi < distEPhi)
857 if (distSPhi<distMin) side = kNSPhi ;
861 if (distEPhi < distMin) { side = kNEPhi ; }
868 -p.
y()*(1-fRtor/rho)/pt,
873 p.
y()*(1-fRtor/rho)/pt,
880 norm =
G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0) ;
886 "Undefined side for valid surface normal to solid.");
927 G4double distX = std::abs(p.
x()) - boxDx;
928 G4double distY = std::abs(p.
y()) - boxDy;
929 G4double distZ = std::abs(p.
z()) - boxDz;
930 if (distX >= -halfCarTolerance && p.
x()*v.
x() >= 0)
return kInfinity;
931 if (distY >= -halfCarTolerance && p.
y()*v.
y() >= 0)
return kInfinity;
932 if (distZ >= -halfCarTolerance && p.
z()*v.
z() >= 0)
return kInfinity;
938 G4double safe = std::max(std::max(distX,distY),distZ);
941 G4double dist = safe - 1.e-8*safe - boxMin;
943 return (dist >= kInfinity) ? kInfinity : dist;
948 G4double snxt=kInfinity, sphi=kInfinity;
957 G4double cPhi,sinCPhi=0.,cosCPhi=0.;
974 cPhi = fSPhi + hDPhi ;
975 sinCPhi = std::sin(cPhi) ;
976 cosCPhi = std::cos(cPhi) ;
983 if (fRmin > fRminTolerance)
985 tolORMin2 = (fRmin - fRminTolerance)*(fRmin - fRminTolerance) ;
991 tolORMax2 = (fRmax + fRmaxTolerance)*(fRmax + fRmaxTolerance) ;
995 snxt = SolveNumericJT(p,v,fRmax,
true);
999 sd[0] = SolveNumericJT(p,v,fRmin,
true);
1000 if ( sd[0] < snxt ) { snxt = sd[0] ; }
1015 sinSPhi = std::sin(fSPhi) ;
1016 cosSPhi = std::cos(fSPhi) ;
1017 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1021 Dist = (p.
y()*cosSPhi - p.
x()*sinSPhi) ;
1023 if (Dist < halfCarTolerance)
1028 if ( sphi < 0 ) { sphi = 0 ; }
1030 xi = p.
x() + sphi*v.
x() ;
1031 yi = p.
y() + sphi*v.
y() ;
1032 zi = p.
z() + sphi*v.
z() ;
1033 rhoi = std::hypot(xi,yi);
1034 it2 = zi*zi + (rhoi-fRtor)*(rhoi-fRtor);
1036 if ( it2 >= tolORMin2 && it2 <= tolORMax2 )
1041 if ((yi*cosCPhi-xi*sinCPhi)<=0) { snxt=sphi; }
1047 sinEPhi=std::sin(ePhi);
1048 cosEPhi=std::cos(ePhi);
1049 Comp=-(v.
x()*sinEPhi-v.
y()*cosEPhi);
1053 Dist = -(p.
y()*cosEPhi - p.
x()*sinEPhi) ;
1055 if (Dist < halfCarTolerance )
1061 if (sphi < 0 ) { sphi = 0 ; }
1063 xi = p.
x() + sphi*v.
x() ;
1064 yi = p.
y() + sphi*v.
y() ;
1065 zi = p.
z() + sphi*v.
z() ;
1066 rhoi = std::hypot(xi,yi);
1067 it2 = zi*zi + (rhoi-fRtor)*(rhoi-fRtor);
1069 if (it2 >= tolORMin2 && it2 <= tolORMax2)
1074 if ((yi*cosCPhi-xi*sinCPhi)>=0) { snxt=sphi; }
1080 if(snxt < halfCarTolerance) { snxt = 0.0 ; }
1095 G4double phiC, cosPhiC, sinPhiC, safePhi, ePhi, cosPsi ;
1098 rho = std::hypot(p.
x(),p.
y());
1099 pt = std::hypot(p.
z(),rho-fRtor);
1100 safe1 = fRmin - pt ;
1101 safe2 = pt - fRmax ;
1103 if (safe1 > safe2) { safe = safe1; }
1104 else { safe = safe2; }
1106 if ( fDPhi < twopi && (rho != 0.0) )
1108 phiC = fSPhi + fDPhi*0.5 ;
1109 cosPhiC = std::cos(phiC) ;
1110 sinPhiC = std::sin(phiC) ;
1111 cosPsi = (p.
x()*cosPhiC + p.
y()*sinPhiC)/rho ;
1113 if (cosPsi < std::cos(fDPhi*0.5) )
1115 if ((p.
y()*cosPhiC - p.
x()*sinPhiC) <= 0 )
1117 safePhi = std::fabs(p.
x()*std::sin(fSPhi) - p.
y()*std::cos(fSPhi)) ;
1121 ePhi = fSPhi + fDPhi ;
1122 safePhi = std::fabs(p.
x()*std::sin(ePhi) - p.
y()*std::cos(ePhi)) ;
1124 if (safePhi > safe) { safe = safePhi ; }
1127 if (safe < 0 ) { safe = 0 ; }
1143 ESide side = kNull, sidephi = kNull ;
1144 G4double snxt = kInfinity, sphi, sd[4] ;
1148 G4double sinSPhi, cosSPhi, ePhi, sinEPhi, cosEPhi;
1150 G4double pDistS, compS, pDistE, compE, sphi2, xi, yi, zi, vphi ;
1168 G4double tolRMax = fRmax - fRmaxTolerance ;
1170 G4double vDotNmax = pDotV - fRtor*(v.
x()*p.
x() + v.
y()*p.
y())/rho ;
1171 G4double pDotxyNmax = (1 - fRtor/rho) ;
1173 if( (pt*pt > tolRMax*tolRMax) && (vDotNmax >= 0) )
1179 if ( calcNorm && (pDotxyNmax >= -2.*fRmaxTolerance) )
1182 p.
y()*(1 - fRtor/rho)/pt,
1190 snxt = SolveNumericJT(p,v,fRmax,
false);
1197 G4double tolRMin = fRmin + fRminTolerance ;
1199 if ( (pt*pt < tolRMin*tolRMin) && (vDotNmax < 0) )
1201 if (calcNorm) { *validNorm = false ; }
1205 sd[0] = SolveNumericJT(p,v,fRmin,
false);
1218 snxt = SolveNumericJT(p,v,fRmax,
false);
1223 sd[0] = SolveNumericJT(p,v,fRmin,
false);
1231 if ( calcNorm && (snxt == 0.0) )
1233 *validNorm = false ;
1241 sinSPhi = std::sin(fSPhi) ;
1242 cosSPhi = std::cos(fSPhi) ;
1243 ePhi = fSPhi + fDPhi ;
1244 sinEPhi = std::sin(ePhi) ;
1245 cosEPhi = std::cos(ePhi) ;
1246 cPhi = fSPhi + fDPhi*0.5 ;
1247 sinCPhi = std::sin(cPhi) ;
1248 cosCPhi = std::cos(cPhi) ;
1253 vphi = std::atan2(v.
y(),v.
x()) ;
1255 if ( vphi < fSPhi - halfAngTolerance ) { vphi += twopi; }
1256 else if ( vphi > ePhi + halfAngTolerance ) { vphi -= twopi; }
1258 if ( (p.
x() != 0.0) || (p.
y() != 0.0) )
1260 pDistS = p.
x()*sinSPhi - p.
y()*cosSPhi ;
1261 pDistE = -p.
x()*sinEPhi + p.
y()*cosEPhi ;
1265 compS = -sinSPhi*v.
x() + cosSPhi*v.
y() ;
1266 compE = sinEPhi*v.
x() - cosEPhi*v.
y() ;
1269 if( ( (fDPhi <= pi) && ( (pDistS <= halfCarTolerance)
1270 && (pDistE <= halfCarTolerance) ) )
1271 || ( (fDPhi > pi) && ((pDistS <= halfCarTolerance)
1272 || (pDistE <= halfCarTolerance) ) ) )
1278 sphi = pDistS/compS ;
1280 if (sphi >= -halfCarTolerance)
1282 xi = p.
x() + sphi*v.
x() ;
1283 yi = p.
y() + sphi*v.
y() ;
1292 if ( ((fSPhi-halfAngTolerance)<=vphi)
1293 && ((ePhi+halfAngTolerance)>=vphi) )
1298 else if ( yi*cosCPhi-xi*sinCPhi >=0 )
1319 sphi2 = pDistE/compE ;
1325 xi = p.
x() + sphi2*v.
x() ;
1326 yi = p.
y() + sphi2*v.
y() ;
1333 if( (fSPhi-halfAngTolerance > vphi)
1334 || (ePhi+halfAngTolerance < vphi) )
1342 if ( (yi*cosCPhi-xi*sinCPhi) >= 0)
1364 vphi = std::atan2(v.
y(),v.
x());
1366 if ( ( fSPhi-halfAngTolerance <= vphi ) &&
1367 ( vphi <= ( ePhi+halfAngTolerance ) ) )
1396 xi = p.
x() + snxt*v.
x() ;
1397 yi = p.
y() + snxt*v.
y() ;
1398 zi = p.
z() + snxt*v.
z() ;
1399 rhoi = std::hypot(xi,yi);
1400 it = hypot(zi,rhoi-fRtor);
1402 iDotxyNmax = (1-fRtor/rhoi) ;
1403 if(iDotxyNmax >= -2.*fRmaxTolerance)
1406 yi*(1-fRtor/rhoi)/it,
1412 *validNorm = false ;
1417 *validNorm = false ;
1428 *validNorm = false ;
1435 *n=
G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0);
1440 *validNorm = false ;
1450 std::ostringstream message;
1451 G4long oldprc = message.precision(16);
1452 message <<
"Undefined side for valid surface normal to solid."
1455 <<
"p.x() = " << p.
x()/mm <<
" mm" <<
G4endl
1456 <<
"p.y() = " << p.
y()/mm <<
" mm" <<
G4endl
1459 <<
"v.x() = " << v.
x() <<
G4endl
1460 <<
"v.y() = " << v.
y() <<
G4endl
1463 <<
"snxt = " << snxt/mm <<
" mm" <<
G4endl;
1464 message.precision(oldprc);
1470 if ( snxt<halfCarTolerance ) { snxt=0 ; }
1483 G4double safePhi,phiC,cosPhiC,sinPhiC,ePhi;
1485 rho = std::hypot(p.
x(),p.
y());
1486 pt = std::hypot(p.
z(),rho-fRtor);
1498 G4cout.precision(oldprc);
1499 G4Exception(
"G4Torus::DistanceToOut(p)",
"GeomSolids1002",
1506 safeR1 = pt - fRmin ;
1507 safeR2 = fRmax - pt ;
1509 if (safeR1 < safeR2) { safe = safeR1 ; }
1510 else { safe = safeR2 ; }
1521 phiC = fSPhi + fDPhi*0.5 ;
1522 cosPhiC = std::cos(phiC) ;
1523 sinPhiC = std::sin(phiC) ;
1525 if ((p.
y()*cosPhiC-p.
x()*sinPhiC)<=0)
1527 safePhi = -(p.
x()*std::sin(fSPhi) - p.
y()*std::cos(fSPhi)) ;
1531 ePhi = fSPhi + fDPhi ;
1532 safePhi = (p.
x()*std::sin(ePhi) - p.
y()*std::cos(ePhi)) ;
1534 if (safePhi < safe) { safe = safePhi ; }
1536 if (safe < 0) { safe = 0 ; }
1564 G4long oldprc = os.precision(16);
1565 os <<
"-----------------------------------------------------------\n"
1566 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
1567 <<
" ===================================================\n"
1568 <<
" Solid type: G4Torus\n"
1569 <<
" Parameters: \n"
1570 <<
" inner radius: " << fRmin/mm <<
" mm \n"
1571 <<
" outer radius: " << fRmax/mm <<
" mm \n"
1572 <<
" swept radius: " << fRtor/mm <<
" mm \n"
1573 <<
" starting phi: " << fSPhi/degree <<
" degrees \n"
1574 <<
" delta phi : " << fDPhi/degree <<
" degrees \n"
1575 <<
"-----------------------------------------------------------\n";
1576 os.precision(oldprc);
1587 G4double cosu, sinu,cosv, sinv, aOut, aIn, aSide, chose, phi, theta, rRand;
1589 phi = G4RandFlat::shoot(fSPhi,fSPhi+fDPhi);
1590 theta = G4RandFlat::shoot(0.,twopi);
1592 cosu = std::cos(phi); sinu = std::sin(phi);
1593 cosv = std::cos(theta); sinv = std::sin(theta);
1597 aOut = (fDPhi)*twopi*fRtor*fRmax;
1598 aIn = (fDPhi)*twopi*fRtor*fRmin;
1599 aSide = pi*(fRmax*fRmax-fRmin*fRmin);
1601 if ((fSPhi == 0) && (fDPhi == twopi)){ aSide = 0; }
1602 chose = G4RandFlat::shoot(0.,aOut + aIn + 2.*aSide);
1606 return { (fRtor+fRmax*cosv)*cosu, (fRtor+fRmax*cosv)*sinu, fRmax*sinv };
1608 else if( (chose >= aOut) && (chose < aOut + aIn) )
1610 return { (fRtor+fRmin*cosv)*cosu, (fRtor+fRmin*cosv)*sinu, fRmin*sinv };
1612 else if( (chose >= aOut + aIn) && (chose < aOut + aIn + aSide) )
1615 return { (fRtor+rRand*cosv)*std::cos(fSPhi),
1616 (fRtor+rRand*cosv)*std::sin(fSPhi), rRand*sinv };
1621 return { (fRtor+rRand*cosv)*std::cos(fSPhi+fDPhi),
1622 (fRtor+rRand*cosv)*std::sin(fSPhi+fDPhi), rRand*sinv };
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
void set(double x, double y)
void set(double x, double y, double z)
G4bool BoundingBoxVsVoxelLimits(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
G4bool fRebuildPolyhedron
G4double GetRadiusInRing(G4double rmin, G4double rmax) const
G4CSGSolid & operator=(const G4CSGSolid &rhs)
G4double GetRadialTolerance() const
static G4GeometryTolerance * GetInstance()
G4double GetAngularTolerance() const
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
G4Torus & operator=(const G4Torus &rhs)
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep) override
G4double GetSinEndPhi() const
std::ostream & StreamInfo(std::ostream &os) const override
G4ThreeVector GetPointOnSurface() const override
G4VSolid * Clone() const override
void SetAllParameters(G4double pRmin, G4double pRmax, G4double pRtor, G4double pSPhi, G4double pDPhi)
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
EInside Inside(const G4ThreeVector &p) const override
G4GeometryType GetEntityType() const override
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
G4Polyhedron * CreatePolyhedron() const override
G4Torus(const G4String &pName, G4double pRmin, G4double pRmax, G4double pRtor, G4double pSPhi, G4double pDPhi)
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
G4double GetCosStartPhi() const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const override
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
G4double GetCosEndPhi() const
G4double GetSinStartPhi() const
virtual void AddSolid(const G4Box &)=0
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4double GetMinExtent(const EAxis pAxis) const
G4double GetMaxExtent(const EAxis pAxis) const