76 if ( pDx > 0 && pDy > 0 && pDz > 0 )
81 fTalpha = std::tan(pAlpha);
82 fTthetaCphi = std::tan(pTheta)*std::cos(pPhi);
83 fTthetaSphi = std::tan(pTheta)*std::sin(pPhi);
87 std::ostringstream message;
88 message <<
"Invalid Length Parameters for Solid: " <<
GetName() <<
G4endl
89 <<
" pDx, pDy, pDz = "
90 << pDx <<
", " << pDy <<
", " << pDz;
91 G4Exception(
"G4Para::SetAllParameters()",
"GeomSolids0002",
107 if ((pDx<=0) || (pDy<=0) || (pDz<=0))
109 std::ostringstream message;
110 message <<
"Invalid Length Parameters for Solid: " <<
GetName() <<
G4endl
111 <<
" pDx, pDy, pDz = "
112 << pDx <<
", " << pDy <<
", " << pDz;
129 if (!( pt[0].z()<0 && pt[0].z()==pt[1].z() && pt[0].z()==pt[2].z() &&
130 pt[0].z()==pt[3].z() && pt[4].z()>0 && pt[4].z()==pt[5].z() &&
131 pt[4].z()==pt[6].z() && pt[4].z()==pt[7].z() &&
132 (pt[0].z()+pt[4].z())==0 &&
133 pt[0].y()==pt[1].y() && pt[2].y()==pt[3].y() &&
134 pt[4].y()==pt[5].y() && pt[6].y()==pt[7].y() &&
135 ( pt[0].y() + pt[2].y() + pt[4].y() + pt[6].y() ) == 0 &&
136 ( pt[0].x() + pt[1].x() + pt[4].x() + pt[5].x() ) == 0) )
138 std::ostringstream message;
139 message <<
"Invalid vertice coordinates for Solid: " <<
GetName();
143 fDx = ((pt[3]).x()-(pt[2]).x())*0.5;
144 fDy = ((pt[2]).y()-(pt[1]).y())*0.5;
146 fTalpha = ((pt[2]).x()+(pt[3]).x()-(pt[1]).x()-(pt[0]).x())*0.25/fDy ;
147 fTthetaCphi = ((pt[4]).x()+fDy*fTalpha+fDx)/fDz ;
148 fTthetaSphi = ((pt[4]).y()+fDy)/fDz ;
161 fTalpha(0.), fTthetaCphi(0.), fTthetaSphi(0.)
177 :
G4CSGSolid(rhs), fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz),
178 fTalpha(rhs.fTalpha), fTthetaCphi(rhs.fTthetaCphi),
179 fTthetaSphi(rhs.fTthetaSphi)
191 if (
this == &rhs) {
return *
this; }
199 fDx = rhs.fDx; fDy = rhs.fDy; fDz = rhs.fDz;
200 fTalpha = rhs.fTalpha; fTthetaCphi = rhs.fTthetaCphi;
201 fTthetaSphi = rhs.fTthetaSphi;
248 yoffset-fDz*fTthetaSphi-fDy,zoffset-fDz);
250 yoffset-fDz*fTthetaSphi-fDy,zoffset-fDz);
252 yoffset-fDz*fTthetaSphi+fDy,zoffset-fDz);
254 yoffset-fDz*fTthetaSphi+fDy,zoffset-fDz);
256 yoffset+fDz*fTthetaSphi-fDy,zoffset+fDz);
258 yoffset+fDz*fTthetaSphi-fDy,zoffset+fDz);
260 yoffset+fDz*fTthetaSphi+fDy,zoffset+fDz);
262 yoffset+fDz*fTthetaSphi+fDy,zoffset+fDz);
285 temp[0] = pt[0].
y()+(pt[4].
y()-pt[0].
y())
286 *(zMin-pt[0].z())/(pt[4].z()-pt[0].
z()) ;
287 temp[1] = pt[0].
y()+(pt[4].
y()-pt[0].
y())
288 *(zMax-pt[0].z())/(pt[4].z()-pt[0].
z()) ;
289 temp[2] = pt[2].
y()+(pt[6].
y()-pt[2].
y())
290 *(zMin-pt[2].z())/(pt[6].z()-pt[2].
z()) ;
291 temp[3] = pt[2].
y()+(pt[6].
y()-pt[2].
y())
292 *(zMax-pt[2].z())/(pt[6].z()-pt[2].
z()) ;
293 yMax = yoffset - std::fabs(fDz*fTthetaSphi) - fDy - fDy ;
297 if(temp[i] > yMax) yMax = temp[i] ;
298 if(temp[i] < yMin) yMin = temp[i] ;
321 temp[0] = pt[0].
x()+(pt[4].
x()-pt[0].
x())
322 *(zMin-pt[0].z())/(pt[4].z()-pt[0].
z()) ;
323 temp[1] = pt[0].
x()+(pt[4].
x()-pt[0].
x())
324 *(zMax-pt[0].z())/(pt[4].z()-pt[0].
z()) ;
325 temp[2] = pt[2].
x()+(pt[6].
x()-pt[2].
x())
326 *(zMin-pt[2].z())/(pt[6].z()-pt[2].
z()) ;
327 temp[3] = pt[2].
x()+(pt[6].
x()-pt[2].
x())
328 *(zMax-pt[2].z())/(pt[6].z()-pt[2].
z()) ;
329 temp[4] = pt[3].
x()+(pt[7].
x()-pt[3].
x())
330 *(zMin-pt[3].z())/(pt[7].z()-pt[3].
z()) ;
331 temp[5] = pt[3].
x()+(pt[7].
x()-pt[3].
x())
332 *(zMax-pt[3].z())/(pt[7].z()-pt[3].
z()) ;
333 temp[6] = pt[1].
x()+(pt[5].
x()-pt[1].
x())
334 *(zMin-pt[1].z())/(pt[5].z()-pt[1].
z()) ;
335 temp[7] = pt[1].
x()+(pt[5].
x()-pt[1].
x())
336 *(zMax-pt[1].z())/(pt[5].z()-pt[1].
z()) ;
338 xMax = xoffset - std::fabs(fDz*fTthetaCphi) - fDx - fDx -fDx - fDx;
342 if(temp[i] > xMax) xMax = temp[i] ;
343 if(temp[i] < xMin) xMin = temp[i] ;
392 G4bool existsAfterClip=
false;
405 if (pMin!=kInfinity||pMax!=-kInfinity)
407 existsAfterClip=
true;
428 existsAfterClip=
true;
434 flag = existsAfterClip ;
448 yt1 = p.
y() - fTthetaSphi*p.
z();
449 yt = std::fabs(yt1) ;
453 xt = std::fabs( p.
x() - fTthetaCphi*p.
z() - fTalpha*yt1 );
485 G4int noSurfaces = 0;
493 newpx = p.
x()-fTthetaCphi*p.
z();
494 newpy = p.
y()-fTthetaSphi*p.
z();
496 calpha = 1/std::sqrt(1+fTalpha*fTalpha);
497 if (fTalpha) {salpha = -calpha*fTalpha;}
501 xshift = newpx - newpy*fTalpha;
504 distx = std::fabs(std::fabs(xshift)-fDx);
505 disty = std::fabs(std::fabs(newpy)-fDy);
506 distz = std::fabs(std::fabs(p.
z())-fDz);
508 tntheta = fTthetaCphi*calpha + fTthetaSphi*salpha;
509 cosntheta = 1/std::sqrt(1+tntheta*tntheta);
510 ycomp = 1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
521 if ( xshift >= 0.) {sumnorm += nX;}
522 else {sumnorm -= nX;}
527 if ( newpy >= 0.) {sumnorm += nY;}
528 else {sumnorm -= nY;}
533 if ( p.
z() >= 0.) {sumnorm += nZ;}
534 else {sumnorm -= nZ;}
536 if ( noSurfaces == 0 )
539 G4Exception(
"G4Para::SurfaceNormal(p)",
"GeomSolids1002",
542 norm = ApproxSurfaceNormal(p);
544 else if ( noSurfaces == 1 ) {norm = sumnorm;}
545 else {norm = sumnorm.
unit();}
566 newpx=p.
x()-fTthetaCphi*p.
z();
567 newpy=p.
y()-fTthetaSphi*p.
z();
569 calpha=1/std::sqrt(1+fTalpha*fTalpha);
572 salpha=-calpha/fTalpha;
579 xshift=newpx*calpha+newpy*salpha;
581 distx=std::fabs(std::fabs(xshift)-fDx*calpha);
582 disty=std::fabs(std::fabs(newpy)-fDy);
583 distz=std::fabs(std::fabs(p.
z())-fDz);
587 if (distx<distz) {side=
kNX;}
592 if (disty<distz) {side=
kNY;}
599 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
602 cosntheta=-1/std::sqrt(1+tntheta*tntheta);
606 cosntheta=1/std::sqrt(1+tntheta*tntheta);
608 norm=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
613 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
617 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
668 smin=(-fDz-p.
z())/v.
z();
672 return snxt=kInfinity;
681 smin=(fDz-p.
z())/v.
z();
685 return snxt=kInfinity;
690 if (std::fabs(p.
z())<=fDz)
697 return snxt=kInfinity;
705 yt=p.
y()-fTthetaSphi*p.
z();
706 vy=v.
y()-fTthetaSphi*v.
z();
718 return snxt=kInfinity;
731 return snxt=kInfinity;
736 if (std::fabs(yt)<=fDy)
743 return snxt=kInfinity;
749 if (tmin>smin) smin=tmin;
750 if (tmax<smax) smax=tmax;
753 return snxt=kInfinity;
760 xt=p.
x()-fTthetaCphi*p.
z()-fTalpha*yt;
761 vx=v.
x()-fTthetaCphi*v.
z()-fTalpha*vy;
772 return snxt=kInfinity;
785 return snxt=kInfinity;
790 if (std::fabs(xt)<=fDx)
797 return snxt=kInfinity;
800 if (tmin>smin) smin=tmin;
801 if (tmax<smax) smax=tmax;
804 if (smax>0&&smin<smax)
830 G4double distz1,distz2,disty1,disty2,distx1,distx2;
846 trany=p.
y()-fTthetaSphi*p.
z();
850 cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi);
851 disty1=(trany-fDy)*cosy;
852 disty2=(-fDy-trany)*cosy;
854 if (disty1>safe) safe=disty1;
855 if (disty2>safe) safe=disty2;
857 tranx=p.
x()-fTthetaCphi*p.
z()-fTalpha*trany;
858 cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi);
859 distx1=(tranx-fDx)*cosx;
860 distx2=(-fDx-tranx)*cosx;
862 if (distx1>safe) safe=distx1;
863 if (distx2>safe) safe=distx2;
883 G4double ycomp,calpha,salpha,tntheta,cosntheta;
934 yt=p.
y()-fTthetaSphi*p.
z();
935 vy=v.
y()-fTthetaSphi*v.
z();
954 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
977 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
988 xt=p.
x()-fTthetaCphi*p.
z()-fTalpha*yt;
989 vx=v.
x()-fTthetaCphi*v.
z()-fTalpha*vy;
1007 calpha=1/std::sqrt(1+fTalpha*fTalpha);
1010 salpha=-calpha/fTalpha;
1016 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
1017 cosntheta=1/std::sqrt(1+tntheta*tntheta);
1018 *n=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
1040 calpha=1/std::sqrt(1+fTalpha*fTalpha);
1043 salpha=-calpha/fTalpha;
1049 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
1050 cosntheta=-1/std::sqrt(1+tntheta*tntheta);
1051 *n=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
1069 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
1073 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi);
1077 calpha=1/std::sqrt(1+fTalpha*fTalpha);
1080 salpha=-calpha/fTalpha;
1086 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
1087 cosntheta=-1/std::sqrt(1+tntheta*tntheta);
1088 *n=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
1091 calpha=1/std::sqrt(1+fTalpha*fTalpha);
1094 salpha=-calpha/fTalpha;
1100 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha;
1101 cosntheta=1/std::sqrt(1+tntheta*tntheta);
1102 *n=
G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta);
1108 "Undefined side for valid surface normal to solid.");
1123 G4double distz1,distz2,disty1,disty2,distx1,distx2;
1136 G4cout.precision(oldprc) ;
1137 G4Exception(
"G4Para::DistanceToOut(p)",
"GeomSolids1002",
1155 trany=p.
y()-fTthetaSphi*p.
z();
1159 cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi);
1160 disty1=(fDy-trany)*cosy;
1161 disty2=(fDy+trany)*cosy;
1163 if (disty1<safe) safe=disty1;
1164 if (disty2<safe) safe=disty2;
1166 tranx=p.
x()-fTthetaCphi*p.
z()-fTalpha*trany;
1167 cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi);
1168 distx1=(fDx-tranx)*cosx;
1169 distx2=(fDx+tranx)*cosx;
1171 if (distx1<safe) safe=distx1;
1172 if (distx2<safe) safe=distx2;
1194 vertices->reserve(8);
1196 -fDz*fTthetaSphi-fDy, -fDz);
1198 -fDz*fTthetaSphi-fDy, -fDz);
1200 -fDz*fTthetaSphi+fDy, -fDz);
1202 -fDz*fTthetaSphi+fDy, -fDz);
1204 +fDz*fTthetaSphi-fDy, +fDz);
1206 +fDz*fTthetaSphi-fDy, +fDz);
1208 +fDz*fTthetaSphi+fDy, +fDz);
1210 +fDz*fTthetaSphi+fDy, +fDz);
1226 "Error in allocation of vertices. Out of memory !");
1246 return new G4Para(*
this);
1255 G4int oldprc = os.precision(16);
1256 os <<
"-----------------------------------------------------------\n"
1257 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
1258 <<
" ===================================================\n"
1259 <<
" Solid type: G4Para\n"
1260 <<
" Parameters: \n"
1261 <<
" half length X: " << fDx/mm <<
" mm \n"
1262 <<
" half length Y: " << fDy/mm <<
" mm \n"
1263 <<
" half length Z: " << fDz/mm <<
" mm \n"
1264 <<
" std::tan(alpha) : " << fTalpha/degree <<
" degrees \n"
1265 <<
" std::tan(theta)*std::cos(phi): " << fTthetaCphi/degree
1267 <<
" std::tan(theta)*std::sin(phi): " << fTthetaSphi/degree
1269 <<
"-----------------------------------------------------------\n";
1270 os.precision(oldprc);
1285 G4double lambda1, lambda2, chose, aOne, aTwo;
1294 w.
z()*v.
x() - w.
x()*v.
z(),
1295 w.
x()*v.
y() - w.
y()*v.
x());
1297 aOne = 0.5*Area.
mag();
1300 t.
z()*u.
x() - t.
x()*u.
z(),
1301 t.
x()*u.
y() - t.
y()*u.
x());
1303 aTwo = 0.5*Area.
mag();
1309 if( (chose>=0.) && (chose < aOne) )
1313 return (p2+lambda1*v+lambda2*w);
1320 return (p0+lambda1*t+lambda2*u);
1334 G4double chose, aOne, aTwo, aThree, aFour, aFive, aSix;
1337 -fDz*fTthetaSphi-fDy, -fDz);
1339 -fDz*fTthetaSphi-fDy, -fDz);
1341 -fDz*fTthetaSphi+fDy, -fDz);
1343 -fDz*fTthetaSphi+fDy, -fDz);
1345 +fDz*fTthetaSphi-fDy, +fDz);
1347 +fDz*fTthetaSphi-fDy, +fDz);
1349 +fDz*fTthetaSphi+fDy, +fDz);
1351 +fDz*fTthetaSphi+fDy, +fDz);
1355 One = GetPointOnPlane(pt[0],pt[1],pt[3],pt[2], aOne);
1356 Two = GetPointOnPlane(pt[4],pt[5],pt[7],pt[6], aTwo);
1357 Three = GetPointOnPlane(pt[6],pt[7],pt[3],pt[2], aThree);
1358 Four = GetPointOnPlane(pt[4],pt[5],pt[1],pt[0], aFour);
1359 Five = GetPointOnPlane(pt[0],pt[2],pt[6],pt[4], aFive);
1360 Six = GetPointOnPlane(pt[1],pt[3],pt[7],pt[5], aSix);
1364 if( (chose>=0.) && (chose<aOne) )
1366 else if(chose>=aOne && chose<aOne+aTwo)
1368 else if(chose>=aOne+aTwo && chose<aOne+aTwo+aThree)
1370 else if(chose>=aOne+aTwo+aThree && chose<aOne+aTwo+aThree+aFour)
1372 else if(chose>=aOne+aTwo+aThree+aFour && chose<aOne+aTwo+aThree+aFour+aFive)
1388 G4double phi = std::atan2(fTthetaSphi, fTthetaCphi);
1389 G4double alpha = std::atan(fTalpha);
1390 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi
1391 +fTthetaSphi*fTthetaSphi));
CLHEP::Hep3Vector G4ThreeVector
std::vector< G4ThreeVector > G4ThreeVectorList
G4DLLIMPORT std::ostream G4cout
G4Polyhedron * fpPolyhedron
G4CSGSolid & operator=(const G4CSGSolid &rhs)
G4GeometryType GetEntityType() const
G4ThreeVectorList * CreateRotatedVertices(const G4AffineTransform &pTransform) const
G4NURBS * CreateNURBS() const
G4Polyhedron * CreatePolyhedron() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=G4bool(false), G4bool *validNorm=0, G4ThreeVector *n=0) const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
G4Para & operator=(const G4Para &rhs)
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
std::ostream & StreamInfo(std::ostream &os) const
G4Para(const G4String &pName, G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
void SetAllParameters(G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
void DescribeYourselfTo(G4VGraphicsScene &scene) const
EInside Inside(const G4ThreeVector &p) const
G4ThreeVector GetPointOnSurface() const
virtual void AddSolid(const G4Box &)=0
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
void ClipBetweenSections(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
void ClipCrossSection(G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
G4double GetMinExtent(const EAxis pAxis) const
G4bool IsYLimited() const
G4double GetMinZExtent() const
G4bool IsXLimited() const
G4double GetMaxExtent(const EAxis pAxis) const
G4double GetMaxYExtent() const
G4double GetMaxZExtent() const
G4double GetMinYExtent() const
G4double GetMinXExtent() const
G4bool IsZLimited() const
G4double GetMaxXExtent() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)