59 #if !defined(G4GEOM_USE_USPHERE)
74 using namespace CLHEP;
93 :
G4CSGSolid(pName), fEpsilon(2.e-11), fSPhi(0.0),
94 fFullPhiSphere(true), fFullThetaSphere(true)
104 if ( (pRmin >= pRmax) || (pRmax < 1.1*
kRadTolerance) || (pRmin < 0) )
106 std::ostringstream message;
107 message <<
"Invalid radii for Solid: " <<
GetName() <<
G4endl
108 <<
" pRmin = " << pRmin <<
", pRmax = " << pRmax;
109 G4Exception(
"G4Sphere::G4Sphere()",
"GeomSolids0002",
128 :
G4CSGSolid(a), fRminTolerance(0.), fRmaxTolerance(0.),
129 kAngTolerance(0.), kRadTolerance(0.), fEpsilon(0.),
130 fRmin(0.), fRmax(0.), fSPhi(0.), fDPhi(0.), fSTheta(0.),
131 fDTheta(0.), sinCPhi(0.), cosCPhi(0.), cosHDPhiOT(0.), cosHDPhiIT(0.),
132 sinSPhi(0.), cosSPhi(0.), sinEPhi(0.), cosEPhi(0.), hDPhi(0.), cPhi(0.),
133 ePhi(0.), sinSTheta(0.), cosSTheta(0.), sinETheta(0.), cosETheta(0.),
134 tanSTheta(0.), tanSTheta2(0.), tanETheta(0.), tanETheta2(0.), eTheta(0.),
135 fFullPhiSphere(false), fFullThetaSphere(false), fFullSphere(true),
136 halfCarTolerance(0.), halfAngTolerance(0.)
153 :
G4CSGSolid(rhs), fRminTolerance(rhs.fRminTolerance),
154 fRmaxTolerance(rhs.fRmaxTolerance), kAngTolerance(rhs.kAngTolerance),
155 kRadTolerance(rhs.kRadTolerance), fEpsilon(rhs.fEpsilon),
156 fRmin(rhs.fRmin), fRmax(rhs.fRmax), fSPhi(rhs.fSPhi), fDPhi(rhs.fDPhi),
157 fSTheta(rhs.fSTheta), fDTheta(rhs.fDTheta),
158 sinCPhi(rhs.sinCPhi), cosCPhi(rhs.cosCPhi),
159 cosHDPhiOT(rhs.cosHDPhiOT), cosHDPhiIT(rhs.cosHDPhiIT),
160 sinSPhi(rhs.sinSPhi), cosSPhi(rhs.cosSPhi),
161 sinEPhi(rhs.sinEPhi), cosEPhi(rhs.cosEPhi),
162 hDPhi(rhs.hDPhi), cPhi(rhs.cPhi), ePhi(rhs.ePhi),
163 sinSTheta(rhs.sinSTheta), cosSTheta(rhs.cosSTheta),
164 sinETheta(rhs.sinETheta), cosETheta(rhs.cosETheta),
165 tanSTheta(rhs.tanSTheta), tanSTheta2(rhs.tanSTheta2),
166 tanETheta(rhs.tanETheta), tanETheta2(rhs.tanETheta2), eTheta(rhs.eTheta),
167 fFullPhiSphere(rhs.fFullPhiSphere), fFullThetaSphere(rhs.fFullThetaSphere),
168 fFullSphere(rhs.fFullSphere),
169 halfCarTolerance(rhs.halfCarTolerance),
170 halfAngTolerance(rhs.halfAngTolerance)
183 if (
this == &rhs) {
return *
this; }
246 G4double diff1,diff2,delta,maxDiff,newMin,newMax;
325 if ((yoff1>=0) && (yoff2>=0))
337 delta=fRmax*fRmax-yoff1*yoff1;
338 diff1=(delta>0.) ? std::sqrt(delta) : 0.;
339 delta=fRmax*fRmax-yoff2*yoff2;
340 diff2=(delta>0.) ? std::sqrt(delta) : 0.;
341 maxDiff=(diff1>diff2) ? diff1:diff2;
342 newMin=xoffset-maxDiff;
343 newMax=xoffset+maxDiff;
344 pMin=(newMin<xMin) ? xMin : newMin;
345 pMax=(newMax>xMax) ? xMax : newMax;
351 if ((xoff1>=0) && (xoff2>=0))
363 delta=fRmax*fRmax-xoff1*xoff1;
364 diff1=(delta>0.) ? std::sqrt(delta) : 0.;
365 delta=fRmax*fRmax-xoff2*xoff2;
366 diff2=(delta>0.) ? std::sqrt(delta) : 0.;
367 maxDiff=(diff1>diff2) ? diff1:diff2;
368 newMin=yoffset-maxDiff;
369 newMax=yoffset+maxDiff;
370 pMin=(newMin<yMin) ? yMin : newMin;
371 pMax=(newMax>yMax) ? yMax : newMax;
388 G4int i,j,noEntries,noBetweenSections;
389 G4bool existsAfterClip=
false;
394 G4int noPolygonVertices ;
400 noEntries=vertices->size();
401 noBetweenSections=noEntries-noPolygonVertices;
404 for (i=0;i<noEntries;i+=noPolygonVertices)
406 for(j=0;j<(noPolygonVertices/2)-1;j++)
408 ThetaPolygon.push_back((*vertices)[i+j]) ;
409 ThetaPolygon.push_back((*vertices)[i+j+1]) ;
410 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-2-j]) ;
411 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-1-j]) ;
413 ThetaPolygon.clear() ;
416 for (i=0;i<noBetweenSections;i+=noPolygonVertices)
418 for(j=0;j<noPolygonVertices-1;j++)
420 ThetaPolygon.push_back((*vertices)[i+j]) ;
421 ThetaPolygon.push_back((*vertices)[i+j+1]) ;
422 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices+j+1]) ;
423 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices+j]) ;
425 ThetaPolygon.clear() ;
427 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices-1]) ;
428 ThetaPolygon.push_back((*vertices)[i]) ;
429 ThetaPolygon.push_back((*vertices)[i+noPolygonVertices]) ;
430 ThetaPolygon.push_back((*vertices)[i+2*noPolygonVertices-1]) ;
432 ThetaPolygon.clear() ;
437 existsAfterClip=
true;
458 existsAfterClip=
true;
464 return existsAfterClip;
476 G4double rho,rho2,rad2,tolRMin,tolRMax;
485 rho2 = p.x()*p.x() + p.y()*p.y() ;
486 rad2 = rho2 + p.z()*p.z() ;
491 tolRMax = Rmax_minus;
493 if ( (rad2 <= Rmax_minus*Rmax_minus) && (rad2 >= Rmin_plus*Rmin_plus) )
499 tolRMax =
fRmax + halfRmaxTolerance;
501 if ( (rad2 <= tolRMax*tolRMax) && (rad2 >= tolRMin*tolRMin) )
515 pPhi = std::atan2(p.y(),p.x()) ;
534 rho = std::sqrt(rho2);
535 pTheta = std::atan2(rho,p.z());
573 G4int noSurfaces = 0;
574 G4double rho, rho2, radius, pTheta, pPhi=0.;
581 rho2 = p.x()*p.x()+p.y()*p.y();
582 radius = std::sqrt(rho2+p.z()*p.z());
583 rho = std::sqrt(rho2);
586 if (
fRmin) distRMin = std::fabs(radius-
fRmin);
590 pPhi = std::atan2(p.y(),p.x());
599 distSPhi = std::fabs( pPhi-
fSPhi );
600 distEPhi = std::fabs( pPhi-
ePhi );
614 pTheta = std::atan2(rho,p.z());
615 distSTheta = std::fabs(pTheta-
fSTheta);
616 distETheta = std::fabs(pTheta-
eTheta);
640 if( radius ) { nR =
G4ThreeVector(p.x()/radius,p.y()/radius,p.z()/radius); }
671 else { sumnorm += nTs; }
677 else { sumnorm += nTe; }
678 if(sumnorm.z() == 0.) { sumnorm += nZ; }
681 if ( noSurfaces == 0 )
684 G4Exception(
"G4Sphere::SurfaceNormal(p)",
"GeomSolids1002",
689 else if ( noSurfaces == 1 ) { norm = sumnorm; }
690 else { norm = sumnorm.unit(); }
704 G4double rho,rho2,radius,pPhi,pTheta;
705 G4double distRMin,distRMax,distSPhi,distEPhi,
706 distSTheta,distETheta,distMin;
708 rho2=p.x()*p.x()+p.y()*p.y();
709 radius=std::sqrt(rho2+p.z()*p.z());
716 distRMax=std::fabs(radius-
fRmax);
719 distRMin=std::fabs(radius-
fRmin);
721 if (distRMin<distRMax)
743 pPhi = std::atan2(p.y(),p.x());
744 if (pPhi<0) { pPhi += twopi; }
750 distSPhi=std::fabs(pPhi-(
fSPhi+twopi))*rho;
754 distSPhi=std::fabs(pPhi-
fSPhi)*rho;
761 if (distSPhi<distEPhi)
763 if (distSPhi<distMin)
771 if (distEPhi<distMin)
785 pTheta=std::atan2(rho,p.z());
786 distSTheta=std::fabs(pTheta-
fSTheta)*radius;
791 if (distSTheta<distETheta)
793 if (distSTheta<distMin)
795 distMin = distSTheta ;
801 if (distETheta<distMin)
803 distMin = distETheta ;
812 norm=
G4ThreeVector(-p.x()/radius,-p.y()/radius,-p.z()/radius);
837 "Undefined side for valid surface normal to solid.");
877 G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
878 G4double tolSTheta=0., tolETheta=0. ;
884 ? (
fRmin-halfRminTolerance)*(
fRmin-halfRminTolerance) : 0;
886 (
fRmin+halfRminTolerance)*(
fRmin+halfRminTolerance);
888 (
fRmax+halfRmaxTolerance)*(
fRmax+halfRmaxTolerance);
890 (
fRmax-halfRmaxTolerance)*(
fRmax-halfRmaxTolerance);
894 G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
911 rho2 = p.x()*p.x() + p.y()*p.y() ;
912 rad2 = rho2 + p.z()*p.z() ;
913 pTheta = std::atan2(std::sqrt(rho2),p.z()) ;
915 pDotV2d = p.x()*v.x() + p.y()*v.y() ;
916 pDotV3d = pDotV2d + p.z()*v.z() ;
947 d2 = pDotV3d*pDotV3d - c ;
951 sd = -pDotV3d - std::sqrt(d2) ;
957 G4double fTerm = sd-std::fmod(sd,dRmax);
960 xi = p.x() + sd*v.x() ;
961 yi = p.y() + sd*v.y() ;
962 rhoi = std::sqrt(xi*xi + yi*yi) ;
972 zi = p.z() + sd*v.z() ;
977 iTheta = std::atan2(rhoi,zi) ;
978 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
993 zi = p.z() + sd*v.z() ;
998 iTheta = std::atan2(rhoi,zi) ;
999 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1021 d2 = pDotV3d*pDotV3d - c ;
1023 if ( (rad2 > tolIRMax2)
1077 d2 = pDotV3d*pDotV3d - c ;
1082 if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
1129 sd = -pDotV3d + std::sqrt(d2) ;
1130 if ( sd >= halfRminTolerance )
1132 xi = p.x() + sd*v.x() ;
1133 yi = p.y() + sd*v.y() ;
1134 rhoi = std::sqrt(xi*xi+yi*yi) ;
1144 zi = p.z() + sd*v.z() ;
1149 iTheta = std::atan2(rhoi,zi) ;
1150 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
1165 zi = p.z() + sd*v.z() ;
1170 iTheta = std::atan2(rhoi,zi) ;
1171 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1214 xi = p.x() + sd*v.x() ;
1215 yi = p.y() + sd*v.y() ;
1216 zi = p.z() + sd*v.z() ;
1217 rhoi2 = xi*xi + yi*yi ;
1218 radi2 = rhoi2 + zi*zi ;
1229 if ( (radi2 <= tolORMax2)
1230 && (radi2 >= tolORMin2)
1239 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1240 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1245 if ((yi*
cosCPhi-xi*sinCPhi) <= 0)
1276 xi = p.x() + sd*v.x() ;
1277 yi = p.y() + sd*v.y() ;
1278 zi = p.z() + sd*v.z() ;
1279 rhoi2 = xi*xi + yi*yi ;
1280 radi2 = rhoi2 + zi*zi ;
1291 if ( (radi2 <= tolORMax2)
1292 && (radi2 >= tolORMin2)
1301 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1302 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1307 if ((yi*
cosCPhi-xi*sinCPhi) >= 0)
1349 dist2STheta = rho2 - p.z()*p.z()*
tanSTheta2 ;
1363 if ( pTheta < tolSTheta )
1373 c = dist2STheta/t1 ;
1380 zi = p.z() + sd*v.z();
1382 if ( (sd < 0) || (zi*(
fSTheta - halfpi) > 0) )
1386 if ((sd >= 0) && (sd < snxt))
1388 xi = p.x() + sd*v.x();
1389 yi = p.y() + sd*v.y();
1390 zi = p.z() + sd*v.z();
1391 rhoi2 = xi*xi + yi*yi;
1392 radi2 = rhoi2 + zi*zi;
1393 if ( (radi2 <= tolORMax2)
1394 && (radi2 >= tolORMin2)
1395 && (zi*(
fSTheta - halfpi) <= 0) )
1424 c = dist2ETheta/t1 ;
1432 if ( (sd >= 0) && (sd < snxt) )
1434 xi = p.x() + sd*v.x() ;
1435 yi = p.y() + sd*v.y() ;
1436 zi = p.z() + sd*v.z() ;
1437 rhoi2 = xi*xi + yi*yi ;
1438 radi2 = rhoi2 + zi*zi ;
1440 if ( (radi2 <= tolORMax2)
1441 && (radi2 >= tolORMin2)
1442 && (zi*(
eTheta - halfpi) <= 0) )
1462 else if ( pTheta > tolETheta )
1473 c = dist2ETheta/t1 ;
1480 zi = p.z() + sd*v.z();
1482 if ( (sd < 0) || (zi*(
eTheta - halfpi) > 0) )
1486 if ( (sd >= 0) && (sd < snxt) )
1488 xi = p.x() + sd*v.x() ;
1489 yi = p.y() + sd*v.y() ;
1490 zi = p.z() + sd*v.z() ;
1491 rhoi2 = xi*xi + yi*yi ;
1492 radi2 = rhoi2 + zi*zi ;
1494 if ( (radi2 <= tolORMax2)
1495 && (radi2 >= tolORMin2)
1496 && (zi*(
eTheta - halfpi) <= 0) )
1525 c = dist2STheta/t1 ;
1533 if ( (sd >= 0) && (sd < snxt) )
1535 xi = p.x() + sd*v.x() ;
1536 yi = p.y() + sd*v.y() ;
1537 zi = p.z() + sd*v.z() ;
1538 rhoi2 = xi*xi + yi*yi ;
1539 radi2 = rhoi2 + zi*zi ;
1541 if ( (radi2 <= tolORMax2)
1542 && (radi2 >= tolORMin2)
1543 && (zi*(
fSTheta - halfpi) <= 0) )
1571 if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 &&
fSTheta<halfpi)
1572 || (t2<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>halfpi)
1573 || (v.z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 &&
fSTheta==halfpi) )
1595 c = dist2STheta/t1 ;
1604 xi = p.x() + sd*v.x() ;
1605 yi = p.y() + sd*v.y() ;
1606 zi = p.z() + sd*v.z() ;
1607 rhoi2 = xi*xi + yi*yi ;
1608 radi2 = rhoi2 + zi*zi ;
1610 if ( (radi2 <= tolORMax2)
1611 && (radi2 >= tolORMin2)
1612 && (zi*(fSTheta - halfpi) <= 0) )
1640 if ( ((t2<0) && (
eTheta < halfpi)
1641 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1642 || ((t2>=0) && (
eTheta > halfpi)
1643 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1644 || ((v.z()>0) && (
eTheta == halfpi)
1645 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2)) )
1667 c = dist2ETheta/t1 ;
1676 && (sd < snxt) && (
eTheta > halfpi) )
1678 xi = p.x() + sd*v.x() ;
1679 yi = p.y() + sd*v.y() ;
1680 zi = p.z() + sd*v.z() ;
1681 rhoi2 = xi*xi + yi*yi ;
1682 radi2 = rhoi2 + zi*zi ;
1684 if ( (radi2 <= tolORMax2)
1685 && (radi2 >= tolORMin2)
1686 && (zi*(
eTheta - halfpi) <= 0) )
1715 c = dist2STheta/t1 ;
1723 if ((sd >= 0) && (sd < snxt))
1725 xi = p.x() + sd*v.x() ;
1726 yi = p.y() + sd*v.y() ;
1727 zi = p.z() + sd*v.z() ;
1728 rhoi2 = xi*xi + yi*yi ;
1729 radi2 = rhoi2 + zi*zi ;
1731 if ( (radi2 <= tolORMax2)
1732 && (radi2 >= tolORMin2)
1733 && (zi*(
fSTheta - halfpi) <= 0) )
1756 c = dist2ETheta/t1 ;
1764 if ((sd >= 0) && (sd < snxt))
1766 xi = p.x() + sd*v.x() ;
1767 yi = p.y() + sd*v.y() ;
1768 zi = p.z() + sd*v.z() ;
1769 rhoi2 = xi*xi + yi*yi ;
1770 radi2 = rhoi2 + zi*zi ;
1772 if ( (radi2 <= tolORMax2)
1773 && (radi2 >= tolORMin2)
1774 && (zi*(
eTheta - halfpi) <= 0) )
1807 G4double safe=0.0,safeRMin,safeRMax,safePhi,safeTheta;
1811 rho2=p.x()*p.x()+p.y()*p.y();
1812 rds=std::sqrt(rho2+p.z()*p.z());
1813 rho=std::sqrt(rho2);
1822 if (safeRMin>safeRMax)
1844 if (cosPsi<std::cos(
hDPhi))
1856 if (safePhi>safe) { safe=safePhi; }
1864 pTheta=std::acos(p.z()/rds);
1865 if (pTheta<0) { pTheta+=
pi; }
1868 if (dTheta1>dTheta2)
1872 safeTheta=rds*std::sin(dTheta1);
1873 if (safe<=safeTheta)
1883 safeTheta=rds*std::sin(dTheta2);
1884 if (safe<=safeTheta)
1892 if (safe<0) { safe=0; }
1920 G4double pDistS,compS,pDistE,compE,sphi2,vphi;
1922 G4double rho2,rad2,pDotV2d,pDotV3d;
1929 G4double dist2STheta, dist2ETheta, distTheta;
1934 rho2 = p.x()*p.x()+p.y()*p.y();
1935 rad2 = rho2+p.z()*p.z();
1937 pDotV2d = p.x()*v.x()+p.y()*v.y();
1938 pDotV3d = pDotV2d+p.z()*v.z();
1956 if( (rad2 <= Rmax_plus*Rmax_plus) && (rad2 >= Rmin_minus*Rmin_minus) )
1971 d2 = pDotV3d*pDotV3d - c;
1974 && ((pDotV3d >=0) || (d2 < 0)) )
1986 snxt = -pDotV3d+std::sqrt(d2);
1998 d2 = pDotV3d*pDotV3d - c;
2005 if(calcNorm) { *validNorm =
false; }
2012 sd = -pDotV3d-std::sqrt(d2);
2057 if ( std::fabs( p.z() ) <= halfRmaxTolerance )
2066 stheta = -p.z()/v.z();
2076 distTheta = std::sqrt(rho2)-p.z()*
tanSTheta;
2082 if(std::fabs(distTheta) < halfRmaxTolerance)
2084 if( (
fSTheta < halfpi) && (p.z() > 0.) )
2086 if( calcNorm ) { *validNorm =
false; }
2089 else if( (
fSTheta > halfpi) && (p.z() <= 0) )
2096 rhoSecTheta = std::sqrt(rho2*(1+
tanSTheta2));
2107 stheta = -0.5*dist2STheta/t2;
2113 if( std::fabs(distTheta) < halfRmaxTolerance )
2115 if( (
fSTheta > halfpi) && (t2 >= 0.) )
2122 rhoSecTheta = std::sqrt(rho2*(1+
tanSTheta2));
2132 else if( (
fSTheta < halfpi) && (t2 < 0.) && (p.z() >=0.) )
2134 if( calcNorm ) { *validNorm =
false; }
2150 if ( ((std::fabs(
s) < halfRmaxTolerance) && (t2 < 0.))
2151 || (sd < 0.) || ( (sd > 0.) && (p.z() + sd*v.z() > 0.) ) )
2155 if( (sd > halfRmaxTolerance) && (p.z() + sd*v.z() <= 0.) )
2165 if ( ( (std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.) )
2166 || (sd < 0.) || ( (sd > 0.) && (p.z() + sd*v.z() < 0.) ) )
2170 if( (sd > halfRmaxTolerance) && (p.z() + sd*v.z() >= 0.) )
2186 if ( std::fabs( p.z() ) <= halfRmaxTolerance )
2210 distTheta = std::sqrt(rho2)-p.z()*
tanETheta;
2216 if(std::fabs(distTheta) < halfRmaxTolerance)
2218 if( (
eTheta > halfpi) && (p.z() < 0.) )
2220 if( calcNorm ) { *validNorm =
false; }
2223 else if ( (
eTheta < halfpi) && (p.z() >= 0) )
2230 rhoSecTheta = std::sqrt(rho2*(1+
tanETheta2));
2240 sd = -0.5*dist2ETheta/t2;
2251 if ( std::fabs(distTheta) < halfRmaxTolerance )
2253 if( (
eTheta < halfpi) && (t2 >= 0.) )
2260 rhoSecTheta = std::sqrt(rho2*(1+
tanETheta2));
2269 else if ( (
eTheta > halfpi)
2270 && (t2 < 0.) && (p.z() <=0.) )
2272 if( calcNorm ) { *validNorm =
false; }
2288 if( ((std::fabs(sd) < halfRmaxTolerance) && (t2 < 0.))
2293 if( sd > halfRmaxTolerance )
2306 if ( ((std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.))
2307 || (sd < 0.) || ( (sd > 0.) && (p.z() + sd*v.z() > 0.) ) )
2311 if( (sd > halfRmaxTolerance) && (p.z() + sd*v.z() <= 0.) )
2331 if ( p.x() || p.y() )
2344 if ( (pDistS <= 0) && (pDistE <= 0) )
2350 sphi = pDistS/compS ;
2351 xi = p.x()+sphi*v.x() ;
2352 yi = p.y()+sphi*v.y() ;
2358 vphi = std::atan2(v.y(),v.x());
2380 sphi2=pDistE/compE ;
2383 xi = p.x()+sphi2*v.x() ;
2384 yi = p.y()+sphi2*v.y() ;
2392 vphi = std::atan2(v.y(),v.x()) ;
2399 else { sphi = 0.0; }
2417 else if ((pDistS >= 0) && (pDistE >= 0))
2419 if ( pDistS <= pDistE )
2429 if ( (compS < 0) && (compE < 0) ) { sphi = 0; }
2437 if ( (compS >= 0) && (compE >= 0) ) { sphi =
kInfinity; }
2441 else if ( (pDistS > 0) && (pDistE < 0) )
2449 sphi = pDistE/compE ;
2450 xi = p.x() + sphi*v.x() ;
2451 yi = p.y() + sphi*v.y() ;
2458 vphi = std::atan2(v.y(),v.x());
2487 sphi = pDistE/compE ;
2488 xi = p.x() + sphi*v.x() ;
2489 yi = p.y() + sphi*v.y() ;
2496 vphi = std::atan2(v.y(),v.x());
2532 xi=p.x()+sphi*v.x();
2533 yi=p.y()+sphi*v.y();
2540 vphi = std::atan2(v.y(),v.x()) ;
2569 sphi = pDistS/compS ;
2570 xi = p.x()+sphi*v.x() ;
2571 yi = p.y()+sphi*v.y() ;
2578 vphi = std::atan2(v.y(),v.x()) ;
2613 if ( v.x() || v.y() )
2615 vphi = std::atan2(v.y(),v.x()) ;
2648 xi=p.x()+snxt*v.x();
2649 yi=p.y()+snxt*v.y();
2650 zi=p.z()+snxt*v.z();
2665 else { *validNorm=
false; }
2674 else { *validNorm=
false; }
2685 xi = p.x() + snxt*v.x();
2686 yi = p.y() + snxt*v.y();
2690 rhoSecTheta = std::sqrt(rho2*(1+
tanSTheta2));
2700 else { *validNorm=
false; }
2709 else if (
eTheta < halfpi )
2711 xi=p.x()+snxt*v.x();
2712 yi=p.y()+snxt*v.y();
2716 rhoSecTheta = std::sqrt(rho2*(1+
tanETheta2));
2726 else { *validNorm=
false; }
2732 std::ostringstream message;
2733 G4int oldprc = message.precision(16);
2734 message <<
"Undefined side for valid surface normal to solid."
2736 <<
"Position:" << G4endl << G4endl
2737 <<
"p.x() = " << p.x()/
mm <<
" mm" << G4endl
2738 <<
"p.y() = " << p.y()/
mm <<
" mm" << G4endl
2739 <<
"p.z() = " << p.z()/
mm <<
" mm" << G4endl << G4endl
2740 <<
"Direction:" << G4endl << G4endl
2741 <<
"v.x() = " << v.x() << G4endl
2742 <<
"v.y() = " << v.y() << G4endl
2743 <<
"v.z() = " << v.z() << G4endl << G4endl
2744 <<
"Proposed distance :" << G4endl << G4endl
2745 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl;
2746 message.precision(oldprc);
2756 std::ostringstream message;
2757 G4int oldprc = message.precision(16);
2758 message <<
"Logic error: snxt = kInfinity ???" << G4endl
2759 <<
"Position:" << G4endl << G4endl
2760 <<
"p.x() = " << p.x()/
mm <<
" mm" << G4endl
2761 <<
"p.y() = " << p.y()/
mm <<
" mm" << G4endl
2762 <<
"p.z() = " << p.z()/
mm <<
" mm" << G4endl << G4endl
2763 <<
"Rp = "<< std::sqrt( p.x()*p.x()+p.y()*p.y()+p.z()*p.z() )/
mm
2764 <<
" mm" << G4endl << G4endl
2765 <<
"Direction:" << G4endl << G4endl
2766 <<
"v.x() = " << v.x() << G4endl
2767 <<
"v.y() = " << v.y() << G4endl
2768 <<
"v.z() = " << v.z() << G4endl << G4endl
2769 <<
"Proposed distance :" << G4endl << G4endl
2770 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl;
2771 message.precision(oldprc);
2785 G4double safe=0.0,safeRMin,safeRMax,safePhi,safeTheta;
2788 rho2=p.x()*p.x()+p.y()*p.y();
2789 rds=std::sqrt(rho2+p.z()*p.z());
2790 rho=std::sqrt(rho2);
2802 G4cout.precision(old_prc) ;
2804 "GeomSolids1002",
JustWarning,
"Point p is outside !?" );
2815 if (safeRMin<safeRMax)
2842 if (safePhi<safe) { safe=safePhi; }
2850 pTheta=std::acos(p.z()/rds);
2851 if (pTheta<0) { pTheta+=
pi; }
2854 if (dTheta1<dTheta2) { safeTheta=rds*std::sin(dTheta1); }
2855 else { safeTheta=rds*std::sin(dTheta2); }
2856 if (safe>safeTheta) { safe=safeTheta; }
2859 if (safe<0) { safe=0; }
2876 G4int& noPolygonVertices )
const
2880 G4double meshAnglePhi,meshRMax,crossAnglePhi,
2881 coscrossAnglePhi,sincrossAnglePhi,sAnglePhi;
2882 G4double meshTheta,crossTheta,startTheta;
2883 G4double rMaxX,rMaxY,rMinX,rMinY,rMinZ,rMaxZ;
2884 G4int crossSectionPhi,noPhiCrossSections,crossSectionTheta,noThetaSections;
2898 meshAnglePhi=
fDPhi/(noPhiCrossSections-1);
2905 sAnglePhi = -meshAnglePhi*0.5;
2924 meshTheta=
fDTheta/(noThetaSections-1);
2931 startTheta = -meshTheta*0.5;
2938 meshRMax = (meshAnglePhi >= meshTheta) ?
2939 fRmax/std::cos(meshAnglePhi*0.5) :
fRmax/std::cos(meshTheta*0.5);
2943 if (vertices && cosCrossTheta && sinCrossTheta)
2945 vertices->reserve(noPhiCrossSections*(noThetaSections*2));
2946 for (crossSectionPhi=0;
2947 crossSectionPhi<noPhiCrossSections; crossSectionPhi++)
2949 crossAnglePhi=sAnglePhi+crossSectionPhi*meshAnglePhi;
2950 coscrossAnglePhi=std::cos(crossAnglePhi);
2951 sincrossAnglePhi=std::sin(crossAnglePhi);
2952 for (crossSectionTheta=0;
2953 crossSectionTheta<noThetaSections;crossSectionTheta++)
2957 crossTheta=startTheta+crossSectionTheta*meshTheta;
2958 cosCrossTheta[crossSectionTheta]=std::cos(crossTheta);
2959 sinCrossTheta[crossSectionTheta]=std::sin(crossTheta);
2961 rMinX=
fRmin*sinCrossTheta[crossSectionTheta]*coscrossAnglePhi;
2962 rMinY=
fRmin*sinCrossTheta[crossSectionTheta]*sincrossAnglePhi;
2963 rMinZ=
fRmin*cosCrossTheta[crossSectionTheta];
2970 for (crossSectionTheta=noThetaSections-1;
2971 crossSectionTheta>=0; crossSectionTheta--)
2973 rMaxX=meshRMax*sinCrossTheta[crossSectionTheta]*coscrossAnglePhi;
2974 rMaxY=meshRMax*sinCrossTheta[crossSectionTheta]*sincrossAnglePhi;
2975 rMaxZ=meshRMax*cosCrossTheta[crossSectionTheta];
2982 noPolygonVertices = noThetaSections*2 ;
2989 "Error in allocation of vertices. Out of memory !");
2992 delete [] cosCrossTheta;
2993 delete [] sinCrossTheta;
3022 G4int oldprc = os.precision(16);
3023 os <<
"-----------------------------------------------------------\n"
3024 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
3025 <<
" ===================================================\n"
3026 <<
" Solid type: G4Sphere\n"
3027 <<
" Parameters: \n"
3028 <<
" inner radius: " <<
fRmin/
mm <<
" mm \n"
3029 <<
" outer radius: " <<
fRmax/
mm <<
" mm \n"
3030 <<
" starting phi of segment : " <<
fSPhi/
degree <<
" degrees \n"
3031 <<
" delta phi of segment : " <<
fDPhi/
degree <<
" degrees \n"
3032 <<
" starting theta of segment: " <<
fSTheta/
degree <<
" degrees \n"
3033 <<
" delta theta of segment : " <<
fDTheta/
degree <<
" degrees \n"
3034 <<
"-----------------------------------------------------------\n";
3035 os.precision(oldprc);
3046 G4double zRand, aOne, aTwo, aThr, aFou, aFiv, chose, phi, sinphi, cosphi;
3047 G4double height1, height2, slant1, slant2, costheta, sintheta, rRand;
3062 cosphi = std::cos(phi);
3063 sinphi = std::sin(phi);
3065 sintheta = std::sqrt(1.-
sqr(costheta));
3074 if( (chose>=0.) && (chose<aOne) )
3079 else if( (chose>=aOne) && (chose<aOne+aTwo) )
3084 else if( (chose>=aOne+aTwo) && (chose<aOne+aTwo+aThr) )
3097 else if( (chose>=aOne+aTwo+aThr) && (chose<aOne+aTwo+aThr+aFou) )
3110 else if( (chose>=aOne+aTwo+aThr+aFou) && (chose<aOne+aTwo+aThr+aFou+aFiv) )
3113 rRand*sintheta*
sinSPhi,rRand*costheta);
3118 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
G4Polyhedron * fpPolyhedron
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
virtual G4Polyhedron * GetPolyhedron() 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