63 using namespace CLHEP;
91 if ( pDz <= 0 || pDy1 <= 0 || pDx1 <= 0 ||
92 pDx2 <= 0 || pDy2 <= 0 || pDx3 <= 0 || pDx4 <= 0 )
94 std::ostringstream message;
95 message <<
"Invalid length parameters for Solid: " <<
GetName() <<
G4endl
97 << pDx1 <<
", " << pDx2 <<
", " << pDx3 <<
", " << pDx4 <<
G4endl
98 <<
" Y - " << pDy1 <<
", " << pDy2 <<
G4endl
137 && pt[0].
z() == pt[1].
z() && pt[0].
z() == pt[2].
z()
138 && pt[0].
z() == pt[3].
z()
140 && pt[4].
z() == pt[5].
z() && pt[4].
z() == pt[6].
z()
141 && pt[4].
z() == pt[7].
z()
143 && pt[0].y() == pt[1].y() && pt[2].y() == pt[3].y()
144 && pt[4].y() == pt[5].y() && pt[6].y() == pt[7].y()
145 && std::fabs( pt[0].y() + pt[2].y() + pt[4].y() + pt[6].y() ) <
kCarTolerance
146 && std::fabs( pt[0].x() + pt[1].x() + pt[4].x() + pt[5].x() +
147 pt[2].x() + pt[3].x() + pt[6].x() + pt[7].x() ) <
kCarTolerance ) )
149 std::ostringstream message;
150 message <<
"Invalid vertice coordinates for Solid: " <<
GetName();
163 "Face at ~-Y not planar.");
172 std::ostringstream message;
173 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
184 std::ostringstream message;
185 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
195 std::ostringstream message;
196 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
202 fDy1 = ((pt[2]).y()-(pt[1]).y())*0.5;
203 fDx1 = ((pt[1]).x()-(pt[0]).x())*0.5;
204 fDx2 = ((pt[3]).x()-(pt[2]).x())*0.5;
205 fTalpha1 = ((pt[2]).x()+(pt[3]).x()-(pt[1]).x()-(pt[0]).x())*0.25/
fDy1;
207 fDy2 = ((pt[6]).y()-(pt[5]).y())*0.5;
208 fDx3 = ((pt[5]).x()-(pt[4]).x())*0.5;
209 fDx4 = ((pt[7]).x()-(pt[6]).x())*0.5;
210 fTalpha2 = ((pt[6]).x()+(pt[7]).x()-(pt[5]).x()-(pt[4]).x())*0.25/
fDy2;
228 if ( pZ<=0 || pY<=0 || pX<=0 || pLTX<=0 || pLTX>pX )
230 std::ostringstream message;
231 message <<
"Invalid length parameters for Solid: " <<
GetName();
274 std::ostringstream message;
275 message <<
"Face at ~-Y not planar for Solid: " <<
GetName();
285 std::ostringstream message;
286 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
296 std::ostringstream message;
297 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
307 std::ostringstream message;
308 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
326 if ( pDz<=0 || pDy1<=0 || pDx1<=0 || pDx2<=0 || pDy2<=0 )
328 std::ostringstream message;
329 message <<
"Invalid length parameters for Solid: " <<
GetName();
372 std::ostringstream message;
373 message <<
"Face at ~-Y not planar for Solid: " <<
GetName();
383 std::ostringstream message;
384 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
394 std::ostringstream message;
395 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
405 std::ostringstream message;
406 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
425 if ( pDz<=0 || pDy<=0 || pDx<=0 )
427 std::ostringstream message;
428 message <<
"Invalid length parameters for Solid: " <<
GetName();
471 std::ostringstream message;
472 message <<
"Face at ~-Y not planar for Solid: " <<
GetName();
482 std::ostringstream message;
483 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
493 std::ostringstream message;
494 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
504 std::ostringstream message;
505 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
518 :
G4CSGSolid (pName), fDz(1.), fTthetaCphi(0.), fTthetaSphi(0.),
519 fDy1(1.), fDx1(1.), fDx2(1.), fTalpha1(0.),
520 fDy2(1.), fDx3(1.), fDx4(1.), fTalpha2(0.)
531 :
G4CSGSolid(a), fDz(1.), fTthetaCphi(0.), fTthetaSphi(0.),
532 fDy1(1.), fDx1(1.), fDx2(1.), fTalpha1(0.),
533 fDy2(1.), fDx3(1.), fDx4(1.), fTalpha2(0.)
552 fTthetaCphi(rhs.fTthetaCphi), fTthetaSphi(rhs.fTthetaSphi),
553 fDy1(rhs.fDy1), fDx1(rhs.fDx1), fDx2(rhs.fDx2), fTalpha1(rhs.fTalpha1),
554 fDy2(rhs.fDy2), fDx3(rhs.fDx3), fDx4(rhs.fDx4), fTalpha2(rhs.fTalpha2)
556 for (
size_t i=0; i<4; ++i)
574 if (
this == &rhs) {
return *
this; }
586 for (
size_t i=0; i<4; ++i)
615 if ( pDz<=0 || pDy1<=0 || pDx1<=0 || pDx2<=0 || pDy2<=0 || pDx3<=0 || pDx4<=0 )
617 std::ostringstream message;
618 message <<
"Invalid Length Parameters for Solid: " <<
GetName() <<
G4endl
620 << pDx1 <<
", " << pDx2 <<
", " << pDx3 <<
", " << pDx4 <<
G4endl
621 <<
" Y - " << pDy1 <<
", " << pDy2 <<
G4endl
623 G4Exception(
"G4Trap::SetAllParameters()",
"GeomSolids0002",
678 std::ostringstream message;
679 message <<
"Face at ~-Y not planar for Solid: " <<
GetName();
680 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
689 std::ostringstream message;
690 message <<
"Face at ~+Y not planar for Solid: " <<
GetName();
691 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
700 std::ostringstream message;
701 message <<
"Face at ~-X not planar for Solid: " <<
GetName();
702 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
711 std::ostringstream message;
712 message <<
"Face at ~+X not planar for Solid: " <<
GetName();
713 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
743 Vcross = v12.cross(v13);
765 a = +(p4.y() - p2.y())*(p3.z() - p1.z())
766 - (p3.y() - p1.y())*(p4.z() - p2.z());
768 b = -(p4.x() - p2.x())*(p3.z() - p1.z())
769 + (p3.x() - p1.x())*(p4.z() - p2.z());
771 c = +(p4.x() - p2.x())*(p3.y() - p1.y())
772 - (p3.x() - p1.x())*(p4.y() - p2.y());
774 sd = std::sqrt( a*a + b*b + c*c );
784 std::ostringstream message;
785 message <<
"Invalid parameters: norm.mod() <= 0, for Solid: "
787 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
792 plane.
d = -( plane.
a*p1.x() + plane.
b*p1.y() + plane.
c*p1.z() );
821 G4double xMin, xMax, yMin, yMax, zMin, zMax;
879 temp[0] = pt[0].y()+(pt[4].y()-pt[0].y())*(zMin-pt[0].
z())
880 /(pt[4].
z()-pt[0].z()) ;
881 temp[1] = pt[0].y()+(pt[4].y()-pt[0].y())*(zMax-pt[0].
z())
882 /(pt[4].
z()-pt[0].z()) ;
883 temp[2] = pt[2].y()+(pt[6].y()-pt[2].y())*(zMin-pt[2].
z())
884 /(pt[6].
z()-pt[2].z()) ;
885 temp[3] = pt[2].y()+(pt[6].y()-pt[2].y())*(zMax-pt[2].
z())
886 /(pt[6].
z()-pt[2].z()) ;
891 for( i = 0 ; i < 4 ; i++ )
893 if( temp[i] > yMax ) yMax = temp[i] ;
894 if( temp[i] < yMin ) yMin = temp[i] ;
915 temp[0] = pt[0].x()+(pt[4].x()-pt[0].x())
916 *(zMin-pt[0].
z())/(pt[4].
z()-pt[0].z()) ;
917 temp[1] = pt[0].x()+(pt[4].x()-pt[0].x())
918 *(zMax-pt[0].
z())/(pt[4].
z()-pt[0].z()) ;
919 temp[2] = pt[2].x()+(pt[6].x()-pt[2].x())
920 *(zMin-pt[2].
z())/(pt[6].
z()-pt[2].z()) ;
921 temp[3] = pt[2].x()+(pt[6].x()-pt[2].x())
922 *(zMax-pt[2].
z())/(pt[6].
z()-pt[2].z()) ;
923 temp[4] = pt[3].x()+(pt[7].x()-pt[3].x())
924 *(zMin-pt[3].
z())/(pt[7].
z()-pt[3].z()) ;
925 temp[5] = pt[3].x()+(pt[7].x()-pt[3].x())
926 *(zMax-pt[3].
z())/(pt[7].
z()-pt[3].z()) ;
927 temp[6] = pt[1].x()+(pt[5].x()-pt[1].x())
928 *(zMin-pt[1].
z())/(pt[5].
z()-pt[1].z()) ;
929 temp[7] = pt[1].x()+(pt[5].x()-pt[1].x())
930 *(zMax-pt[1].
z())/(pt[5].
z()-pt[1].z()) ;
935 for( i = 0 ; i < 8 ; i++ )
937 if( temp[i] > xMax) xMax = temp[i] ;
938 if( temp[i] < xMin) xMin = temp[i] ;
986 G4bool existsAfterClip = false ;
998 for(
G4int nv = 0 ; nv < 8 ; nv++ )
1000 if( (*vertices)[nv].x() > xMax ) xMax = (*vertices)[nv].x();
1001 if( (*vertices)[nv].y() > yMax ) yMax = (*vertices)[nv].y();
1002 if( (*vertices)[nv].
z() > zMax ) zMax = (*vertices)[nv].z();
1004 if( (*vertices)[nv].x() < xMin ) xMin = (*vertices)[nv].x();
1005 if( (*vertices)[nv].y() < yMin ) yMin = (*vertices)[nv].y();
1006 if( (*vertices)[nv].
z() < zMin ) zMin = (*vertices)[nv].z();
1090 existsAfterClip=
true;
1098 flag = existsAfterClip ;
1117 for ( i = 0;i < 4;i++ )
1131 for ( i = 0; i < 4; i++ )
1151 G4int i, noSurfaces = 0;
1156 for (i = 0; i < 4; i++)
1165 distz = std::fabs( std::fabs( p.z() ) -
fDz );
1190 if (distmx <= delta)
1200 if (distmy <= delta)
1208 if ( p.z() >= 0.) sumnorm += nZ;
1211 if ( noSurfaces == 0 )
1214 G4Exception(
"G4Trap::SurfaceNormal(p)",
"GeomSolids1002",
1219 else if ( noSurfaces == 1 ) norm = sumnorm;
1220 else norm = sumnorm.unit();
1243 safez=std::fabs(std::fabs(p.z())-
fDz);
1287 smin = (-
fDz-p.z())/v.z();
1294 else if (v.z() < 0 )
1296 max = -
fDz - p.z() ;
1300 smin=(
fDz-p.z())/v.z();
1396 safe=std::fabs(p.z())-
fDz;
1401 if (Dist > safe) safe=Dist;
1678 std::ostringstream message;
1679 G4int oldprc = message.precision(16);
1680 message <<
"Undefined side for valid surface normal to solid."
1682 <<
"Position:" << G4endl << G4endl
1683 <<
"p.x() = " << p.x()/
mm <<
" mm" << G4endl
1684 <<
"p.y() = " << p.y()/
mm <<
" mm" << G4endl
1685 <<
"p.z() = " << p.z()/
mm <<
" mm" << G4endl << G4endl
1686 <<
"Direction:" << G4endl << G4endl
1687 <<
"v.x() = " << v.x() << G4endl
1688 <<
"v.y() = " << v.y() << G4endl
1689 <<
"v.z() = " << v.z() << G4endl << G4endl
1690 <<
"Proposed distance :" << G4endl << G4endl
1691 <<
"snxt = " << snxt/
mm <<
" mm" <<
G4endl;
1692 message.precision(oldprc);
1693 G4Exception(
"G4Trap::DistanceToOut(p,v,..)",
"GeomSolids1002",
1721 G4cout.precision(oldprc) ;
1723 "GeomSolids1002",
JustWarning,
"Point p is outside !?" );
1727 safe=
fDz-std::fabs(p.z());
1735 if (Dist<safe) safe=Dist;
1758 vertices->reserve(8);
1790 "Error in allocation of vertices. Out of memory !");
1810 return new G4Trap(*
this);
1819 G4int oldprc = os.precision(16);
1820 os <<
"-----------------------------------------------------------\n"
1821 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
1822 <<
" ===================================================\n"
1823 <<
" Solid type: G4Trap\n"
1824 <<
" Parameters: \n"
1825 <<
" half length Z: " <<
fDz/
mm <<
" mm \n"
1826 <<
" half length Y of face -fDz: " <<
fDy1/
mm <<
" mm \n"
1827 <<
" half length X of side -fDy1, face -fDz: " <<
fDx1/
mm <<
" mm \n"
1828 <<
" half length X of side +fDy1, face -fDz: " <<
fDx2/
mm <<
" mm \n"
1829 <<
" half length Y of face +fDz: " <<
fDy2/
mm <<
" mm \n"
1830 <<
" half length X of side -fDy2, face +fDz: " <<
fDx3/
mm <<
" mm \n"
1831 <<
" half length X of side +fDy2, face +fDz: " <<
fDx4/
mm <<
" mm \n"
1834 <<
" std::tan(alpha), -fDz: " <<
fTalpha1/
degree <<
" degrees \n"
1835 <<
" std::tan(alpha), +fDz: " <<
fTalpha2/
degree <<
" degrees \n"
1836 <<
" trap side plane equations:\n"
1845 <<
"-----------------------------------------------------------\n";
1846 os.precision(oldprc);
1861 G4double lambda1, lambda2, chose, aOne, aTwo;
1870 w.z()*v.x() - w.x()*v.z(),
1871 w.x()*v.y() - w.y()*v.x());
1873 aOne = 0.5*Area.mag();
1876 t.z()*u.x() - t.x()*u.z(),
1877 t.x()*u.y() - t.y()*u.x());
1879 aTwo = 0.5*Area.mag();
1885 if( (chose>=0.) && (chose < aOne) )
1889 return (p2+lambda1*v+lambda2*w);
1897 return (p0+lambda1*t+lambda2*u);
1906 G4double aOne, aTwo, aThree, aFour, aFive, aSix, chose;
1937 if( (chose>=0.) && (chose<aOne) )
1939 else if( (chose>=aOne) && (chose<aOne+aTwo) )
1941 else if( (chose>=aOne+aTwo) && (chose<aOne+aTwo+aThree) )
1943 else if( (chose>=aOne+aTwo+aThree) && (chose<aOne+aTwo+aThree+aFour) )
1945 else if( (chose>=aOne+aTwo+aThree+aFour)
1946 && (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
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
G4Polyhedron * fpPolyhedron
virtual G4Polyhedron * GetPolyhedron() const
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