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)
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",
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; }
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 ;
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() ;
436 existsAfterClip=
true;
457 existsAfterClip=
true;
463 return existsAfterClip;
475 G4double rho,rho2,rad2,tolRMin,tolRMax;
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;
500 if ( (rad2 <= tolRMax*tolRMax) && (rad2 >= tolRMin*tolRMin) )
514 pPhi = std::atan2(p.y(),p.x()) ;
533 rho = std::sqrt(rho2);
534 pTheta = std::atan2(rho,p.z());
572 G4int noSurfaces = 0;
573 G4double rho, rho2, radius, pTheta, pPhi=0.;
580 rho2 = p.x()*p.x()+p.y()*p.y();
581 radius = std::sqrt(rho2+p.z()*p.z());
582 rho = std::sqrt(rho2);
585 if (
fRmin) distRMin = std::fabs(radius-
fRmin);
589 pPhi = std::atan2(p.y(),p.x());
598 distSPhi = std::fabs( pPhi-
fSPhi );
599 distEPhi = std::fabs( pPhi-
ePhi );
613 pTheta = std::atan2(rho,p.z());
614 distSTheta = std::fabs(pTheta-
fSTheta);
615 distETheta = std::fabs(pTheta-
eTheta);
639 if( radius ) { nR =
G4ThreeVector(p.x()/radius,p.y()/radius,p.z()/radius); }
670 else { sumnorm += nTs; }
676 else { sumnorm += nTe; }
677 if(sumnorm.z() == 0.) { sumnorm += nZ; }
680 if ( noSurfaces == 0 )
683 G4Exception(
"G4Sphere::SurfaceNormal(p)",
"GeomSolids1002",
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; }
749 distSPhi=std::fabs(pPhi-(
fSPhi+twopi))*rho;
753 distSPhi=std::fabs(pPhi-
fSPhi)*rho;
760 if (distSPhi<distEPhi)
762 if (distSPhi<distMin)
770 if (distEPhi<distMin)
784 pTheta=std::atan2(rho,p.z());
785 distSTheta=std::fabs(pTheta-
fSTheta)*radius;
790 if (distSTheta<distETheta)
792 if (distSTheta<distMin)
794 distMin = distSTheta ;
800 if (distETheta<distMin)
802 distMin = distETheta ;
811 norm=
G4ThreeVector(-p.x()/radius,-p.y()/radius,-p.z()/radius);
836 "Undefined side for valid surface normal to solid.");
876 G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
877 G4double tolSTheta=0., tolETheta=0. ;
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() ;
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) ;
971 zi = p.z() + sd*v.z() ;
976 iTheta = std::atan2(rhoi,zi) ;
977 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
992 zi = p.z() + sd*v.z() ;
997 iTheta = std::atan2(rhoi,zi) ;
998 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1020 d2 = pDotV3d*pDotV3d - c ;
1022 if ( (rad2 > tolIRMax2)
1076 d2 = pDotV3d*pDotV3d - c ;
1081 if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
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) ;
1143 zi = p.z() + sd*v.z() ;
1148 iTheta = std::atan2(rhoi,zi) ;
1149 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
1164 zi = p.z() + sd*v.z() ;
1169 iTheta = std::atan2(rhoi,zi) ;
1170 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
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)
1238 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1239 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1244 if ((yi*
cosCPhi-xi*sinCPhi) <= 0)
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)
1300 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1301 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1306 if ((yi*
cosCPhi-xi*sinCPhi) >= 0)
1348 dist2STheta = rho2 - p.z()*p.z()*
tanSTheta2 ;
1362 if ( pTheta < tolSTheta )
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) )
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) )
1461 else if ( pTheta > tolETheta )
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) )
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) )
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) )
1594 c = dist2STheta/t1 ;
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) )
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)) )
1666 c = dist2ETheta/t1 ;
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) )
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) )
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) )
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)
1843 if (cosPsi<std::cos(
hDPhi))
1855 if (safePhi>safe) { safe=safePhi; }
1863 pTheta=std::acos(p.z()/rds);
1864 if (pTheta<0) { pTheta+=
pi; }
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; }
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) )
1970 d2 = pDotV3d*pDotV3d - c;
1973 && ((pDotV3d >=0) || (d2 < 0)) )
1985 snxt = -pDotV3d+std::sqrt(d2);
1997 d2 = pDotV3d*pDotV3d - c;
2004 if(calcNorm) { *validNorm =
false; }
2011 sd = -pDotV3d-std::sqrt(d2);
2056 if ( std::fabs( p.z() ) <= halfRmaxTolerance )
2065 stheta = -p.z()/v.z();
2075 distTheta = std::sqrt(rho2)-p.z()*
tanSTheta;
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));
2106 stheta = -0.5*dist2STheta/t2;
2112 if( std::fabs(distTheta) < halfRmaxTolerance )
2114 if( (
fSTheta > halfpi) && (t2 >= 0.) )
2121 rhoSecTheta = std::sqrt(rho2*(1+
tanSTheta2));
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.) )
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.) )
2185 if ( std::fabs( p.z() ) <= halfRmaxTolerance )
2209 distTheta = std::sqrt(rho2)-p.z()*
tanETheta;
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;
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 )
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.) )
2330 if ( p.x() || p.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());
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()) ;
2398 else { sphi = 0.0; }
2416 else if ((pDistS >= 0) && (pDistE >= 0))
2418 if ( pDistS <= pDistE )
2428 if ( (compS < 0) && (compE < 0) ) { sphi = 0; }
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());
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());
2531 xi=p.x()+sphi*v.x();
2532 yi=p.y()+sphi*v.y();
2539 vphi = std::atan2(v.y(),v.x()) ;
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()) ;
2612 if ( v.x() || v.y() )
2614 vphi = std::atan2(v.y(),v.x()) ;
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; }
2684 xi = p.x() + snxt*v.x();
2685 yi = p.y() + snxt*v.y();
2689 rhoSecTheta = std::sqrt(rho2*(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));
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);
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)
2841 if (safePhi<safe) { safe=safePhi; }
2849 pTheta=std::acos(p.z()/rds);
2850 if (pTheta<0) { pTheta+=
pi; }
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);
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;
3061 cosphi = std::cos(phi);
3062 sinphi = std::sin(phi);
3064 sintheta = std::sqrt(1.-
sqr(costheta));
3073 if( (chose>=0.) && (chose<aOne) )
3078 else if( (chose>=aOne) && (chose<aOne+aTwo) )
3083 else if( (chose>=aOne+aTwo) && (chose<aOne+aTwo+aThr) )
3096 else if( (chose>=aOne+aTwo+aThr) && (chose<aOne+aTwo+aThr+aFou) )
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);
ThreeVector shoot(const G4int Ap, const G4int Af)
G4double halfCarTolerance
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
static const G4double kInfinity
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
void CheckThetaAngles(G4double sTheta, G4double dTheta)
G4double GetRadialTolerance() const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=G4bool(false), G4bool *validNorm=0, G4ThreeVector *n=0) const
G4ThreeVectorList * CreateRotatedVertices(const G4AffineTransform &pTransform, G4int &noPolygonVertices) const
EInside Inside(const G4ThreeVector &p) const
void CheckPhiAngles(G4double sPhi, G4double dPhi)
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)
G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector &p) const
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)
static const double degree
G4VisExtent GetExtent() const
G4double GetSurfaceArea()
G4double GetMaxYExtent() const
G4double GetMaxExtent(const EAxis pAxis) const
G4CSGSolid & operator=(const G4CSGSolid &rhs)
G4bool IsZLimited() const
G4double halfAngTolerance
G4double GetAngularTolerance() const
G4double GetMinExtent(const EAxis pAxis) const
const G4double kMeshAngleDefault
static G4GeometryTolerance * GetInstance()
const G4int kMaxMeshSections
void DescribeYourselfTo(G4VGraphicsScene &scene) const