59 #if !defined(G4GEOM_USE_USPHERE)
75 using namespace CLHEP;
94 :
G4CSGSolid(pName), fEpsilon(2.e-11), fSPhi(0.0),
95 fFullPhiSphere(true), fFullThetaSphere(true)
101 halfAngTolerance = 0.5*kAngTolerance;
105 if ( (pRmin >= pRmax) || (pRmax < 1.1*kRadTolerance) || (pRmin < 0) )
107 std::ostringstream message;
108 message <<
"Invalid radii for Solid: " <<
GetName() <<
G4endl
109 <<
" pRmin = " << pRmin <<
", pRmax = " << pRmax;
110 G4Exception(
"G4Sphere::G4Sphere()",
"GeomSolids0002",
113 fRmin=pRmin; fRmax=pRmax;
114 fRminTolerance = (fRmin) ?
std::max( kRadTolerance, fEpsilon*fRmin ) : 0;
115 fRmaxTolerance =
std::max( kRadTolerance, fEpsilon*fRmax );
119 CheckPhiAngles(pSPhi, pDPhi);
120 CheckThetaAngles(pSTheta, pDTheta);
129 :
G4CSGSolid(a), fRminTolerance(0.), fRmaxTolerance(0.),
130 kAngTolerance(0.), kRadTolerance(0.), fEpsilon(0.),
131 fRmin(0.), fRmax(0.), fSPhi(0.), fDPhi(0.), fSTheta(0.),
132 fDTheta(0.), sinCPhi(0.), cosCPhi(0.), cosHDPhiOT(0.), cosHDPhiIT(0.),
133 sinSPhi(0.), cosSPhi(0.), sinEPhi(0.), cosEPhi(0.), hDPhi(0.), cPhi(0.),
134 ePhi(0.), sinSTheta(0.), cosSTheta(0.), sinETheta(0.), cosETheta(0.),
135 tanSTheta(0.), tanSTheta2(0.), tanETheta(0.), tanETheta2(0.), eTheta(0.),
136 fFullPhiSphere(false), fFullThetaSphere(false), fFullSphere(true),
137 halfCarTolerance(0.), halfAngTolerance(0.)
154 :
G4CSGSolid(rhs), fRminTolerance(rhs.fRminTolerance),
155 fRmaxTolerance(rhs.fRmaxTolerance), kAngTolerance(rhs.kAngTolerance),
156 kRadTolerance(rhs.kRadTolerance), fEpsilon(rhs.fEpsilon),
157 fRmin(rhs.fRmin), fRmax(rhs.fRmax), fSPhi(rhs.fSPhi), fDPhi(rhs.fDPhi),
158 fSTheta(rhs.fSTheta), fDTheta(rhs.fDTheta),
159 sinCPhi(rhs.sinCPhi), cosCPhi(rhs.cosCPhi),
160 cosHDPhiOT(rhs.cosHDPhiOT), cosHDPhiIT(rhs.cosHDPhiIT),
161 sinSPhi(rhs.sinSPhi), cosSPhi(rhs.cosSPhi),
162 sinEPhi(rhs.sinEPhi), cosEPhi(rhs.cosEPhi),
163 hDPhi(rhs.hDPhi), cPhi(rhs.cPhi), ePhi(rhs.ePhi),
164 sinSTheta(rhs.sinSTheta), cosSTheta(rhs.cosSTheta),
165 sinETheta(rhs.sinETheta), cosETheta(rhs.cosETheta),
166 tanSTheta(rhs.tanSTheta), tanSTheta2(rhs.tanSTheta2),
167 tanETheta(rhs.tanETheta), tanETheta2(rhs.tanETheta2), eTheta(rhs.eTheta),
168 fFullPhiSphere(rhs.fFullPhiSphere), fFullThetaSphere(rhs.fFullThetaSphere),
169 fFullSphere(rhs.fFullSphere),
170 halfCarTolerance(rhs.halfCarTolerance),
171 halfAngTolerance(rhs.halfAngTolerance)
183 if (
this == &rhs) {
return *
this; }
191 fRminTolerance = rhs.fRminTolerance; fRmaxTolerance = rhs.fRmaxTolerance;
192 kAngTolerance = rhs.kAngTolerance; kRadTolerance = rhs.kRadTolerance;
193 fEpsilon = rhs.fEpsilon; fRmin = rhs.fRmin; fRmax = rhs.fRmax;
194 fSPhi = rhs.fSPhi; fDPhi = rhs.fDPhi; fSTheta = rhs.fSTheta;
195 fDTheta = rhs.fDTheta; sinCPhi = rhs.sinCPhi; cosCPhi = rhs.cosCPhi;
196 cosHDPhiOT = rhs.cosHDPhiOT; cosHDPhiIT = rhs.cosHDPhiIT;
197 sinSPhi = rhs.sinSPhi; cosSPhi = rhs.cosSPhi;
198 sinEPhi = rhs.sinEPhi; cosEPhi = rhs.cosEPhi;
199 hDPhi = rhs.hDPhi; cPhi = rhs.cPhi; ePhi = rhs.ePhi;
200 sinSTheta = rhs.sinSTheta; cosSTheta = rhs.cosSTheta;
201 sinETheta = rhs.sinETheta; cosETheta = rhs.cosETheta;
202 tanSTheta = rhs.tanSTheta; tanSTheta2 = rhs.tanSTheta2;
203 tanETheta = rhs.tanETheta; tanETheta2 = rhs.tanETheta2;
204 eTheta = rhs.eTheta; fFullPhiSphere = rhs.fFullPhiSphere;
205 fFullThetaSphere = rhs.fFullThetaSphere; fFullSphere = rhs.fFullSphere;
206 halfCarTolerance = rhs.halfCarTolerance;
207 halfAngTolerance = rhs.halfAngTolerance;
245 G4double diff1,diff2,delta,maxDiff,newMin,newMax;
324 if ((yoff1>=0) && (yoff2>=0))
336 delta=fRmax*fRmax-yoff1*yoff1;
337 diff1=(delta>0.) ? std::sqrt(delta) : 0.;
338 delta=fRmax*fRmax-yoff2*yoff2;
339 diff2=(delta>0.) ? std::sqrt(delta) : 0.;
340 maxDiff=(diff1>diff2) ? diff1:diff2;
341 newMin=xoffset-maxDiff;
342 newMax=xoffset+maxDiff;
343 pMin=(newMin<xMin) ? xMin : newMin;
344 pMax=(newMax>xMax) ? xMax : newMax;
350 if ((xoff1>=0) && (xoff2>=0))
362 delta=fRmax*fRmax-xoff1*xoff1;
363 diff1=(delta>0.) ? std::sqrt(delta) : 0.;
364 delta=fRmax*fRmax-xoff2*xoff2;
365 diff2=(delta>0.) ? std::sqrt(delta) : 0.;
366 maxDiff=(diff1>diff2) ? diff1:diff2;
367 newMin=yoffset-maxDiff;
368 newMax=yoffset+maxDiff;
369 pMin=(newMin<yMin) ? yMin : newMin;
370 pMax=(newMax>yMax) ? yMax : newMax;
387 G4int i,j,noEntries,noBetweenSections;
388 G4bool existsAfterClip=
false;
393 G4int noPolygonVertices ;
394 vertices=CreateRotatedVertices(pTransform,noPolygonVertices);
399 noEntries=vertices->size();
400 noBetweenSections=noEntries-noPolygonVertices;
403 for (i=0;i<noEntries;i+=noPolygonVertices)
405 for(j=0;j<(noPolygonVertices/2)-1;j++)
407 ThetaPolygon.push_back((*vertices)[i+j]) ;
408 ThetaPolygon.push_back((*vertices)[i+j+1]) ;
409 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-2-j]) ;
410 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-1-j]) ;
412 ThetaPolygon.clear() ;
415 for (i=0;i<noBetweenSections;i+=noPolygonVertices)
417 for(j=0;j<noPolygonVertices-1;j++)
419 ThetaPolygon.push_back((*vertices)[i+j]) ;
420 ThetaPolygon.push_back((*vertices)[i+j+1]) ;
421 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices+j+1]) ;
422 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices+j]) ;
424 ThetaPolygon.clear() ;
426 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-1]) ;
427 ThetaPolygon.push_back((*vertices)[i]) ;
428 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices]) ;
429 ThetaPolygon.push_back((*vertices)[i+2*noPolygonVertices-1]) ;
431 ThetaPolygon.clear() ;
434 if ((pMin!=kInfinity) || (pMax!=-kInfinity))
436 existsAfterClip=
true;
457 existsAfterClip=
true;
463 return existsAfterClip;
475 G4double rho,rho2,rad2,tolRMin,tolRMax;
479 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
480 const G4double halfRminTolerance = fRminTolerance*0.5;
481 const G4double Rmax_minus = fRmax - halfRmaxTolerance;
482 const G4double Rmin_plus = (fRmin > 0) ? fRmin+halfRminTolerance : 0;
484 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
485 rad2 = rho2 + p.
z()*p.
z() ;
490 tolRMax = Rmax_minus;
492 if ( (rad2 <= Rmax_minus*Rmax_minus) && (rad2 >= Rmin_plus*Rmin_plus) )
498 tolRMax = fRmax + halfRmaxTolerance;
499 tolRMin =
std::max(fRmin-halfRminTolerance, 0.);
500 if ( (rad2 <= tolRMax*tolRMax) && (rad2 >= tolRMin*tolRMin) )
512 if ( !fFullPhiSphere && rho2 )
514 pPhi = std::atan2(p.
y(),p.
x()) ;
516 if ( pPhi < fSPhi - halfAngTolerance ) { pPhi +=
twopi; }
517 else if ( pPhi > ePhi + halfAngTolerance ) { pPhi -=
twopi; }
519 if ( (pPhi < fSPhi - halfAngTolerance)
520 || (pPhi > ePhi + halfAngTolerance) ) {
return in =
kOutside; }
524 if ( (pPhi < fSPhi + halfAngTolerance)
525 || (pPhi > ePhi - halfAngTolerance) ) { in =
kSurface; }
531 if ( (rho2 || p.
z()) && (!fFullThetaSphere) )
533 rho = std::sqrt(rho2);
534 pTheta = std::atan2(rho,p.
z());
538 if ( (pTheta < fSTheta + halfAngTolerance)
539 || (pTheta > eTheta - halfAngTolerance) )
541 if ( (pTheta >= fSTheta - halfAngTolerance)
542 && (pTheta <= eTheta + halfAngTolerance) )
554 if ( (pTheta < fSTheta - halfAngTolerance)
555 || (pTheta > eTheta + halfAngTolerance) )
572 G4int noSurfaces = 0;
573 G4double rho, rho2, radius, pTheta, pPhi=0.;
575 G4double distSPhi = kInfinity, distEPhi = kInfinity;
576 G4double distSTheta = kInfinity, distETheta = kInfinity;
580 rho2 = p.
x()*p.
x()+p.
y()*p.
y();
581 radius = std::sqrt(rho2+p.
z()*p.
z());
582 rho = std::sqrt(rho2);
584 G4double distRMax = std::fabs(radius-fRmax);
585 if (fRmin) distRMin = std::fabs(radius-fRmin);
587 if ( rho && !fFullSphere )
589 pPhi = std::atan2(p.
y(),p.
x());
591 if (pPhi < fSPhi-halfAngTolerance) { pPhi +=
twopi; }
592 else if (pPhi > ePhi+halfAngTolerance) { pPhi -=
twopi; }
594 if ( !fFullPhiSphere )
598 distSPhi = std::fabs( pPhi-fSPhi );
599 distEPhi = std::fabs( pPhi-ePhi );
609 if ( !fFullThetaSphere )
613 pTheta = std::atan2(rho,p.
z());
614 distSTheta = std::fabs(pTheta-fSTheta);
615 distETheta = std::fabs(pTheta-eTheta);
618 -cosSTheta*p.
y()/rho,
639 if( radius ) { nR =
G4ThreeVector(p.
x()/radius,p.
y()/radius,p.
z()/radius); }
641 if( distRMax <= halfCarTolerance )
646 if( fRmin && (distRMin <= halfCarTolerance) )
651 if( !fFullPhiSphere )
653 if (distSPhi <= halfAngTolerance)
658 if (distEPhi <= halfAngTolerance)
664 if ( !fFullThetaSphere )
666 if ((distSTheta <= halfAngTolerance) && (fSTheta > 0.))
669 if ((radius <= halfCarTolerance) && fFullPhiSphere) { sumnorm += nZ; }
670 else { sumnorm += nTs; }
672 if ((distETheta <= halfAngTolerance) && (eTheta <
pi))
675 if ((radius <= halfCarTolerance) && fFullPhiSphere) { sumnorm -= nZ; }
676 else { sumnorm += nTe; }
677 if(sumnorm.
z() == 0.) { sumnorm += nZ; }
680 if ( noSurfaces == 0 )
683 G4Exception(
"G4Sphere::SurfaceNormal(p)",
"GeomSolids1002",
686 norm = ApproxSurfaceNormal(p);
688 else if ( noSurfaces == 1 ) { norm = sumnorm; }
689 else { norm = sumnorm.
unit(); }
703 G4double rho,rho2,radius,pPhi,pTheta;
704 G4double distRMin,distRMax,distSPhi,distEPhi,
705 distSTheta,distETheta,distMin;
707 rho2=p.
x()*p.
x()+p.
y()*p.
y();
708 radius=std::sqrt(rho2+p.
z()*p.
z());
715 distRMax=std::fabs(radius-fRmax);
718 distRMin=std::fabs(radius-fRmin);
720 if (distRMin<distRMax)
742 pPhi = std::atan2(p.
y(),p.
x());
743 if (pPhi<0) { pPhi +=
twopi; }
745 if (!fFullPhiSphere && rho)
749 distSPhi=std::fabs(pPhi-(fSPhi+
twopi))*rho;
753 distSPhi=std::fabs(pPhi-fSPhi)*rho;
756 distEPhi=std::fabs(pPhi-fSPhi-fDPhi)*rho;
760 if (distSPhi<distEPhi)
762 if (distSPhi<distMin)
770 if (distEPhi<distMin)
782 if (!fFullThetaSphere && radius)
784 pTheta=std::atan2(rho,p.
z());
785 distSTheta=std::fabs(pTheta-fSTheta)*radius;
786 distETheta=std::fabs(pTheta-fSTheta-fDTheta)*radius;
790 if (distSTheta<distETheta)
792 if (distSTheta<distMin)
794 distMin = distSTheta ;
800 if (distETheta<distMin)
802 distMin = distETheta ;
824 -cosSTheta*std::sin(pPhi),
829 cosETheta*std::sin(pPhi),
836 "Undefined side for valid surface normal to solid.");
876 G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
877 G4double tolSTheta=0., tolETheta=0. ;
880 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
881 const G4double halfRminTolerance = fRminTolerance*0.5;
882 const G4double tolORMin2 = (fRmin>halfRminTolerance)
883 ? (fRmin-halfRminTolerance)*(fRmin-halfRminTolerance) : 0;
885 (fRmin+halfRminTolerance)*(fRmin+halfRminTolerance);
887 (fRmax+halfRmaxTolerance)*(fRmax+halfRmaxTolerance);
889 (fRmax-halfRmaxTolerance)*(fRmax-halfRmaxTolerance);
893 G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
910 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
911 rad2 = rho2 + p.
z()*p.
z() ;
912 pTheta = std::atan2(std::sqrt(rho2),p.
z()) ;
914 pDotV2d = p.
x()*v.
x() + p.
y()*v.
y() ;
915 pDotV3d = pDotV2d + p.
z()*v.
z() ;
919 if (!fFullThetaSphere)
921 tolSTheta = fSTheta - halfAngTolerance ;
922 tolETheta = eTheta + halfAngTolerance ;
939 c = rad2 - fRmax*fRmax ;
941 if (c > fRmaxTolerance*fRmax)
946 d2 = pDotV3d*pDotV3d -
c ;
950 sd = -pDotV3d - std::sqrt(d2) ;
956 G4double fTerm = sd-std::fmod(sd,dRmax);
959 xi = p.
x() + sd*v.
x() ;
960 yi = p.
y() + sd*v.
y() ;
961 rhoi = std::sqrt(xi*xi + yi*yi) ;
963 if (!fFullPhiSphere && rhoi)
965 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
967 if (cosPsi >= cosHDPhiOT)
969 if (!fFullThetaSphere)
971 zi = p.
z() + sd*v.
z() ;
976 iTheta = std::atan2(rhoi,zi) ;
977 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
990 if (!fFullThetaSphere)
992 zi = p.
z() + sd*v.
z() ;
997 iTheta = std::atan2(rhoi,zi) ;
998 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1012 return snxt=kInfinity;
1020 d2 = pDotV3d*pDotV3d -
c ;
1022 if ( (rad2 > tolIRMax2)
1023 && ( (d2 >= fRmaxTolerance*fRmax) && (pDotV3d < 0) ) )
1025 if (!fFullPhiSphere)
1030 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1032 if (cosPsi>=cosHDPhiIT)
1036 if ( !fFullThetaSphere )
1038 if ( (pTheta >= tolSTheta + kAngTolerance)
1039 && (pTheta <= tolETheta - kAngTolerance) )
1052 if ( !fFullThetaSphere )
1054 if ( (pTheta >= tolSTheta + kAngTolerance)
1055 && (pTheta <= tolETheta - kAngTolerance) )
1075 c = rad2 - fRmin*fRmin ;
1076 d2 = pDotV3d*pDotV3d -
c ;
1081 if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
1084 if ( !fFullPhiSphere )
1089 cosPsi = (p.
x()*cosCPhi+p.
y()*sinCPhi)/std::sqrt(rho2) ;
1090 if (cosPsi >= cosHDPhiIT)
1094 if ( !fFullThetaSphere )
1096 if ( (pTheta >= tolSTheta + kAngTolerance)
1097 && (pTheta <= tolETheta - kAngTolerance) )
1110 if ( !fFullThetaSphere )
1112 if ( (pTheta >= tolSTheta + kAngTolerance)
1113 && (pTheta <= tolETheta - kAngTolerance) )
1128 sd = -pDotV3d + std::sqrt(d2) ;
1129 if ( sd >= halfRminTolerance )
1131 xi = p.
x() + sd*v.
x() ;
1132 yi = p.
y() + sd*v.
y() ;
1133 rhoi = std::sqrt(xi*xi+yi*yi) ;
1135 if ( !fFullPhiSphere && rhoi )
1137 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
1139 if (cosPsi >= cosHDPhiOT)
1141 if ( !fFullThetaSphere )
1143 zi = p.
z() + sd*v.
z() ;
1148 iTheta = std::atan2(rhoi,zi) ;
1149 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
1162 if ( !fFullThetaSphere )
1164 zi = p.
z() + sd*v.
z() ;
1169 iTheta = std::atan2(rhoi,zi) ;
1170 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1194 if ( !fFullPhiSphere )
1199 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1203 Dist = p.
y()*cosSPhi - p.
x()*sinSPhi ;
1205 if (Dist < halfCarTolerance)
1213 xi = p.
x() + sd*v.
x() ;
1214 yi = p.
y() + sd*v.
y() ;
1215 zi = p.
z() + sd*v.
z() ;
1216 rhoi2 = xi*xi + yi*yi ;
1217 radi2 = rhoi2 + zi*zi ;
1228 if ( (radi2 <= tolORMax2)
1229 && (radi2 >= tolORMin2)
1230 && ((yi*cosCPhi-xi*sinCPhi) <= 0) )
1236 if ( !fFullThetaSphere )
1238 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1239 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1244 if ((yi*cosCPhi-xi*sinCPhi) <= 0)
1262 Comp = -( v.
x()*sinEPhi-v.
y()*cosEPhi ) ;
1266 Dist = -(p.
y()*cosEPhi-p.
x()*sinEPhi) ;
1267 if ( Dist < halfCarTolerance )
1275 xi = p.
x() + sd*v.
x() ;
1276 yi = p.
y() + sd*v.
y() ;
1277 zi = p.
z() + sd*v.
z() ;
1278 rhoi2 = xi*xi + yi*yi ;
1279 radi2 = rhoi2 + zi*zi ;
1290 if ( (radi2 <= tolORMax2)
1291 && (radi2 >= tolORMin2)
1292 && ((yi*cosCPhi-xi*sinCPhi) >= 0) )
1298 if ( !fFullThetaSphere )
1300 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1301 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1306 if ((yi*cosCPhi-xi*sinCPhi) >= 0)
1324 if ( !fFullThetaSphere )
1348 dist2STheta = rho2 - p.
z()*p.
z()*tanSTheta2 ;
1352 dist2STheta = kInfinity ;
1356 dist2ETheta=rho2-p.
z()*p.
z()*tanETheta2;
1360 dist2ETheta=kInfinity;
1362 if ( pTheta < tolSTheta )
1367 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1368 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1372 c = dist2STheta/
t1 ;
1379 zi = p.
z() + sd*v.
z();
1381 if ( (sd < 0) || (zi*(fSTheta -
halfpi) > 0) )
1385 if ((sd >= 0) && (sd < snxt))
1387 xi = p.
x() + sd*v.
x();
1388 yi = p.
y() + sd*v.
y();
1389 zi = p.
z() + sd*v.
z();
1390 rhoi2 = xi*xi + yi*yi;
1391 radi2 = rhoi2 + zi*zi;
1392 if ( (radi2 <= tolORMax2)
1393 && (radi2 >= tolORMin2)
1394 && (zi*(fSTheta -
halfpi) <= 0) )
1396 if ( !fFullPhiSphere && rhoi2 )
1398 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1399 if (cosPsi >= cosHDPhiOT)
1418 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1419 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1423 c = dist2ETheta/
t1 ;
1431 if ( (sd >= 0) && (sd < snxt) )
1433 xi = p.
x() + sd*v.
x() ;
1434 yi = p.
y() + sd*v.
y() ;
1435 zi = p.
z() + sd*v.
z() ;
1436 rhoi2 = xi*xi + yi*yi ;
1437 radi2 = rhoi2 + zi*zi ;
1439 if ( (radi2 <= tolORMax2)
1440 && (radi2 >= tolORMin2)
1441 && (zi*(eTheta -
halfpi) <= 0) )
1443 if (!fFullPhiSphere && rhoi2)
1445 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1446 if (cosPsi >= cosHDPhiOT)
1461 else if ( pTheta > tolETheta )
1467 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1468 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1472 c = dist2ETheta/
t1 ;
1479 zi = p.
z() + sd*v.
z();
1481 if ( (sd < 0) || (zi*(eTheta -
halfpi) > 0) )
1485 if ( (sd >= 0) && (sd < snxt) )
1487 xi = p.
x() + sd*v.
x() ;
1488 yi = p.
y() + sd*v.
y() ;
1489 zi = p.
z() + sd*v.
z() ;
1490 rhoi2 = xi*xi + yi*yi ;
1491 radi2 = rhoi2 + zi*zi ;
1493 if ( (radi2 <= tolORMax2)
1494 && (radi2 >= tolORMin2)
1495 && (zi*(eTheta -
halfpi) <= 0) )
1497 if (!fFullPhiSphere && rhoi2)
1499 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1500 if (cosPsi >= cosHDPhiOT)
1519 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1520 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1524 c = dist2STheta/
t1 ;
1532 if ( (sd >= 0) && (sd < snxt) )
1534 xi = p.
x() + sd*v.
x() ;
1535 yi = p.
y() + sd*v.
y() ;
1536 zi = p.
z() + sd*v.
z() ;
1537 rhoi2 = xi*xi + yi*yi ;
1538 radi2 = rhoi2 + zi*zi ;
1540 if ( (radi2 <= tolORMax2)
1541 && (radi2 >= tolORMin2)
1542 && (zi*(fSTheta -
halfpi) <= 0) )
1544 if (!fFullPhiSphere && rhoi2)
1546 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1547 if (cosPsi >= cosHDPhiOT)
1562 else if ( (pTheta < tolSTheta + kAngTolerance)
1563 && (fSTheta > halfAngTolerance) )
1569 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1570 if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta<
halfpi)
1571 || (t2<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>
halfpi)
1572 || (v.
z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta==
halfpi) )
1574 if (!fFullPhiSphere && rho2)
1576 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1577 if (cosPsi >= cosHDPhiIT)
1590 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1594 c = dist2STheta/
t1 ;
1601 if ( (sd >= halfCarTolerance) && (sd < snxt) && (fSTheta < halfpi) )
1603 xi = p.
x() + sd*v.
x() ;
1604 yi = p.
y() + sd*v.
y() ;
1605 zi = p.
z() + sd*v.
z() ;
1606 rhoi2 = xi*xi + yi*yi ;
1607 radi2 = rhoi2 + zi*zi ;
1609 if ( (radi2 <= tolORMax2)
1610 && (radi2 >= tolORMin2)
1611 && (zi*(fSTheta - halfpi) <= 0) )
1613 if ( !fFullPhiSphere && rhoi2 )
1615 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1616 if ( cosPsi >= cosHDPhiOT )
1630 else if ((pTheta > tolETheta-kAngTolerance) && (eTheta <
pi-kAngTolerance))
1637 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1639 if ( ((t2<0) && (eTheta <
halfpi)
1640 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1641 || ((t2>=0) && (eTheta >
halfpi)
1642 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1643 || ((v.
z()>0) && (eTheta ==
halfpi)
1644 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2)) )
1646 if (!fFullPhiSphere && rho2)
1648 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1649 if (cosPsi >= cosHDPhiIT)
1662 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1666 c = dist2ETheta/
t1 ;
1674 if ( (sd >= halfCarTolerance)
1675 && (sd < snxt) && (eTheta >
halfpi) )
1677 xi = p.
x() + sd*v.
x() ;
1678 yi = p.
y() + sd*v.
y() ;
1679 zi = p.
z() + sd*v.
z() ;
1680 rhoi2 = xi*xi + yi*yi ;
1681 radi2 = rhoi2 + zi*zi ;
1683 if ( (radi2 <= tolORMax2)
1684 && (radi2 >= tolORMin2)
1685 && (zi*(eTheta -
halfpi) <= 0) )
1687 if (!fFullPhiSphere && rhoi2)
1689 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1690 if (cosPsi >= cosHDPhiOT)
1709 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1710 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1714 c = dist2STheta/
t1 ;
1722 if ((sd >= 0) && (sd < snxt))
1724 xi = p.
x() + sd*v.
x() ;
1725 yi = p.
y() + sd*v.
y() ;
1726 zi = p.
z() + sd*v.
z() ;
1727 rhoi2 = xi*xi + yi*yi ;
1728 radi2 = rhoi2 + zi*zi ;
1730 if ( (radi2 <= tolORMax2)
1731 && (radi2 >= tolORMin2)
1732 && (zi*(fSTheta -
halfpi) <= 0) )
1734 if (!fFullPhiSphere && rhoi2)
1736 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1737 if (cosPsi >= cosHDPhiOT)
1750 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1751 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1755 c = dist2ETheta/
t1 ;
1763 if ((sd >= 0) && (sd < snxt))
1765 xi = p.
x() + sd*v.
x() ;
1766 yi = p.
y() + sd*v.
y() ;
1767 zi = p.
z() + sd*v.
z() ;
1768 rhoi2 = xi*xi + yi*yi ;
1769 radi2 = rhoi2 + zi*zi ;
1771 if ( (radi2 <= tolORMax2)
1772 && (radi2 >= tolORMin2)
1773 && (zi*(eTheta -
halfpi) <= 0) )
1775 if (!fFullPhiSphere && rhoi2)
1777 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1778 if ( cosPsi >= cosHDPhiOT )
1806 G4double safe=0.0,safeRMin,safeRMax,safePhi,safeTheta;
1810 rho2=p.
x()*p.
x()+p.
y()*p.
y();
1811 rds=std::sqrt(rho2+p.
z()*p.
z());
1812 rho=std::sqrt(rho2);
1821 if (safeRMin>safeRMax)
1838 if (!fFullPhiSphere && rho)
1842 cosPsi=(p.
x()*cosCPhi+p.
y()*sinCPhi)/rho;
1843 if (cosPsi<std::cos(hDPhi))
1847 if ((p.
y()*cosCPhi-p.
x()*sinCPhi)<=0)
1849 safePhi=std::fabs(p.
x()*sinSPhi-p.
y()*cosSPhi);
1853 safePhi=std::fabs(p.
x()*sinEPhi-p.
y()*cosEPhi);
1855 if (safePhi>safe) { safe=safePhi; }
1861 if ((rds!=0.0) && (!fFullThetaSphere))
1863 pTheta=std::acos(p.
z()/rds);
1864 if (pTheta<0) { pTheta+=
pi; }
1865 dTheta1=fSTheta-pTheta;
1866 dTheta2=pTheta-eTheta;
1867 if (dTheta1>dTheta2)
1871 safeTheta=rds*std::sin(dTheta1);
1872 if (safe<=safeTheta)
1882 safeTheta=rds*std::sin(dTheta2);
1883 if (safe<=safeTheta)
1891 if (safe<0) { safe=0; }
1907 G4double sphi= kInfinity,stheta= kInfinity;
1908 ESide side=kNull,sidephi=kNull,sidetheta=kNull;
1910 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
1911 const G4double halfRminTolerance = fRminTolerance*0.5;
1912 const G4double Rmax_plus = fRmax + halfRmaxTolerance;
1913 const G4double Rmin_minus = (fRmin) ? fRmin-halfRminTolerance : 0;
1919 G4double pDistS,compS,pDistE,compE,sphi2,vphi;
1921 G4double rho2,rad2,pDotV2d,pDotV3d;
1928 G4double dist2STheta, dist2ETheta, distTheta;
1933 rho2 = p.
x()*p.
x()+p.
y()*p.
y();
1934 rad2 = rho2+p.
z()*p.
z();
1936 pDotV2d = p.
x()*v.
x()+p.
y()*v.
y();
1937 pDotV3d = pDotV2d+p.
z()*v.
z();
1955 if( (rad2 <= Rmax_plus*Rmax_plus) && (rad2 >= Rmin_minus*Rmin_minus) )
1957 c = rad2 - fRmax*fRmax;
1959 if (c < fRmaxTolerance*fRmax)
1970 d2 = pDotV3d*pDotV3d -
c;
1972 if( (c >- fRmaxTolerance*fRmax)
1973 && ((pDotV3d >=0) || (d2 < 0)) )
1985 snxt = -pDotV3d+std::sqrt(d2);
1996 c = rad2 - fRmin*fRmin;
1997 d2 = pDotV3d*pDotV3d -
c;
1999 if (c >- fRminTolerance*fRmin)
2001 if ( (c < fRminTolerance*fRmin)
2002 && (d2 >= fRminTolerance*fRmin) && (pDotV3d < 0) )
2004 if(calcNorm) { *validNorm =
false; }
2011 sd = -pDotV3d-std::sqrt(d2);
2026 if ( !fFullThetaSphere )
2052 if( std::fabs(tanSTheta) > 5./kAngTolerance )
2056 if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
2065 stheta = -p.
z()/v.
z();
2066 sidetheta = kSTheta;
2071 t1 = 1-v.
z()*v.
z()*(1+tanSTheta2);
2072 t2 = pDotV2d-p.
z()*v.
z()*tanSTheta2;
2073 dist2STheta = rho2-p.
z()*p.
z()*tanSTheta2;
2075 distTheta = std::sqrt(rho2)-p.
z()*tanSTheta;
2077 if( std::fabs(t1) < halfAngTolerance )
2081 if(std::fabs(distTheta) < halfRmaxTolerance)
2083 if( (fSTheta <
halfpi) && (p.
z() > 0.) )
2085 if( calcNorm ) { *validNorm =
false; }
2088 else if( (fSTheta >
halfpi) && (p.
z() <= 0) )
2095 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
2099 std::sin(fSTheta) );
2106 stheta = -0.5*dist2STheta/
t2;
2107 sidetheta = kSTheta;
2112 if( std::fabs(distTheta) < halfRmaxTolerance )
2114 if( (fSTheta >
halfpi) && (t2 >= 0.) )
2121 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
2125 std::sin(fSTheta) );
2131 else if( (fSTheta <
halfpi) && (t2 < 0.) && (p.
z() >=0.) )
2133 if( calcNorm ) { *validNorm =
false; }
2149 if ( ((std::fabs(
s) < halfRmaxTolerance) && (t2 < 0.))
2150 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() > 0.) ) )
2154 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() <= 0.) )
2157 sidetheta = kSTheta;
2164 if ( ( (std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.) )
2165 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() < 0.) ) )
2169 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() >= 0.) )
2172 sidetheta = kSTheta;
2181 if( std::fabs(tanETheta) > 5./kAngTolerance )
2185 if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
2199 sidetheta = kETheta;
2205 t1 = 1-v.
z()*v.
z()*(1+tanETheta2);
2206 t2 = pDotV2d-p.
z()*v.
z()*tanETheta2;
2207 dist2ETheta = rho2-p.
z()*p.
z()*tanETheta2;
2209 distTheta = std::sqrt(rho2)-p.
z()*tanETheta;
2211 if( std::fabs(t1) < halfAngTolerance )
2215 if(std::fabs(distTheta) < halfRmaxTolerance)
2217 if( (eTheta >
halfpi) && (p.
z() < 0.) )
2219 if( calcNorm ) { *validNorm =
false; }
2222 else if ( (eTheta <
halfpi) && (p.
z() >= 0) )
2229 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2239 sd = -0.5*dist2ETheta/
t2;
2244 sidetheta = kETheta;
2250 if ( std::fabs(distTheta) < halfRmaxTolerance )
2252 if( (eTheta <
halfpi) && (t2 >= 0.) )
2259 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2268 else if ( (eTheta >
halfpi)
2269 && (t2 < 0.) && (p.
z() <=0.) )
2271 if( calcNorm ) { *validNorm =
false; }
2287 if( ((std::fabs(sd) < halfRmaxTolerance) && (t2 < 0.))
2292 if( sd > halfRmaxTolerance )
2297 sidetheta = kETheta;
2305 if ( ((std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.))
2306 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() > 0.) ) )
2310 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() <= 0.) )
2315 sidetheta = kETheta;
2328 if ( !fFullPhiSphere )
2330 if ( p.
x() || p.
y() )
2334 pDistS=p.
x()*sinSPhi-p.
y()*cosSPhi;
2335 pDistE=-p.
x()*sinEPhi+p.
y()*cosEPhi;
2339 compS = -sinSPhi*v.
x()+cosSPhi*v.
y() ;
2340 compE = sinEPhi*v.
x()-cosEPhi*v.
y() ;
2343 if ( (pDistS <= 0) && (pDistE <= 0) )
2349 sphi = pDistS/compS ;
2350 xi = p.
x()+sphi*v.
x() ;
2351 yi = p.
y()+sphi*v.
y() ;
2357 vphi = std::atan2(v.
y(),v.
x());
2359 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2360 && ( (ePhi+halfAngTolerance) >= vphi) )
2365 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2372 if ( pDistS > -halfCarTolerance) { sphi = 0; }
2375 else { sphi = kInfinity; }
2379 sphi2=pDistE/compE ;
2382 xi = p.
x()+sphi2*v.
x() ;
2383 yi = p.
y()+sphi2*v.
y() ;
2391 vphi = std::atan2(v.
y(),v.
x()) ;
2393 if( !((fSPhi-halfAngTolerance <= vphi)
2394 &&(fSPhi+fDPhi+halfAngTolerance >= vphi)) )
2397 if ( pDistE <= -halfCarTolerance ) { sphi = sphi2; }
2398 else { sphi = 0.0; }
2401 else if ((yi*cosCPhi-xi*sinCPhi)>=0)
2404 if ( pDistE <= -halfCarTolerance )
2416 else if ((pDistS >= 0) && (pDistE >= 0))
2418 if ( pDistS <= pDistE )
2428 if ( (compS < 0) && (compE < 0) ) { sphi = 0; }
2429 else { sphi = kInfinity; }
2436 if ( (compS >= 0) && (compE >= 0) ) { sphi = kInfinity; }
2440 else if ( (pDistS > 0) && (pDistE < 0) )
2448 sphi = pDistE/compE ;
2449 xi = p.
x() + sphi*v.
x() ;
2450 yi = p.
y() + sphi*v.
y() ;
2457 vphi = std::atan2(v.
y(),v.
x());
2459 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2460 && ( (ePhi+halfAngTolerance) >= vphi) )
2465 else if ( ( yi*cosCPhi - xi*sinCPhi ) <= 0 )
2472 if ( pDistE > -halfCarTolerance ) { sphi = 0.; }
2486 sphi = pDistE/compE ;
2487 xi = p.
x() + sphi*v.
x() ;
2488 yi = p.
y() + sphi*v.
y() ;
2495 vphi = std::atan2(v.
y(),v.
x());
2497 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2498 && ( (ePhi+halfAngTolerance) >= vphi) )
2503 else if ( ( yi*cosCPhi - xi*sinCPhi) <= 0 )
2512 else sphi=kInfinity;
2531 xi=p.
x()+sphi*v.
x();
2532 yi=p.
y()+sphi*v.
y();
2539 vphi = std::atan2(v.
y(),v.
x()) ;
2541 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2542 && ( (ePhi+halfAngTolerance) >= vphi) )
2547 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2554 if ( pDistS > -halfCarTolerance ) { sphi = 0; }
2568 sphi = pDistS/compS ;
2569 xi = p.
x()+sphi*v.
x() ;
2570 yi = p.
y()+sphi*v.
y() ;
2577 vphi = std::atan2(v.
y(),v.
x()) ;
2579 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2580 && ( (ePhi+halfAngTolerance) >= vphi) )
2585 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2612 if ( v.
x() || v.
y() )
2614 vphi = std::atan2(v.
y(),v.
x()) ;
2615 if ((fSPhi-halfAngTolerance < vphi) && (vphi < ePhi+halfAngTolerance))
2647 xi=p.
x()+snxt*v.
x();
2648 yi=p.
y()+snxt*v.
y();
2649 zi=p.
z()+snxt*v.
z();
2664 else { *validNorm=
false; }
2673 else { *validNorm=
false; }
2682 else if ( fSTheta >
halfpi )
2684 xi = p.
x() + snxt*v.
x();
2685 yi = p.
y() + snxt*v.
y();
2689 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
2691 -tanSTheta/std::sqrt(1+tanSTheta2));
2699 else { *validNorm=
false; }
2708 else if ( eTheta <
halfpi )
2710 xi=p.
x()+snxt*v.
x();
2711 yi=p.
y()+snxt*v.
y();
2715 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2717 -tanETheta/std::sqrt(1+tanETheta2) );
2725 else { *validNorm=
false; }
2731 std::ostringstream message;
2732 G4int oldprc = message.precision(16);
2733 message <<
"Undefined side for valid surface normal to solid."
2735 <<
"Position:" << G4endl << G4endl
2736 <<
"p.x() = " << p.
x()/
mm <<
" mm" << G4endl
2737 <<
"p.y() = " << p.
y()/
mm <<
" mm" << G4endl
2738 <<
"p.z() = " << p.
z()/
mm <<
" mm" << G4endl << G4endl
2739 <<
"Direction:" << G4endl << G4endl
2740 <<
"v.x() = " << v.
x() << G4endl
2741 <<
"v.y() = " << v.
y() << G4endl
2742 <<
"v.z() = " << v.
z() << G4endl << G4endl
2743 <<
"Proposed distance :" << G4endl << G4endl
2744 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl;
2745 message.precision(oldprc);
2751 if (snxt == kInfinity)
2755 std::ostringstream message;
2756 G4int oldprc = message.precision(16);
2757 message <<
"Logic error: snxt = kInfinity ???" << G4endl
2758 <<
"Position:" << G4endl << G4endl
2759 <<
"p.x() = " << p.
x()/
mm <<
" mm" << G4endl
2760 <<
"p.y() = " << p.
y()/
mm <<
" mm" << G4endl
2761 <<
"p.z() = " << p.
z()/
mm <<
" mm" << G4endl << G4endl
2762 <<
"Rp = "<< std::sqrt( p.
x()*p.
x()+p.
y()*p.
y()+p.
z()*p.
z() )/
mm
2763 <<
" mm" << G4endl << G4endl
2764 <<
"Direction:" << G4endl << G4endl
2765 <<
"v.x() = " << v.
x() << G4endl
2766 <<
"v.y() = " << v.
y() << G4endl
2767 <<
"v.z() = " << v.
z() << G4endl << G4endl
2768 <<
"Proposed distance :" << G4endl << G4endl
2769 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl;
2770 message.precision(oldprc);
2784 G4double safe=0.0,safeRMin,safeRMax,safePhi,safeTheta;
2787 rho2=p.
x()*p.
x()+p.
y()*p.
y();
2788 rds=std::sqrt(rho2+p.
z()*p.
z());
2789 rho=std::sqrt(rho2);
2801 G4cout.precision(old_prc) ;
2803 "GeomSolids1002",
JustWarning,
"Point p is outside !?" );
2814 if (safeRMin<safeRMax)
2831 if (!fFullPhiSphere && rho)
2833 if ((p.
y()*cosCPhi-p.
x()*sinCPhi)<=0)
2835 safePhi=-(p.
x()*sinSPhi-p.
y()*cosSPhi);
2839 safePhi=(p.
x()*sinEPhi-p.
y()*cosEPhi);
2841 if (safePhi<safe) { safe=safePhi; }
2849 pTheta=std::acos(p.
z()/rds);
2850 if (pTheta<0) { pTheta+=
pi; }
2851 dTheta1=pTheta-fSTheta;
2852 dTheta2=eTheta-pTheta;
2853 if (dTheta1<dTheta2) { safeTheta=rds*std::sin(dTheta1); }
2854 else { safeTheta=rds*std::sin(dTheta2); }
2855 if (safe>safeTheta) { safe=safeTheta; }
2858 if (safe<0) { safe=0; }
2875 G4int& noPolygonVertices )
const
2879 G4double meshAnglePhi,meshRMax,crossAnglePhi,
2880 coscrossAnglePhi,sincrossAnglePhi,sAnglePhi;
2881 G4double meshTheta,crossTheta,startTheta;
2882 G4double rMaxX,rMaxY,rMinX,rMinY,rMinZ,rMaxZ;
2883 G4int crossSectionPhi,noPhiCrossSections,crossSectionTheta,noThetaSections;
2897 meshAnglePhi=fDPhi/(noPhiCrossSections-1);
2904 sAnglePhi = -meshAnglePhi*0.5;
2923 meshTheta=fDTheta/(noThetaSections-1);
2928 if (fFullThetaSphere)
2930 startTheta = -meshTheta*0.5;
2937 meshRMax = (meshAnglePhi >= meshTheta) ?
2938 fRmax/std::cos(meshAnglePhi*0.5) : fRmax/std::cos(meshTheta*0.5);
2942 if (vertices && cosCrossTheta && sinCrossTheta)
2944 vertices->reserve(noPhiCrossSections*(noThetaSections*2));
2945 for (crossSectionPhi=0;
2946 crossSectionPhi<noPhiCrossSections; crossSectionPhi++)
2948 crossAnglePhi=sAnglePhi+crossSectionPhi*meshAnglePhi;
2949 coscrossAnglePhi=std::cos(crossAnglePhi);
2950 sincrossAnglePhi=std::sin(crossAnglePhi);
2951 for (crossSectionTheta=0;
2952 crossSectionTheta<noThetaSections;crossSectionTheta++)
2956 crossTheta=startTheta+crossSectionTheta*meshTheta;
2957 cosCrossTheta[crossSectionTheta]=std::cos(crossTheta);
2958 sinCrossTheta[crossSectionTheta]=std::sin(crossTheta);
2960 rMinX=fRmin*sinCrossTheta[crossSectionTheta]*coscrossAnglePhi;
2961 rMinY=fRmin*sinCrossTheta[crossSectionTheta]*sincrossAnglePhi;
2962 rMinZ=fRmin*cosCrossTheta[crossSectionTheta];
2969 for (crossSectionTheta=noThetaSections-1;
2970 crossSectionTheta>=0; crossSectionTheta--)
2972 rMaxX=meshRMax*sinCrossTheta[crossSectionTheta]*coscrossAnglePhi;
2973 rMaxY=meshRMax*sinCrossTheta[crossSectionTheta]*sincrossAnglePhi;
2974 rMaxZ=meshRMax*cosCrossTheta[crossSectionTheta];
2981 noPolygonVertices = noThetaSections*2 ;
2988 "Error in allocation of vertices. Out of memory !");
2991 delete [] cosCrossTheta;
2992 delete [] sinCrossTheta;
3021 G4int oldprc = os.precision(16);
3022 os <<
"-----------------------------------------------------------\n"
3023 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
3024 <<
" ===================================================\n"
3025 <<
" Solid type: G4Sphere\n"
3026 <<
" Parameters: \n"
3027 <<
" inner radius: " << fRmin/
mm <<
" mm \n"
3028 <<
" outer radius: " << fRmax/
mm <<
" mm \n"
3029 <<
" starting phi of segment : " << fSPhi/
degree <<
" degrees \n"
3030 <<
" delta phi of segment : " << fDPhi/
degree <<
" degrees \n"
3031 <<
" starting theta of segment: " << fSTheta/
degree <<
" degrees \n"
3032 <<
" delta theta of segment : " << fDTheta/
degree <<
" degrees \n"
3033 <<
"-----------------------------------------------------------\n";
3034 os.precision(oldprc);
3045 G4double zRand, aOne, aTwo, aThr, aFou, aFiv, chose, phi, sinphi, cosphi;
3046 G4double height1, height2, slant1, slant2, costheta, sintheta, rRand;
3048 height1 = (fRmax-fRmin)*cosSTheta;
3049 height2 = (fRmax-fRmin)*cosETheta;
3050 slant1 = std::sqrt(
sqr((fRmax - fRmin)*sinSTheta) + height1*height1);
3051 slant2 = std::sqrt(
sqr((fRmax - fRmin)*sinETheta) + height2*height2);
3054 aOne = fRmax*fRmax*fDPhi*(cosSTheta-cosETheta);
3055 aTwo = fRmin*fRmin*fDPhi*(cosSTheta-cosETheta);
3056 aThr = fDPhi*((fRmax + fRmin)*sinSTheta)*slant1;
3057 aFou = fDPhi*((fRmax + fRmin)*sinETheta)*slant2;
3058 aFiv = 0.5*fDTheta*(fRmax*fRmax-fRmin*fRmin);
3061 cosphi = std::cos(phi);
3062 sinphi = std::sin(phi);
3064 sintheta = std::sqrt(1.-
sqr(costheta));
3066 if(fFullPhiSphere) { aFiv = 0; }
3067 if(fSTheta == 0) { aThr=0; }
3068 if(eTheta ==
pi) { aFou = 0; }
3069 if(fSTheta ==
halfpi) { aThr =
pi*(fRmax*fRmax-fRmin*fRmin); }
3070 if(eTheta ==
halfpi) { aFou =
pi*(fRmax*fRmax-fRmin*fRmin); }
3073 if( (chose>=0.) && (chose<aOne) )
3076 fRmax*sintheta*sinphi, fRmax*costheta);
3078 else if( (chose>=aOne) && (chose<aOne+aTwo) )
3081 fRmin*sintheta*sinphi, fRmin*costheta);
3083 else if( (chose>=aOne+aTwo) && (chose<aOne+aTwo+aThr) )
3089 tanSTheta*zRand*sinphi,zRand);
3096 else if( (chose>=aOne+aTwo+aThr) && (chose<aOne+aTwo+aThr+aFou) )
3102 tanETheta*zRand*sinphi,zRand);
3109 else if( (chose>=aOne+aTwo+aThr+aFou) && (chose<aOne+aTwo+aThr+aFou+aFiv) )
3112 rRand*sintheta*sinSPhi,rRand*costheta);
3117 rRand*sintheta*sinEPhi,rRand*costheta);
3133 fSurfaceArea = fDPhi*(rsq+Rsq)*(cosSTheta - cosETheta);
3140 G4double acos1=std::acos( std::pow(sinSTheta,2) * std::cos(fDPhi)
3141 + std::pow(cosSTheta,2));
3153 G4double acos2=std::acos( std::pow(sinETheta,2) * std::cos(fDPhi)
3154 + std::pow(cosETheta,2));
3174 return G4VisExtent(-fRmax, fRmax,-fRmax, fRmax,-fRmax, fRmax );
ThreeVector shoot(const G4int Ap, const G4int Af)
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4double GetMinYExtent() const
CLHEP::Hep3Vector G4ThreeVector
G4bool IsYLimited() const
G4double GetRadiusInRing(G4double rmin, G4double rmax) const
G4Polyhedron * CreatePolyhedron() const
G4bool IsXLimited() const
const G4int kMinMeshSections
virtual void AddSolid(const G4Box &)=0
G4Sphere(const G4String &pName, G4double pRmin, G4double pRmax, G4double pSPhi, G4double pDPhi, G4double pSTheta, G4double pDTheta)
G4ThreeVector GetPointOnSurface() const
G4double GetMaxXExtent() const
G4double GetMinZExtent() const
G4GLOB_DLL std::ostream G4cout
void CalculateClippedPolygonExtent(G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
G4double GetRadialTolerance() const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=G4bool(false), G4bool *validNorm=0, G4ThreeVector *n=0) const
EInside Inside(const G4ThreeVector &p) const
std::vector< G4ThreeVector > G4ThreeVectorList
G4GeometryType GetEntityType() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4Sphere & operator=(const G4Sphere &rhs)
G4double GetMinXExtent() const
G4double GetMaxZExtent() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
std::ostream & StreamInfo(std::ostream &os) const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
G4VisExtent GetExtent() const
G4double GetSurfaceArea()
G4double GetMaxYExtent() const
G4double GetMaxExtent(const EAxis pAxis) const
G4CSGSolid & operator=(const G4CSGSolid &rhs)
G4bool IsZLimited() const
G4double GetAngularTolerance() const
G4double GetMinExtent(const EAxis pAxis) const
const G4double kMeshAngleDefault
static G4GeometryTolerance * GetInstance()
const G4int kMaxMeshSections
void DescribeYourselfTo(G4VGraphicsScene &scene) const