64 using namespace CLHEP;
92 if ( pDz <= 0 || pDy1 <= 0 || pDx1 <= 0 ||
93 pDx2 <= 0 || pDy2 <= 0 || pDx3 <= 0 || pDx4 <= 0 )
95 std::ostringstream message;
96 message <<
"Invalid length parameters for Solid: " <<
GetName() <<
G4endl
98 << pDx1 <<
", " << pDx2 <<
", " << pDx3 <<
", " << pDx4 <<
G4endl
99 <<
" Y - " << pDy1 <<
", " << pDy2 <<
G4endl
138 && pt[0].
z() == pt[1].
z() && pt[0].
z() == pt[2].
z()
139 && pt[0].
z() == pt[3].
z()
141 && pt[4].
z() == pt[5].
z() && pt[4].
z() == pt[6].
z()
142 && pt[4].
z() == pt[7].
z()
144 && pt[0].y() == pt[1].y() && pt[2].y() == pt[3].y()
145 && pt[4].y() == pt[5].y() && pt[6].y() == pt[7].y()
146 && std::fabs( pt[0].y() + pt[2].y() + pt[4].y() + pt[6].y() ) <
kCarTolerance
147 && std::fabs( pt[0].x() + pt[1].x() + pt[4].x() + pt[5].x() +
148 pt[2].x() + pt[3].x() + pt[6].x() + pt[7].x() ) <
kCarTolerance ) )
150 std::ostringstream message;
151 message <<
"Invalid vertice coordinates for Solid: " <<
GetName();
164 "Face at ~-Y not planar.");
173 std::ostringstream message;
174 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
185 std::ostringstream message;
186 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
196 std::ostringstream message;
197 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
203 fDy1 = ((pt[2]).y()-(pt[1]).y())*0.5;
204 fDx1 = ((pt[1]).x()-(pt[0]).x())*0.5;
205 fDx2 = ((pt[3]).x()-(pt[2]).x())*0.5;
206 fTalpha1 = ((pt[2]).x()+(pt[3]).x()-(pt[1]).x()-(pt[0]).x())*0.25/
fDy1;
208 fDy2 = ((pt[6]).y()-(pt[5]).y())*0.5;
209 fDx3 = ((pt[5]).x()-(pt[4]).x())*0.5;
210 fDx4 = ((pt[7]).x()-(pt[6]).x())*0.5;
211 fTalpha2 = ((pt[6]).x()+(pt[7]).x()-(pt[5]).x()-(pt[4]).x())*0.25/
fDy2;
229 if ( pZ<=0 || pY<=0 || pX<=0 || pLTX<=0 || pLTX>pX )
231 std::ostringstream message;
232 message <<
"Invalid length parameters for Solid: " <<
GetName();
275 std::ostringstream message;
276 message <<
"Face at ~-Y not planar for Solid: " <<
GetName();
286 std::ostringstream message;
287 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
297 std::ostringstream message;
298 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
308 std::ostringstream message;
309 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
327 if ( pDz<=0 || pDy1<=0 || pDx1<=0 || pDx2<=0 || pDy2<=0 )
329 std::ostringstream message;
330 message <<
"Invalid length parameters for Solid: " <<
GetName();
373 std::ostringstream message;
374 message <<
"Face at ~-Y not planar for Solid: " <<
GetName();
384 std::ostringstream message;
385 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
395 std::ostringstream message;
396 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
406 std::ostringstream message;
407 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
426 if ( pDz<=0 || pDy<=0 || pDx<=0 )
428 std::ostringstream message;
429 message <<
"Invalid length parameters for Solid: " <<
GetName();
472 std::ostringstream message;
473 message <<
"Face at ~-Y not planar for Solid: " <<
GetName();
483 std::ostringstream message;
484 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
494 std::ostringstream message;
495 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
505 std::ostringstream message;
506 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
519 :
G4CSGSolid (pName), fDz(1.), fTthetaCphi(0.), fTthetaSphi(0.),
520 fDy1(1.), fDx1(1.), fDx2(1.), fTalpha1(0.),
521 fDy2(1.), fDx3(1.), fDx4(1.), fTalpha2(0.)
532 :
G4CSGSolid(a), fDz(1.), fTthetaCphi(0.), fTthetaSphi(0.),
533 fDy1(1.), fDx1(1.), fDx2(1.), fTalpha1(0.),
534 fDy2(1.), fDx3(1.), fDx4(1.), fTalpha2(0.)
553 fTthetaCphi(rhs.fTthetaCphi), fTthetaSphi(rhs.fTthetaSphi),
554 fDy1(rhs.fDy1), fDx1(rhs.fDx1), fDx2(rhs.fDx2), fTalpha1(rhs.fTalpha1),
555 fDy2(rhs.fDy2), fDx3(rhs.fDx3), fDx4(rhs.fDx4), fTalpha2(rhs.fTalpha2)
557 for (
size_t i=0; i<4; ++i)
574 if (
this == &rhs) {
return *
this; }
586 for (
size_t i=0; i<4; ++i)
614 if ( pDz<=0 || pDy1<=0 || pDx1<=0 || pDx2<=0 || pDy2<=0 || pDx3<=0 || pDx4<=0 )
616 std::ostringstream message;
617 message <<
"Invalid Length Parameters for Solid: " <<
GetName() <<
G4endl
619 << pDx1 <<
", " << pDx2 <<
", " << pDx3 <<
", " << pDx4 <<
G4endl
620 <<
" Y - " << pDy1 <<
", " << pDy2 <<
G4endl
622 G4Exception(
"G4Trap::SetAllParameters()",
"GeomSolids0002",
677 std::ostringstream message;
678 message <<
"Face at ~-Y not planar for Solid: " <<
GetName();
679 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
688 std::ostringstream message;
689 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
690 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
699 std::ostringstream message;
700 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
701 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
710 std::ostringstream message;
711 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
712 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
742 Vcross = v12.cross(v13);
764 a = +(p4.y() - p2.y())*(p3.z() - p1.z())
765 - (p3.y() - p1.y())*(p4.z() - p2.z());
767 b = -(p4.x() - p2.x())*(p3.z() - p1.z())
768 + (p3.x() - p1.x())*(p4.z() - p2.z());
770 c = +(p4.x() - p2.x())*(p3.y() - p1.y())
771 - (p3.x() - p1.x())*(p4.y() - p2.y());
773 sd = std::sqrt( a*a + b*b + c*c );
783 std::ostringstream message;
784 message <<
"Invalid parameters: norm.mod() <= 0, for Solid: "
786 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
791 plane.
d = -( plane.
a*p1.x() + plane.
b*p1.y() + plane.
c*p1.z() );
820 G4double xMin, xMax, yMin, yMax, zMin, zMax;
878 temp[0] = pt[0].y()+(pt[4].y()-pt[0].y())*(zMin-pt[0].
z())
879 /(pt[4].
z()-pt[0].z()) ;
880 temp[1] = pt[0].y()+(pt[4].y()-pt[0].y())*(zMax-pt[0].
z())
881 /(pt[4].
z()-pt[0].z()) ;
882 temp[2] = pt[2].y()+(pt[6].y()-pt[2].y())*(zMin-pt[2].
z())
883 /(pt[6].
z()-pt[2].z()) ;
884 temp[3] = pt[2].y()+(pt[6].y()-pt[2].y())*(zMax-pt[2].
z())
885 /(pt[6].
z()-pt[2].z()) ;
890 for( i = 0 ; i < 4 ; i++ )
892 if( temp[i] > yMax ) yMax = temp[i] ;
893 if( temp[i] < yMin ) yMin = temp[i] ;
914 temp[0] = pt[0].x()+(pt[4].x()-pt[0].x())
915 *(zMin-pt[0].
z())/(pt[4].
z()-pt[0].z()) ;
916 temp[1] = pt[0].x()+(pt[4].x()-pt[0].x())
917 *(zMax-pt[0].
z())/(pt[4].
z()-pt[0].z()) ;
918 temp[2] = pt[2].x()+(pt[6].x()-pt[2].x())
919 *(zMin-pt[2].
z())/(pt[6].
z()-pt[2].z()) ;
920 temp[3] = pt[2].x()+(pt[6].x()-pt[2].x())
921 *(zMax-pt[2].
z())/(pt[6].
z()-pt[2].z()) ;
922 temp[4] = pt[3].x()+(pt[7].x()-pt[3].x())
923 *(zMin-pt[3].
z())/(pt[7].
z()-pt[3].z()) ;
924 temp[5] = pt[3].x()+(pt[7].x()-pt[3].x())
925 *(zMax-pt[3].
z())/(pt[7].
z()-pt[3].z()) ;
926 temp[6] = pt[1].x()+(pt[5].x()-pt[1].x())
927 *(zMin-pt[1].
z())/(pt[5].
z()-pt[1].z()) ;
928 temp[7] = pt[1].x()+(pt[5].x()-pt[1].x())
929 *(zMax-pt[1].
z())/(pt[5].
z()-pt[1].z()) ;
934 for( i = 0 ; i < 8 ; i++ )
936 if( temp[i] > xMax) xMax = temp[i] ;
937 if( temp[i] < xMin) xMin = temp[i] ;
985 G4bool existsAfterClip = false ;
997 for(
G4int nv = 0 ; nv < 8 ; nv++ )
999 if( (*vertices)[nv].x() > xMax ) xMax = (*vertices)[nv].x();
1000 if( (*vertices)[nv].y() > yMax ) yMax = (*vertices)[nv].y();
1001 if( (*vertices)[nv].
z() > zMax ) zMax = (*vertices)[nv].z();
1003 if( (*vertices)[nv].x() < xMin ) xMin = (*vertices)[nv].x();
1004 if( (*vertices)[nv].y() < yMin ) yMin = (*vertices)[nv].y();
1005 if( (*vertices)[nv].
z() < zMin ) zMin = (*vertices)[nv].z();
1089 existsAfterClip=
true;
1097 flag = existsAfterClip ;
1116 for ( i = 0;i < 4;i++ )
1130 for ( i = 0; i < 4; i++ )
1150 G4int i, noSurfaces = 0;
1155 for (i = 0; i < 4; i++)
1164 distz = std::fabs( std::fabs( p.z() ) -
fDz );
1189 if (distmx <= delta)
1199 if (distmy <= delta)
1207 if ( p.z() >= 0.) sumnorm += nZ;
1210 if ( noSurfaces == 0 )
1213 G4Exception(
"G4Trap::SurfaceNormal(p)",
"GeomSolids1002",
1218 else if ( noSurfaces == 1 ) norm = sumnorm;
1219 else norm = sumnorm.unit();
1242 safez=std::fabs(std::fabs(p.z())-
fDz);
1286 smin = (-
fDz-p.z())/v.z();
1293 else if (v.z() < 0 )
1295 max = -
fDz - p.z() ;
1299 smin=(
fDz-p.z())/v.z();
1395 safe=std::fabs(p.z())-
fDz;
1400 if (Dist > safe) safe=Dist;
1677 std::ostringstream message;
1678 G4int oldprc = message.precision(16);
1679 message <<
"Undefined side for valid surface normal to solid."
1681 <<
"Position:" << G4endl << G4endl
1682 <<
"p.x() = " << p.x()/
mm <<
" mm" << G4endl
1683 <<
"p.y() = " << p.y()/
mm <<
" mm" << G4endl
1684 <<
"p.z() = " << p.z()/
mm <<
" mm" << G4endl << G4endl
1685 <<
"Direction:" << G4endl << G4endl
1686 <<
"v.x() = " << v.x() << G4endl
1687 <<
"v.y() = " << v.y() << G4endl
1688 <<
"v.z() = " << v.z() << G4endl << G4endl
1689 <<
"Proposed distance :" << G4endl << G4endl
1690 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl;
1691 message.precision(oldprc);
1692 G4Exception(
"G4Trap::DistanceToOut(p,v,..)",
"GeomSolids1002",
1720 G4cout.precision(oldprc) ;
1722 "GeomSolids1002",
JustWarning,
"Point p is outside !?" );
1726 safe=
fDz-std::fabs(p.z());
1734 if (Dist<safe) safe=Dist;
1757 vertices->reserve(8);
1789 "Error in allocation of vertices. Out of memory !");
1809 return new G4Trap(*
this);
1818 G4int oldprc = os.precision(16);
1819 os <<
"-----------------------------------------------------------\n"
1820 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
1821 <<
" ===================================================\n"
1822 <<
" Solid type: G4Trap\n"
1823 <<
" Parameters: \n"
1824 <<
" half length Z: " <<
fDz/
mm <<
" mm \n"
1825 <<
" half length Y of face -fDz: " <<
fDy1/
mm <<
" mm \n"
1826 <<
" half length X of side -fDy1, face -fDz: " <<
fDx1/
mm <<
" mm \n"
1827 <<
" half length X of side +fDy1, face -fDz: " <<
fDx2/
mm <<
" mm \n"
1828 <<
" half length Y of face +fDz: " <<
fDy2/
mm <<
" mm \n"
1829 <<
" half length X of side -fDy2, face +fDz: " <<
fDx3/
mm <<
" mm \n"
1830 <<
" half length X of side +fDy2, face +fDz: " <<
fDx4/
mm <<
" mm \n"
1833 <<
" std::tan(alpha), -fDz: " <<
fTalpha1/
degree <<
" degrees \n"
1834 <<
" std::tan(alpha), +fDz: " <<
fTalpha2/
degree <<
" degrees \n"
1835 <<
" trap side plane equations:\n"
1844 <<
"-----------------------------------------------------------\n";
1845 os.precision(oldprc);
1860 G4double lambda1, lambda2, chose, aOne, aTwo;
1869 w.z()*v.x() - w.x()*v.z(),
1870 w.x()*v.y() - w.y()*v.x());
1872 aOne = 0.5*Area.mag();
1875 t.z()*u.x() - t.x()*u.z(),
1876 t.x()*u.y() - t.y()*u.x());
1878 aTwo = 0.5*Area.mag();
1884 if( (chose>=0.) && (chose < aOne) )
1888 return (p2+lambda1*v+lambda2*w);
1896 return (p0+lambda1*t+lambda2*u);
1905 G4double aOne, aTwo, aThree, aFour, aFive, aSix, chose;
1936 if( (chose>=0.) && (chose<aOne) )
1938 else if( (chose>=aOne) && (chose<aOne+aTwo) )
1940 else if( (chose>=aOne+aTwo) && (chose<aOne+aTwo+aThree) )
1942 else if( (chose>=aOne+aTwo+aThree) && (chose<aOne+aTwo+aThree+aFour) )
1944 else if( (chose>=aOne+aTwo+aThree+aFour)
1945 && (chose<aOne+aTwo+aThree+aFour+aFive) )
ThreeVector shoot(const G4int Ap, const G4int Af)
G4ThreeVector GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, G4ThreeVector p2, G4ThreeVector p3, G4double &area) const
G4GeometryType GetEntityType() const
static const G4double kInfinity
G4double GetMinYExtent() const
CLHEP::Hep3Vector G4ThreeVector
G4bool fRebuildPolyhedron
G4Trap(const G4String &pName, G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pAlp1, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlp2)
G4bool IsYLimited() const
G4Trap & operator=(const G4Trap &rhs)
G4bool IsXLimited() const
virtual void AddSolid(const G4Box &)=0
static double normal(HepRandomEngine *eptr)
G4double GetMaxXExtent() const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
G4double GetMinZExtent() const
G4GLOB_DLL std::ostream G4cout
void SetAllParameters(G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pAlp1, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlp2)
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
std::vector< G4ThreeVector > G4ThreeVectorList
G4ThreeVectorList * CreateRotatedVertices(const G4AffineTransform &pTransform) const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
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
G4double GetMinXExtent() const
std::ostream & StreamInfo(std::ostream &os) const
G4double GetMaxZExtent() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector &p) const
static const double degree
G4ThreeVector GetPointOnSurface() const
G4double GetMaxYExtent() const
const G4double kCoplanar_Tolerance
G4Polyhedron * CreatePolyhedron() const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4bool MakePlane(const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3, const G4ThreeVector &p4, TrapSidePlane &plane)
EInside Inside(const G4ThreeVector &p) const
G4CSGSolid & operator=(const G4CSGSolid &rhs)
G4bool IsZLimited() const
void DescribeYourselfTo(G4VGraphicsScene &scene) const