75 using namespace CLHEP;
95 fFullPhiSphere(true), fFullThetaSphere(true)
102 if ( (pRmin >= pRmax) || (pRmax < 1.1*kRadTolerance) || (pRmin < 0) )
104 std::ostringstream message;
105 message <<
"Invalid radii for Solid: " <<
GetName() <<
G4endl
106 <<
" pRmin = " << pRmin <<
", pRmax = " << pRmax;
107 G4Exception(
"G4Sphere::G4Sphere()",
"GeomSolids0002",
110 fRmin=pRmin; fRmax=pRmax;
111 fRminTolerance = (fRmin) ? std::max( kRadTolerance, fEpsilon*fRmin ) : 0;
112 fRmaxTolerance = std::max( kRadTolerance, fEpsilon*fRmax );
116 CheckPhiAngles(pSPhi, pDPhi);
117 CheckThetaAngles(pSTheta, pDTheta);
126 :
G4CSGSolid(a), fRminTolerance(0.), fRmaxTolerance(0.),
127 kAngTolerance(0.), kRadTolerance(0.), fEpsilon(0.),
128 fRmin(0.), fRmax(0.), fSPhi(0.), fDPhi(0.), fSTheta(0.),
129 fDTheta(0.), sinCPhi(0.), cosCPhi(0.), cosHDPhiOT(0.), cosHDPhiIT(0.),
130 sinSPhi(0.), cosSPhi(0.), sinEPhi(0.), cosEPhi(0.), hDPhi(0.), cPhi(0.),
131 ePhi(0.), sinSTheta(0.), cosSTheta(0.), sinETheta(0.), cosETheta(0.),
132 tanSTheta(0.), tanSTheta2(0.), tanETheta(0.), tanETheta2(0.), eTheta(0.),
133 fFullPhiSphere(false), fFullThetaSphere(false), fFullSphere(true)
150 :
G4CSGSolid(rhs), fRminTolerance(rhs.fRminTolerance),
151 fRmaxTolerance(rhs.fRmaxTolerance), kAngTolerance(rhs.kAngTolerance),
152 kRadTolerance(rhs.kRadTolerance), fEpsilon(rhs.fEpsilon),
153 fRmin(rhs.fRmin), fRmax(rhs.fRmax), fSPhi(rhs.fSPhi), fDPhi(rhs.fDPhi),
154 fSTheta(rhs.fSTheta), fDTheta(rhs.fDTheta),
155 sinCPhi(rhs.sinCPhi), cosCPhi(rhs.cosCPhi),
156 cosHDPhiOT(rhs.cosHDPhiOT), cosHDPhiIT(rhs.cosHDPhiIT),
157 sinSPhi(rhs.sinSPhi), cosSPhi(rhs.cosSPhi),
158 sinEPhi(rhs.sinEPhi), cosEPhi(rhs.cosEPhi),
159 hDPhi(rhs.hDPhi), cPhi(rhs.cPhi), ePhi(rhs.ePhi),
160 sinSTheta(rhs.sinSTheta), cosSTheta(rhs.cosSTheta),
161 sinETheta(rhs.sinETheta), cosETheta(rhs.cosETheta),
162 tanSTheta(rhs.tanSTheta), tanSTheta2(rhs.tanSTheta2),
163 tanETheta(rhs.tanETheta), tanETheta2(rhs.tanETheta2), eTheta(rhs.eTheta),
164 fFullPhiSphere(rhs.fFullPhiSphere), fFullThetaSphere(rhs.fFullThetaSphere),
165 fFullSphere(rhs.fFullSphere)
177 if (
this == &rhs) {
return *
this; }
185 fRminTolerance = rhs.fRminTolerance; fRmaxTolerance = rhs.fRmaxTolerance;
186 kAngTolerance = rhs.kAngTolerance; kRadTolerance = rhs.kRadTolerance;
187 fEpsilon = rhs.fEpsilon; fRmin = rhs.fRmin; fRmax = rhs.fRmax;
188 fSPhi = rhs.fSPhi; fDPhi = rhs.fDPhi; fSTheta = rhs.fSTheta;
189 fDTheta = rhs.fDTheta; sinCPhi = rhs.sinCPhi; cosCPhi = rhs.cosCPhi;
190 cosHDPhiOT = rhs.cosHDPhiOT; cosHDPhiIT = rhs.cosHDPhiIT;
191 sinSPhi = rhs.sinSPhi; cosSPhi = rhs.cosSPhi;
192 sinEPhi = rhs.sinEPhi; cosEPhi = rhs.cosEPhi;
193 hDPhi = rhs.hDPhi; cPhi = rhs.cPhi; ePhi = rhs.ePhi;
194 sinSTheta = rhs.sinSTheta; cosSTheta = rhs.cosSTheta;
195 sinETheta = rhs.sinETheta; cosETheta = rhs.cosETheta;
196 tanSTheta = rhs.tanSTheta; tanSTheta2 = rhs.tanSTheta2;
197 tanETheta = rhs.tanETheta; tanETheta2 = rhs.tanETheta2;
198 eTheta = rhs.eTheta; fFullPhiSphere = rhs.fFullPhiSphere;
199 fFullThetaSphere = rhs.fFullThetaSphere; fFullSphere = rhs.fFullSphere;
237 G4double diff1,diff2,delta,maxDiff,newMin,newMax;
316 if ((yoff1>=0) && (yoff2>=0))
328 delta=fRmax*fRmax-yoff1*yoff1;
329 diff1=(delta>0.) ? std::sqrt(delta) : 0.;
330 delta=fRmax*fRmax-yoff2*yoff2;
331 diff2=(delta>0.) ? std::sqrt(delta) : 0.;
332 maxDiff=(diff1>diff2) ? diff1:diff2;
333 newMin=xoffset-maxDiff;
334 newMax=xoffset+maxDiff;
335 pMin=(newMin<xMin) ? xMin : newMin;
336 pMax=(newMax>xMax) ? xMax : newMax;
342 if ((xoff1>=0) && (xoff2>=0))
354 delta=fRmax*fRmax-xoff1*xoff1;
355 diff1=(delta>0.) ? std::sqrt(delta) : 0.;
356 delta=fRmax*fRmax-xoff2*xoff2;
357 diff2=(delta>0.) ? std::sqrt(delta) : 0.;
358 maxDiff=(diff1>diff2) ? diff1:diff2;
359 newMin=yoffset-maxDiff;
360 newMax=yoffset+maxDiff;
361 pMin=(newMin<yMin) ? yMin : newMin;
362 pMax=(newMax>yMax) ? yMax : newMax;
379 G4int i,j,noEntries,noBetweenSections;
380 G4bool existsAfterClip=
false;
385 G4int noPolygonVertices ;
386 vertices=CreateRotatedVertices(pTransform,noPolygonVertices);
391 noEntries=vertices->size();
392 noBetweenSections=noEntries-noPolygonVertices;
395 for (i=0;i<noEntries;i+=noPolygonVertices)
397 for(j=0;j<(noPolygonVertices/2)-1;j++)
399 ThetaPolygon.push_back((*vertices)[i+j]) ;
400 ThetaPolygon.push_back((*vertices)[i+j+1]) ;
401 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-2-j]) ;
402 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-1-j]) ;
404 ThetaPolygon.clear() ;
407 for (i=0;i<noBetweenSections;i+=noPolygonVertices)
409 for(j=0;j<noPolygonVertices-1;j++)
411 ThetaPolygon.push_back((*vertices)[i+j]) ;
412 ThetaPolygon.push_back((*vertices)[i+j+1]) ;
413 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices+j+1]) ;
414 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices+j]) ;
416 ThetaPolygon.clear() ;
418 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-1]) ;
419 ThetaPolygon.push_back((*vertices)[i]) ;
420 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices]) ;
421 ThetaPolygon.push_back((*vertices)[i+2*noPolygonVertices-1]) ;
423 ThetaPolygon.clear() ;
426 if ((pMin!=kInfinity) || (pMax!=-kInfinity))
428 existsAfterClip=
true;
449 existsAfterClip=
true;
455 return existsAfterClip;
467 G4double rho,rho2,rad2,tolRMin,tolRMax;
470 static const G4double halfAngTolerance = kAngTolerance*0.5;
471 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
472 const G4double halfRminTolerance = fRminTolerance*0.5;
473 const G4double Rmax_minus = fRmax - halfRmaxTolerance;
474 const G4double Rmin_plus = (fRmin > 0) ? fRmin+halfRminTolerance : 0;
476 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
477 rad2 = rho2 + p.
z()*p.
z() ;
482 tolRMax = Rmax_minus;
484 if ( (rad2 <= Rmax_minus*Rmax_minus) && (rad2 >= Rmin_plus*Rmin_plus) )
490 tolRMax = fRmax + halfRmaxTolerance;
491 tolRMin = std::max(fRmin-halfRminTolerance, 0.);
492 if ( (rad2 <= tolRMax*tolRMax) && (rad2 >= tolRMin*tolRMin) )
504 if ( !fFullPhiSphere && rho2 )
506 pPhi = std::atan2(p.
y(),p.
x()) ;
508 if ( pPhi < fSPhi - halfAngTolerance ) { pPhi +=
twopi; }
509 else if ( pPhi > ePhi + halfAngTolerance ) { pPhi -=
twopi; }
511 if ( (pPhi < fSPhi - halfAngTolerance)
512 || (pPhi > ePhi + halfAngTolerance) ) {
return in =
kOutside; }
516 if ( (pPhi < fSPhi + halfAngTolerance)
517 || (pPhi > ePhi - halfAngTolerance) ) { in =
kSurface; }
523 if ( (rho2 || p.
z()) && (!fFullThetaSphere) )
525 rho = std::sqrt(rho2);
526 pTheta = std::atan2(rho,p.
z());
530 if ( (pTheta < fSTheta + halfAngTolerance)
531 || (pTheta > eTheta - halfAngTolerance) )
533 if ( (pTheta >= fSTheta - halfAngTolerance)
534 && (pTheta <= eTheta + halfAngTolerance) )
546 if ( (pTheta < fSTheta - halfAngTolerance)
547 || (pTheta > eTheta + halfAngTolerance) )
564 G4int noSurfaces = 0;
565 G4double rho, rho2, radius, pTheta, pPhi=0.;
567 G4double distSPhi = kInfinity, distEPhi = kInfinity;
568 G4double distSTheta = kInfinity, distETheta = kInfinity;
573 static const G4double halfAngTolerance = 0.5*kAngTolerance;
575 rho2 = p.
x()*p.
x()+p.
y()*p.
y();
576 radius = std::sqrt(rho2+p.
z()*p.
z());
577 rho = std::sqrt(rho2);
579 G4double distRMax = std::fabs(radius-fRmax);
580 if (fRmin) distRMin = std::fabs(radius-fRmin);
582 if ( rho && !fFullSphere )
584 pPhi = std::atan2(p.
y(),p.
x());
586 if (pPhi < fSPhi-halfAngTolerance) { pPhi +=
twopi; }
587 else if (pPhi > ePhi+halfAngTolerance) { pPhi -=
twopi; }
589 if ( !fFullPhiSphere )
593 distSPhi = std::fabs( pPhi-fSPhi );
594 distEPhi = std::fabs( pPhi-ePhi );
604 if ( !fFullThetaSphere )
608 pTheta = std::atan2(rho,p.
z());
609 distSTheta = std::fabs(pTheta-fSTheta);
610 distETheta = std::fabs(pTheta-eTheta);
613 -cosSTheta*p.
y()/rho,
634 if( radius ) { nR =
G4ThreeVector(p.
x()/radius,p.
y()/radius,p.
z()/radius); }
636 if( distRMax <= halfCarTolerance )
641 if( fRmin && (distRMin <= halfCarTolerance) )
646 if( !fFullPhiSphere )
648 if (distSPhi <= halfAngTolerance)
653 if (distEPhi <= halfAngTolerance)
659 if ( !fFullThetaSphere )
661 if ((distSTheta <= halfAngTolerance) && (fSTheta > 0.))
664 if ((radius <= halfCarTolerance) && fFullPhiSphere) { sumnorm += nZ; }
665 else { sumnorm += nTs; }
667 if ((distETheta <= halfAngTolerance) && (eTheta <
pi))
670 if ((radius <= halfCarTolerance) && fFullPhiSphere) { sumnorm -= nZ; }
671 else { sumnorm += nTe; }
672 if(sumnorm.
z() == 0.) { sumnorm += nZ; }
675 if ( noSurfaces == 0 )
678 G4Exception(
"G4Sphere::SurfaceNormal(p)",
"GeomSolids1002",
681 norm = ApproxSurfaceNormal(p);
683 else if ( noSurfaces == 1 ) { norm = sumnorm; }
684 else { norm = sumnorm.
unit(); }
698 G4double rho,rho2,radius,pPhi,pTheta;
699 G4double distRMin,distRMax,distSPhi,distEPhi,
700 distSTheta,distETheta,distMin;
702 rho2=p.
x()*p.
x()+p.
y()*p.
y();
703 radius=std::sqrt(rho2+p.
z()*p.
z());
710 distRMax=std::fabs(radius-fRmax);
713 distRMin=std::fabs(radius-fRmin);
715 if (distRMin<distRMax)
737 pPhi = std::atan2(p.
y(),p.
x());
738 if (pPhi<0) { pPhi +=
twopi; }
740 if (!fFullPhiSphere && rho)
744 distSPhi=std::fabs(pPhi-(fSPhi+
twopi))*rho;
748 distSPhi=std::fabs(pPhi-fSPhi)*rho;
751 distEPhi=std::fabs(pPhi-fSPhi-fDPhi)*rho;
755 if (distSPhi<distEPhi)
757 if (distSPhi<distMin)
765 if (distEPhi<distMin)
777 if (!fFullThetaSphere && radius)
779 pTheta=std::atan2(rho,p.
z());
780 distSTheta=std::fabs(pTheta-fSTheta)*radius;
781 distETheta=std::fabs(pTheta-fSTheta-fDTheta)*radius;
785 if (distSTheta<distETheta)
787 if (distSTheta<distMin)
789 distMin = distSTheta ;
795 if (distETheta<distMin)
797 distMin = distETheta ;
819 -cosSTheta*std::sin(pPhi),
824 cosETheta*std::sin(pPhi),
831 "Undefined side for valid surface normal to solid.");
871 G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
872 G4double tolSTheta=0., tolETheta=0. ;
876 static const G4double halfAngTolerance = kAngTolerance*0.5;
877 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
878 const G4double halfRminTolerance = fRminTolerance*0.5;
879 const G4double tolORMin2 = (fRmin>halfRminTolerance)
880 ? (fRmin-halfRminTolerance)*(fRmin-halfRminTolerance) : 0;
882 (fRmin+halfRminTolerance)*(fRmin+halfRminTolerance);
884 (fRmax+halfRmaxTolerance)*(fRmax+halfRmaxTolerance);
886 (fRmax-halfRmaxTolerance)*(fRmax-halfRmaxTolerance);
890 G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
907 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
908 rad2 = rho2 + p.
z()*p.
z() ;
909 pTheta = std::atan2(std::sqrt(rho2),p.
z()) ;
911 pDotV2d = p.
x()*v.
x() + p.
y()*v.
y() ;
912 pDotV3d = pDotV2d + p.
z()*v.
z() ;
916 if (!fFullThetaSphere)
918 tolSTheta = fSTheta - halfAngTolerance ;
919 tolETheta = eTheta + halfAngTolerance ;
936 c = rad2 - fRmax*fRmax ;
938 if (c > fRmaxTolerance*fRmax)
943 d2 = pDotV3d*pDotV3d -
c ;
947 sd = -pDotV3d - std::sqrt(d2) ;
953 G4double fTerm = sd-std::fmod(sd,dRmax);
956 xi = p.
x() + sd*v.
x() ;
957 yi = p.
y() + sd*v.
y() ;
958 rhoi = std::sqrt(xi*xi + yi*yi) ;
960 if (!fFullPhiSphere && rhoi)
962 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
964 if (cosPsi >= cosHDPhiOT)
966 if (!fFullThetaSphere)
968 zi = p.
z() + sd*v.
z() ;
973 iTheta = std::atan2(rhoi,zi) ;
974 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
987 if (!fFullThetaSphere)
989 zi = p.
z() + sd*v.
z() ;
994 iTheta = std::atan2(rhoi,zi) ;
995 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1009 return snxt=kInfinity;
1017 d2 = pDotV3d*pDotV3d -
c ;
1019 if ( (rad2 > tolIRMax2)
1020 && ( (d2 >= fRmaxTolerance*fRmax) && (pDotV3d < 0) ) )
1022 if (!fFullPhiSphere)
1027 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1029 if (cosPsi>=cosHDPhiIT)
1033 if ( !fFullThetaSphere )
1035 if ( (pTheta >= tolSTheta + kAngTolerance)
1036 && (pTheta <= tolETheta - kAngTolerance) )
1049 if ( !fFullThetaSphere )
1051 if ( (pTheta >= tolSTheta + kAngTolerance)
1052 && (pTheta <= tolETheta - kAngTolerance) )
1072 c = rad2 - fRmin*fRmin ;
1073 d2 = pDotV3d*pDotV3d -
c ;
1078 if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
1081 if ( !fFullPhiSphere )
1086 cosPsi = (p.
x()*cosCPhi+p.
y()*sinCPhi)/std::sqrt(rho2) ;
1087 if (cosPsi >= cosHDPhiIT)
1091 if ( !fFullThetaSphere )
1093 if ( (pTheta >= tolSTheta + kAngTolerance)
1094 && (pTheta <= tolETheta - kAngTolerance) )
1107 if ( !fFullThetaSphere )
1109 if ( (pTheta >= tolSTheta + kAngTolerance)
1110 && (pTheta <= tolETheta - kAngTolerance) )
1125 sd = -pDotV3d + std::sqrt(d2) ;
1126 if ( sd >= halfRminTolerance )
1128 xi = p.
x() + sd*v.
x() ;
1129 yi = p.
y() + sd*v.
y() ;
1130 rhoi = std::sqrt(xi*xi+yi*yi) ;
1132 if ( !fFullPhiSphere && rhoi )
1134 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
1136 if (cosPsi >= cosHDPhiOT)
1138 if ( !fFullThetaSphere )
1140 zi = p.
z() + sd*v.
z() ;
1145 iTheta = std::atan2(rhoi,zi) ;
1146 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
1159 if ( !fFullThetaSphere )
1161 zi = p.
z() + sd*v.
z() ;
1166 iTheta = std::atan2(rhoi,zi) ;
1167 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1191 if ( !fFullPhiSphere )
1196 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1200 Dist = p.
y()*cosSPhi - p.
x()*sinSPhi ;
1202 if (Dist < halfCarTolerance)
1210 xi = p.
x() + sd*v.
x() ;
1211 yi = p.
y() + sd*v.
y() ;
1212 zi = p.
z() + sd*v.
z() ;
1213 rhoi2 = xi*xi + yi*yi ;
1214 radi2 = rhoi2 + zi*zi ;
1225 if ( (radi2 <= tolORMax2)
1226 && (radi2 >= tolORMin2)
1227 && ((yi*cosCPhi-xi*sinCPhi) <= 0) )
1233 if ( !fFullThetaSphere )
1235 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1236 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1241 if ((yi*cosCPhi-xi*sinCPhi) <= 0)
1259 Comp = -( v.
x()*sinEPhi-v.
y()*cosEPhi ) ;
1263 Dist = -(p.
y()*cosEPhi-p.
x()*sinEPhi) ;
1264 if ( Dist < halfCarTolerance )
1272 xi = p.
x() + sd*v.
x() ;
1273 yi = p.
y() + sd*v.
y() ;
1274 zi = p.
z() + sd*v.
z() ;
1275 rhoi2 = xi*xi + yi*yi ;
1276 radi2 = rhoi2 + zi*zi ;
1287 if ( (radi2 <= tolORMax2)
1288 && (radi2 >= tolORMin2)
1289 && ((yi*cosCPhi-xi*sinCPhi) >= 0) )
1295 if ( !fFullThetaSphere )
1297 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1298 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1303 if ((yi*cosCPhi-xi*sinCPhi) >= 0)
1321 if ( !fFullThetaSphere )
1345 dist2STheta = rho2 - p.
z()*p.
z()*tanSTheta2 ;
1349 dist2STheta = kInfinity ;
1353 dist2ETheta=rho2-p.
z()*p.
z()*tanETheta2;
1357 dist2ETheta=kInfinity;
1359 if ( pTheta < tolSTheta )
1364 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1365 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1369 c = dist2STheta/
t1 ;
1376 zi = p.
z() + sd*v.
z();
1378 if ( (sd < 0) || (zi*(fSTheta -
halfpi) > 0) )
1382 if ((sd >= 0) && (sd < snxt))
1384 xi = p.
x() + sd*v.
x();
1385 yi = p.
y() + sd*v.
y();
1386 zi = p.
z() + sd*v.
z();
1387 rhoi2 = xi*xi + yi*yi;
1388 radi2 = rhoi2 + zi*zi;
1389 if ( (radi2 <= tolORMax2)
1390 && (radi2 >= tolORMin2)
1391 && (zi*(fSTheta -
halfpi) <= 0) )
1393 if ( !fFullPhiSphere && rhoi2 )
1395 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1396 if (cosPsi >= cosHDPhiOT)
1415 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1416 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1420 c = dist2ETheta/
t1 ;
1428 if ( (sd >= 0) && (sd < snxt) )
1430 xi = p.
x() + sd*v.
x() ;
1431 yi = p.
y() + sd*v.
y() ;
1432 zi = p.
z() + sd*v.
z() ;
1433 rhoi2 = xi*xi + yi*yi ;
1434 radi2 = rhoi2 + zi*zi ;
1436 if ( (radi2 <= tolORMax2)
1437 && (radi2 >= tolORMin2)
1438 && (zi*(eTheta -
halfpi) <= 0) )
1440 if (!fFullPhiSphere && rhoi2)
1442 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1443 if (cosPsi >= cosHDPhiOT)
1458 else if ( pTheta > tolETheta )
1464 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1465 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1469 c = dist2ETheta/
t1 ;
1476 zi = p.
z() + sd*v.
z();
1478 if ( (sd < 0) || (zi*(eTheta -
halfpi) > 0) )
1482 if ( (sd >= 0) && (sd < snxt) )
1484 xi = p.
x() + sd*v.
x() ;
1485 yi = p.
y() + sd*v.
y() ;
1486 zi = p.
z() + sd*v.
z() ;
1487 rhoi2 = xi*xi + yi*yi ;
1488 radi2 = rhoi2 + zi*zi ;
1490 if ( (radi2 <= tolORMax2)
1491 && (radi2 >= tolORMin2)
1492 && (zi*(eTheta -
halfpi) <= 0) )
1494 if (!fFullPhiSphere && rhoi2)
1496 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1497 if (cosPsi >= cosHDPhiOT)
1516 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1517 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1521 c = dist2STheta/
t1 ;
1529 if ( (sd >= 0) && (sd < snxt) )
1531 xi = p.
x() + sd*v.
x() ;
1532 yi = p.
y() + sd*v.
y() ;
1533 zi = p.
z() + sd*v.
z() ;
1534 rhoi2 = xi*xi + yi*yi ;
1535 radi2 = rhoi2 + zi*zi ;
1537 if ( (radi2 <= tolORMax2)
1538 && (radi2 >= tolORMin2)
1539 && (zi*(fSTheta -
halfpi) <= 0) )
1541 if (!fFullPhiSphere && rhoi2)
1543 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1544 if (cosPsi >= cosHDPhiOT)
1559 else if ( (pTheta < tolSTheta + kAngTolerance)
1560 && (fSTheta > halfAngTolerance) )
1566 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1567 if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta<
halfpi)
1568 || (t2<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>
halfpi)
1569 || (v.
z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta==
halfpi) )
1571 if (!fFullPhiSphere && rho2)
1573 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1574 if (cosPsi >= cosHDPhiIT)
1587 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1591 c = dist2STheta/
t1 ;
1598 if ( (sd >= halfCarTolerance) && (sd < snxt) && (fSTheta < halfpi) )
1600 xi = p.
x() + sd*v.
x() ;
1601 yi = p.
y() + sd*v.
y() ;
1602 zi = p.
z() + sd*v.
z() ;
1603 rhoi2 = xi*xi + yi*yi ;
1604 radi2 = rhoi2 + zi*zi ;
1606 if ( (radi2 <= tolORMax2)
1607 && (radi2 >= tolORMin2)
1608 && (zi*(fSTheta - halfpi) <= 0) )
1610 if ( !fFullPhiSphere && rhoi2 )
1612 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1613 if ( cosPsi >= cosHDPhiOT )
1627 else if ((pTheta > tolETheta-kAngTolerance) && (eTheta <
pi-kAngTolerance))
1634 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1636 if ( ((t2<0) && (eTheta <
halfpi)
1637 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1638 || ((t2>=0) && (eTheta >
halfpi)
1639 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1640 || ((v.
z()>0) && (eTheta ==
halfpi)
1641 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2)) )
1643 if (!fFullPhiSphere && rho2)
1645 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1646 if (cosPsi >= cosHDPhiIT)
1659 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1663 c = dist2ETheta/
t1 ;
1671 if ( (sd >= halfCarTolerance)
1672 && (sd < snxt) && (eTheta >
halfpi) )
1674 xi = p.
x() + sd*v.
x() ;
1675 yi = p.
y() + sd*v.
y() ;
1676 zi = p.
z() + sd*v.
z() ;
1677 rhoi2 = xi*xi + yi*yi ;
1678 radi2 = rhoi2 + zi*zi ;
1680 if ( (radi2 <= tolORMax2)
1681 && (radi2 >= tolORMin2)
1682 && (zi*(eTheta -
halfpi) <= 0) )
1684 if (!fFullPhiSphere && rhoi2)
1686 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1687 if (cosPsi >= cosHDPhiOT)
1706 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1707 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1711 c = dist2STheta/
t1 ;
1719 if ((sd >= 0) && (sd < snxt))
1721 xi = p.
x() + sd*v.
x() ;
1722 yi = p.
y() + sd*v.
y() ;
1723 zi = p.
z() + sd*v.
z() ;
1724 rhoi2 = xi*xi + yi*yi ;
1725 radi2 = rhoi2 + zi*zi ;
1727 if ( (radi2 <= tolORMax2)
1728 && (radi2 >= tolORMin2)
1729 && (zi*(fSTheta -
halfpi) <= 0) )
1731 if (!fFullPhiSphere && rhoi2)
1733 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1734 if (cosPsi >= cosHDPhiOT)
1747 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1748 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1752 c = dist2ETheta/
t1 ;
1760 if ((sd >= 0) && (sd < snxt))
1762 xi = p.
x() + sd*v.
x() ;
1763 yi = p.
y() + sd*v.
y() ;
1764 zi = p.
z() + sd*v.
z() ;
1765 rhoi2 = xi*xi + yi*yi ;
1766 radi2 = rhoi2 + zi*zi ;
1768 if ( (radi2 <= tolORMax2)
1769 && (radi2 >= tolORMin2)
1770 && (zi*(eTheta -
halfpi) <= 0) )
1772 if (!fFullPhiSphere && rhoi2)
1774 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1775 if ( cosPsi >= cosHDPhiOT )
1803 G4double safe=0.0,safeRMin,safeRMax,safePhi,safeTheta;
1807 rho2=p.
x()*p.
x()+p.
y()*p.
y();
1808 rds=std::sqrt(rho2+p.
z()*p.
z());
1809 rho=std::sqrt(rho2);
1818 if (safeRMin>safeRMax)
1835 if (!fFullPhiSphere && rho)
1839 cosPsi=(p.
x()*cosCPhi+p.
y()*sinCPhi)/rho;
1840 if (cosPsi<std::cos(hDPhi))
1844 if ((p.
y()*cosCPhi-p.
x()*sinCPhi)<=0)
1846 safePhi=std::fabs(p.
x()*sinSPhi-p.
y()*cosSPhi);
1850 safePhi=std::fabs(p.
x()*sinEPhi-p.
y()*cosEPhi);
1852 if (safePhi>safe) { safe=safePhi; }
1858 if ((rds!=0.0) && (!fFullThetaSphere))
1860 pTheta=std::acos(p.
z()/rds);
1861 if (pTheta<0) { pTheta+=
pi; }
1862 dTheta1=fSTheta-pTheta;
1863 dTheta2=pTheta-eTheta;
1864 if (dTheta1>dTheta2)
1868 safeTheta=rds*std::sin(dTheta1);
1869 if (safe<=safeTheta)
1879 safeTheta=rds*std::sin(dTheta2);
1880 if (safe<=safeTheta)
1888 if (safe<0) { safe=0; }
1904 G4double sphi= kInfinity,stheta= kInfinity;
1905 ESide side=kNull,sidephi=kNull,sidetheta=kNull;
1908 static const G4double halfAngTolerance = kAngTolerance*0.5;
1909 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
1910 const G4double halfRminTolerance = fRminTolerance*0.5;
1911 const G4double Rmax_plus = fRmax + halfRmaxTolerance;
1912 const G4double Rmin_minus = (fRmin) ? fRmin-halfRminTolerance : 0;
1918 G4double pDistS,compS,pDistE,compE,sphi2,vphi;
1920 G4double rho2,rad2,pDotV2d,pDotV3d;
1927 G4double dist2STheta, dist2ETheta, distTheta;
1932 rho2 = p.
x()*p.
x()+p.
y()*p.
y();
1933 rad2 = rho2+p.
z()*p.
z();
1935 pDotV2d = p.
x()*v.
x()+p.
y()*v.
y();
1936 pDotV3d = pDotV2d+p.
z()*v.
z();
1954 if( (rad2 <= Rmax_plus*Rmax_plus) && (rad2 >= Rmin_minus*Rmin_minus) )
1956 c = rad2 - fRmax*fRmax;
1958 if (c < fRmaxTolerance*fRmax)
1969 d2 = pDotV3d*pDotV3d -
c;
1971 if( (c >- fRmaxTolerance*fRmax)
1972 && ((pDotV3d >=0) || (d2 < 0)) )
1984 snxt = -pDotV3d+std::sqrt(d2);
1995 c = rad2 - fRmin*fRmin;
1996 d2 = pDotV3d*pDotV3d -
c;
1998 if (c >- fRminTolerance*fRmin)
2000 if ( (c < fRminTolerance*fRmin)
2001 && (d2 >= fRminTolerance*fRmin) && (pDotV3d < 0) )
2003 if(calcNorm) { *validNorm =
false; }
2010 sd = -pDotV3d-std::sqrt(d2);
2025 if ( !fFullThetaSphere )
2051 if( std::fabs(tanSTheta) > 5./kAngTolerance )
2055 if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
2064 stheta = -p.
z()/v.
z();
2065 sidetheta = kSTheta;
2070 t1 = 1-v.
z()*v.
z()*(1+tanSTheta2);
2071 t2 = pDotV2d-p.
z()*v.
z()*tanSTheta2;
2072 dist2STheta = rho2-p.
z()*p.
z()*tanSTheta2;
2074 distTheta = std::sqrt(rho2)-p.
z()*tanSTheta;
2076 if( std::fabs(t1) < halfAngTolerance )
2080 if(std::fabs(distTheta) < halfRmaxTolerance)
2082 if( (fSTheta <
halfpi) && (p.
z() > 0.) )
2084 if( calcNorm ) { *validNorm =
false; }
2087 else if( (fSTheta >
halfpi) && (p.
z() <= 0) )
2094 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
2098 std::sin(fSTheta) );
2105 stheta = -0.5*dist2STheta/
t2;
2106 sidetheta = kSTheta;
2111 if( std::fabs(distTheta) < halfRmaxTolerance )
2113 if( (fSTheta >
halfpi) && (t2 >= 0.) )
2120 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
2124 std::sin(fSTheta) );
2130 else if( (fSTheta <
halfpi) && (t2 < 0.) && (p.
z() >=0.) )
2132 if( calcNorm ) { *validNorm =
false; }
2148 if ( ((std::fabs(
s) < halfRmaxTolerance) && (t2 < 0.))
2149 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() > 0.) ) )
2153 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() <= 0.) )
2156 sidetheta = kSTheta;
2163 if ( ( (std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.) )
2164 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() < 0.) ) )
2168 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() >= 0.) )
2171 sidetheta = kSTheta;
2180 if( std::fabs(tanETheta) > 5./kAngTolerance )
2184 if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
2198 sidetheta = kETheta;
2204 t1 = 1-v.
z()*v.
z()*(1+tanETheta2);
2205 t2 = pDotV2d-p.
z()*v.
z()*tanETheta2;
2206 dist2ETheta = rho2-p.
z()*p.
z()*tanETheta2;
2208 distTheta = std::sqrt(rho2)-p.
z()*tanETheta;
2210 if( std::fabs(t1) < halfAngTolerance )
2214 if(std::fabs(distTheta) < halfRmaxTolerance)
2216 if( (eTheta >
halfpi) && (p.
z() < 0.) )
2218 if( calcNorm ) { *validNorm =
false; }
2221 else if ( (eTheta <
halfpi) && (p.
z() >= 0) )
2228 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2238 sd = -0.5*dist2ETheta/
t2;
2243 sidetheta = kETheta;
2249 if ( std::fabs(distTheta) < halfRmaxTolerance )
2251 if( (eTheta <
halfpi) && (t2 >= 0.) )
2258 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2267 else if ( (eTheta >
halfpi)
2268 && (t2 < 0.) && (p.
z() <=0.) )
2270 if( calcNorm ) { *validNorm =
false; }
2286 if( ((std::fabs(sd) < halfRmaxTolerance) && (t2 < 0.))
2291 if( sd > halfRmaxTolerance )
2296 sidetheta = kETheta;
2304 if ( ((std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.))
2305 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() > 0.) ) )
2309 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() <= 0.) )
2314 sidetheta = kETheta;
2327 if ( !fFullPhiSphere )
2329 if ( p.
x() || p.
y() )
2333 pDistS=p.
x()*sinSPhi-p.
y()*cosSPhi;
2334 pDistE=-p.
x()*sinEPhi+p.
y()*cosEPhi;
2338 compS = -sinSPhi*v.
x()+cosSPhi*v.
y() ;
2339 compE = sinEPhi*v.
x()-cosEPhi*v.
y() ;
2342 if ( (pDistS <= 0) && (pDistE <= 0) )
2348 sphi = pDistS/compS ;
2349 xi = p.
x()+sphi*v.
x() ;
2350 yi = p.
y()+sphi*v.
y() ;
2356 vphi = std::atan2(v.
y(),v.
x());
2358 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2359 && ( (ePhi+halfAngTolerance) >= vphi) )
2364 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2371 if ( pDistS > -halfCarTolerance) { sphi = 0; }
2374 else { sphi = kInfinity; }
2378 sphi2=pDistE/compE ;
2381 xi = p.
x()+sphi2*v.
x() ;
2382 yi = p.
y()+sphi2*v.
y() ;
2390 vphi = std::atan2(v.
y(),v.
x()) ;
2392 if( !((fSPhi-halfAngTolerance <= vphi)
2393 &&(fSPhi+fDPhi+halfAngTolerance >= vphi)) )
2396 if ( pDistE <= -halfCarTolerance ) { sphi = sphi2; }
2397 else { sphi = 0.0; }
2400 else if ((yi*cosCPhi-xi*sinCPhi)>=0)
2403 if ( pDistE <= -halfCarTolerance )
2415 else if ((pDistS >= 0) && (pDistE >= 0))
2417 if ( pDistS <= pDistE )
2427 if ( (compS < 0) && (compE < 0) ) { sphi = 0; }
2428 else { sphi = kInfinity; }
2435 if ( (compS >= 0) && (compE >= 0) ) { sphi = kInfinity; }
2439 else if ( (pDistS > 0) && (pDistE < 0) )
2447 sphi = pDistE/compE ;
2448 xi = p.
x() + sphi*v.
x() ;
2449 yi = p.
y() + sphi*v.
y() ;
2456 vphi = std::atan2(v.
y(),v.
x());
2458 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2459 && ( (ePhi+halfAngTolerance) >= vphi) )
2464 else if ( ( yi*cosCPhi - xi*sinCPhi ) <= 0 )
2471 if ( pDistE > -halfCarTolerance ) { sphi = 0.; }
2485 sphi = pDistE/compE ;
2486 xi = p.
x() + sphi*v.
x() ;
2487 yi = p.
y() + sphi*v.
y() ;
2494 vphi = std::atan2(v.
y(),v.
x());
2496 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2497 && ( (ePhi+halfAngTolerance) >= vphi) )
2502 else if ( ( yi*cosCPhi - xi*sinCPhi) <= 0 )
2511 else sphi=kInfinity;
2530 xi=p.
x()+sphi*v.
x();
2531 yi=p.
y()+sphi*v.
y();
2538 vphi = std::atan2(v.
y(),v.
x()) ;
2540 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2541 && ( (ePhi+halfAngTolerance) >= vphi) )
2546 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2553 if ( pDistS > -halfCarTolerance ) { sphi = 0; }
2567 sphi = pDistS/compS ;
2568 xi = p.
x()+sphi*v.
x() ;
2569 yi = p.
y()+sphi*v.
y() ;
2576 vphi = std::atan2(v.
y(),v.
x()) ;
2578 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2579 && ( (ePhi+halfAngTolerance) >= vphi) )
2584 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2611 if ( v.
x() || v.
y() )
2613 vphi = std::atan2(v.
y(),v.
x()) ;
2614 if ((fSPhi-halfAngTolerance < vphi) && (vphi < ePhi+halfAngTolerance))
2646 xi=p.
x()+snxt*v.
x();
2647 yi=p.
y()+snxt*v.
y();
2648 zi=p.
z()+snxt*v.
z();
2663 else { *validNorm=
false; }
2672 else { *validNorm=
false; }
2681 else if ( fSTheta >
halfpi )
2683 xi = p.
x() + snxt*v.
x();
2684 yi = p.
y() + snxt*v.
y();
2688 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
2690 -tanSTheta/std::sqrt(1+tanSTheta2));
2698 else { *validNorm=
false; }
2707 else if ( eTheta <
halfpi )
2709 xi=p.
x()+snxt*v.
x();
2710 yi=p.
y()+snxt*v.
y();
2714 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2716 -tanETheta/std::sqrt(1+tanETheta2) );
2724 else { *validNorm=
false; }
2730 std::ostringstream message;
2731 G4int oldprc = message.precision(16);
2732 message <<
"Undefined side for valid surface normal to solid."
2734 <<
"Position:" << G4endl << G4endl
2735 <<
"p.x() = " << p.
x()/
mm <<
" mm" << G4endl
2736 <<
"p.y() = " << p.
y()/
mm <<
" mm" << G4endl
2737 <<
"p.z() = " << p.
z()/
mm <<
" mm" << G4endl << G4endl
2738 <<
"Direction:" << G4endl << G4endl
2739 <<
"v.x() = " << v.
x() << G4endl
2740 <<
"v.y() = " << v.
y() << G4endl
2741 <<
"v.z() = " << v.
z() << G4endl << G4endl
2742 <<
"Proposed distance :" << G4endl << G4endl
2743 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl;
2744 message.precision(oldprc);
2750 if (snxt == kInfinity)
2754 std::ostringstream message;
2755 G4int oldprc = message.precision(16);
2756 message <<
"Logic error: snxt = kInfinity ???" << G4endl
2757 <<
"Position:" << G4endl << G4endl
2758 <<
"p.x() = " << p.
x()/
mm <<
" mm" << G4endl
2759 <<
"p.y() = " << p.
y()/
mm <<
" mm" << G4endl
2760 <<
"p.z() = " << p.
z()/
mm <<
" mm" << G4endl << G4endl
2761 <<
"Rp = "<< std::sqrt( p.
x()*p.
x()+p.
y()*p.
y()+p.
z()*p.
z() )/
mm
2762 <<
" mm" << G4endl << G4endl
2763 <<
"Direction:" << G4endl << G4endl
2764 <<
"v.x() = " << v.
x() << G4endl
2765 <<
"v.y() = " << v.
y() << G4endl
2766 <<
"v.z() = " << v.
z() << G4endl << G4endl
2767 <<
"Proposed distance :" << G4endl << G4endl
2768 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl;
2769 message.precision(oldprc);
2783 G4double safe=0.0,safeRMin,safeRMax,safePhi,safeTheta;
2786 rho2=p.
x()*p.
x()+p.
y()*p.
y();
2787 rds=std::sqrt(rho2+p.
z()*p.
z());
2788 rho=std::sqrt(rho2);
2800 G4cout.precision(old_prc) ;
2802 "GeomSolids1002",
JustWarning,
"Point p is outside !?" );
2813 if (safeRMin<safeRMax)
2830 if (!fFullPhiSphere && rho)
2832 if ((p.
y()*cosCPhi-p.
x()*sinCPhi)<=0)
2834 safePhi=-(p.
x()*sinSPhi-p.
y()*cosSPhi);
2838 safePhi=(p.
x()*sinEPhi-p.
y()*cosEPhi);
2840 if (safePhi<safe) { safe=safePhi; }
2848 pTheta=std::acos(p.
z()/rds);
2849 if (pTheta<0) { pTheta+=
pi; }
2850 dTheta1=pTheta-fSTheta;
2851 dTheta2=eTheta-pTheta;
2852 if (dTheta1<dTheta2) { safeTheta=rds*std::sin(dTheta1); }
2853 else { safeTheta=rds*std::sin(dTheta2); }
2854 if (safe>safeTheta) { safe=safeTheta; }
2857 if (safe<0) { safe=0; }
2874 G4int& noPolygonVertices )
const
2878 G4double meshAnglePhi,meshRMax,crossAnglePhi,
2879 coscrossAnglePhi,sincrossAnglePhi,sAnglePhi;
2880 G4double meshTheta,crossTheta,startTheta;
2881 G4double rMaxX,rMaxY,rMinX,rMinY,rMinZ,rMaxZ;
2882 G4int crossSectionPhi,noPhiCrossSections,crossSectionTheta,noThetaSections;
2896 meshAnglePhi=fDPhi/(noPhiCrossSections-1);
2903 sAnglePhi = -meshAnglePhi*0.5;
2922 meshTheta=fDTheta/(noThetaSections-1);
2927 if (fFullThetaSphere)
2929 startTheta = -meshTheta*0.5;
2936 meshRMax = (meshAnglePhi >= meshTheta) ?
2937 fRmax/std::cos(meshAnglePhi*0.5) : fRmax/std::cos(meshTheta*0.5);
2941 if (vertices && cosCrossTheta && sinCrossTheta)
2943 vertices->reserve(noPhiCrossSections*(noThetaSections*2));
2944 for (crossSectionPhi=0;
2945 crossSectionPhi<noPhiCrossSections; crossSectionPhi++)
2947 crossAnglePhi=sAnglePhi+crossSectionPhi*meshAnglePhi;
2948 coscrossAnglePhi=std::cos(crossAnglePhi);
2949 sincrossAnglePhi=std::sin(crossAnglePhi);
2950 for (crossSectionTheta=0;
2951 crossSectionTheta<noThetaSections;crossSectionTheta++)
2955 crossTheta=startTheta+crossSectionTheta*meshTheta;
2956 cosCrossTheta[crossSectionTheta]=std::cos(crossTheta);
2957 sinCrossTheta[crossSectionTheta]=std::sin(crossTheta);
2959 rMinX=fRmin*sinCrossTheta[crossSectionTheta]*coscrossAnglePhi;
2960 rMinY=fRmin*sinCrossTheta[crossSectionTheta]*sincrossAnglePhi;
2961 rMinZ=fRmin*cosCrossTheta[crossSectionTheta];
2968 for (crossSectionTheta=noThetaSections-1;
2969 crossSectionTheta>=0; crossSectionTheta--)
2971 rMaxX=meshRMax*sinCrossTheta[crossSectionTheta]*coscrossAnglePhi;
2972 rMaxY=meshRMax*sinCrossTheta[crossSectionTheta]*sincrossAnglePhi;
2973 rMaxZ=meshRMax*cosCrossTheta[crossSectionTheta];
2980 noPolygonVertices = noThetaSections*2 ;
2987 "Error in allocation of vertices. Out of memory !");
2990 delete [] cosCrossTheta;
2991 delete [] sinCrossTheta;
3020 G4int oldprc = os.precision(16);
3021 os <<
"-----------------------------------------------------------\n"
3022 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
3023 <<
" ===================================================\n"
3024 <<
" Solid type: G4Sphere\n"
3025 <<
" Parameters: \n"
3026 <<
" inner radius: " << fRmin/
mm <<
" mm \n"
3027 <<
" outer radius: " << fRmax/
mm <<
" mm \n"
3028 <<
" starting phi of segment : " << fSPhi/
degree <<
" degrees \n"
3029 <<
" delta phi of segment : " << fDPhi/
degree <<
" degrees \n"
3030 <<
" starting theta of segment: " << fSTheta/
degree <<
" degrees \n"
3031 <<
" delta theta of segment : " << fDTheta/
degree <<
" degrees \n"
3032 <<
"-----------------------------------------------------------\n";
3033 os.precision(oldprc);
3044 G4double zRand, aOne, aTwo, aThr, aFou, aFiv, chose, phi, sinphi, cosphi;
3045 G4double height1, height2, slant1, slant2, costheta, sintheta, rRand;
3047 height1 = (fRmax-fRmin)*cosSTheta;
3048 height2 = (fRmax-fRmin)*cosETheta;
3049 slant1 = std::sqrt(
sqr((fRmax - fRmin)*sinSTheta) + height1*height1);
3050 slant2 = std::sqrt(
sqr((fRmax - fRmin)*sinETheta) + height2*height2);
3053 aOne = fRmax*fRmax*fDPhi*(cosSTheta-cosETheta);
3054 aTwo = fRmin*fRmin*fDPhi*(cosSTheta-cosETheta);
3055 aThr = fDPhi*((fRmax + fRmin)*sinSTheta)*slant1;
3056 aFou = fDPhi*((fRmax + fRmin)*sinETheta)*slant2;
3057 aFiv = 0.5*fDTheta*(fRmax*fRmax-fRmin*fRmin);
3059 phi = RandFlat::shoot(fSPhi, ePhi);
3060 cosphi = std::cos(phi);
3061 sinphi = std::sin(phi);
3062 costheta = RandFlat::shoot(cosETheta,cosSTheta);
3063 sintheta = std::sqrt(1.-
sqr(costheta));
3065 if(fFullPhiSphere) { aFiv = 0; }
3066 if(fSTheta == 0) { aThr=0; }
3067 if(eTheta ==
pi) { aFou = 0; }
3068 if(fSTheta ==
halfpi) { aThr =
pi*(fRmax*fRmax-fRmin*fRmin); }
3069 if(eTheta ==
halfpi) { aFou =
pi*(fRmax*fRmax-fRmin*fRmin); }
3071 chose = RandFlat::shoot(0.,aOne+aTwo+aThr+aFou+2.*aFiv);
3072 if( (chose>=0.) && (chose<aOne) )
3075 fRmax*sintheta*sinphi, fRmax*costheta);
3077 else if( (chose>=aOne) && (chose<aOne+aTwo) )
3080 fRmin*sintheta*sinphi, fRmin*costheta);
3082 else if( (chose>=aOne+aTwo) && (chose<aOne+aTwo+aThr) )
3086 zRand = RandFlat::shoot(fRmin*cosSTheta,fRmax*cosSTheta);
3088 tanSTheta*zRand*sinphi,zRand);
3095 else if( (chose>=aOne+aTwo+aThr) && (chose<aOne+aTwo+aThr+aFou) )
3099 zRand = RandFlat::shoot(fRmin*cosETheta, fRmax*cosETheta);
3101 tanETheta*zRand*sinphi,zRand);
3108 else if( (chose>=aOne+aTwo+aThr+aFou) && (chose<aOne+aTwo+aThr+aFou+aFiv) )
3111 rRand*sintheta*sinSPhi,rRand*costheta);
3116 rRand*sintheta*sinEPhi,rRand*costheta);
3132 fSurfaceArea = fDPhi*(rsq+Rsq)*(cosSTheta - cosETheta);
3139 G4double acos1=std::acos( std::pow(sinSTheta,2) * std::cos(fDPhi)
3140 + std::pow(cosSTheta,2));
3152 G4double acos2=std::acos( std::pow(sinETheta,2) * std::cos(fDPhi)
3153 + std::pow(cosETheta,2));
3173 return G4VisExtent(-fRmax, fRmax,-fRmax, fRmax,-fRmax, fRmax );