37#if !defined(G4GEOM_USE_UTRAP)
94 && pt[0].z() == pt[1].z()
95 && pt[0].z() == pt[2].z()
96 && pt[0].z() == pt[3].z()
99 && pt[4].z() == pt[5].z()
100 && pt[4].z() == pt[6].z()
101 && pt[4].z() == pt[7].z()
105 && pt[0].y() == pt[1].y()
106 && pt[2].y() == pt[3].y()
107 && pt[4].y() == pt[5].y()
108 && pt[6].y() == pt[7].y()
110 && std::fabs(pt[0].y()+pt[2].y()+pt[4].y()+pt[6].y()) <
kCarTolerance
111 && std::fabs(pt[0].x()+pt[1].x()+pt[4].x()+pt[5].x() +
114 std::ostringstream message;
115 message <<
"Invalid vertice coordinates for Solid: " <<
GetName();
124 fDy1 = ((pt[2]).y()-(pt[1]).y())*0.5;
125 fDx1 = ((pt[1]).x()-(pt[0]).x())*0.5;
126 fDx2 = ((pt[3]).x()-(pt[2]).x())*0.5;
127 fTalpha1 = ((pt[2]).x()+(pt[3]).x()-(pt[1]).x()-(pt[0]).x())*0.25/
fDy1;
129 fDy2 = ((pt[6]).y()-(pt[5]).y())*0.5;
130 fDx3 = ((pt[5]).x()-(pt[4]).x())*0.5;
131 fDx4 = ((pt[7]).x()-(pt[6]).x())*0.5;
132 fTalpha2 = ((pt[6]).x()+(pt[7]).x()-(pt[5]).x()-(pt[4]).x())*0.25/
fDy2;
207 fDz(1.), fTthetaCphi(0.), fTthetaSphi(0.),
208 fDy1(1.), fDx1(1.), fDx2(1.), fTalpha1(0.),
209 fDy2(1.), fDx3(1.), fDx4(1.), fTalpha2(0.)
221 fDz(1.), fTthetaCphi(0.), fTthetaSphi(0.),
222 fDy1(1.), fDx1(1.), fDx2(1.), fTalpha1(0.),
223 fDy2(1.), fDx3(1.), fDx4(1.), fTalpha2(0.)
241 :
G4CSGSolid(rhs), halfCarTolerance(rhs.halfCarTolerance),
242 fDz(rhs.fDz), fTthetaCphi(rhs.fTthetaCphi), fTthetaSphi(rhs.fTthetaSphi),
243 fDy1(rhs.fDy1), fDx1(rhs.fDx1), fDx2(rhs.fDx2), fTalpha1(rhs.fTalpha1),
244 fDy2(rhs.fDy2), fDx3(rhs.fDx3), fDx4(rhs.fDx4), fTalpha2(rhs.fTalpha2)
259 if (
this == &rhs) {
return *
this; }
321 std::ostringstream message;
322 message <<
"Invalid Length Parameters for Solid: " <<
GetName()
326 G4Exception(
"G4Trap::CheckParameters()",
"GeomSolids0002",
363 constexpr G4int iface[4][4] = { {0,4,5,1}, {2,3,7,6}, {0,2,6,4}, {1,5,7,3} };
364 const static G4String side[4] = {
"~-Y",
"~+Y",
"~-X",
"~+X" };
366 for (
G4int i=0; i<4; ++i)
377 for (
G4int k=0; k<4; ++k)
380 if (std::abs(dist) > std::abs(dmax)) dmax = dist;
382 std::ostringstream message;
383 message <<
"Side face " << side[i] <<
" is not planar for solid: "
384 <<
GetName() <<
"\nDiscrepancy: " << dmax/
mm <<
" mm\n";
386 G4Exception(
"G4Trap::MakePlanes()",
"GeomSolids0002",
437 constexpr G4int iface[6][4] =
438 { {0,1,3,2}, {0,4,5,1}, {2,3,7,6}, {0,2,6,4}, {1,5,7,3}, {4,6,7,5} };
445 for (
G4int i=0; i<6; ++i)
450 pt[iface[i][3]]).
mag();
504 (dx4 + dx3 - dx2 - dx1)*(dy2 - dy1)/3)*dz*0.125;
519 { {0,1,3,2}, {0,4,5,1}, {2,3,7,6}, {0,2,6,4}, {1,5,7,3}, {4,6,7,5} };
522 for (
G4int i=0; i<6; ++i)
527 pt[iface[i][3]]).
mag();
556 for (
G4int i=0; i<8; ++i)
559 if (x < xmin) xmin = x;
560 if (x > xmax) xmax = x;
562 if (y < ymin) ymin = y;
563 if (y > ymax) ymax = y;
567 pMin.set(xmin,ymin,-dz);
568 pMax.set(xmax,ymax, dz);
574 std::ostringstream message;
575 message <<
"Bad bounding box (min >= max) for solid: "
577 <<
"\npMin = " <<
pMin
578 <<
"\npMax = " <<
pMax;
579 G4Exception(
"G4Trap::BoundingLimits()",
"GeomMgt0001",
606 return exist = (
pMin <
pMax) ?
true :
false;
625 std::vector<const G4ThreeVectorList *> polygons(2);
626 polygons[0] = &baseA;
627 polygons[1] = &baseB;
711 for (
G4int i=0; i<2; ++i)
719 for (
G4int i=2; i<4; ++i)
735 for (
G4int i=2; i<4; ++i)
754 nx = std::copysign(k, p.
x())*
fPlanes[3].
a;
765 nx = std::copysign(k, p.
x())*
fPlanes[3].
a;
773 G4double mag2 = nx*nx + ny*ny + nz*nz;
781 std::ostringstream message;
782 G4int oldprc = message.precision(16);
783 message <<
"Point p is not on surface (!?) of solid: "
785 message <<
"Position:\n";
786 message <<
" p.x() = " << p.
x()/
mm <<
" mm\n";
787 message <<
" p.y() = " << p.
y()/
mm <<
" mm\n";
788 message <<
" p.z() = " << p.
z()/
mm <<
" mm";
789 G4cout.precision(oldprc) ;
790 G4Exception(
"G4Trap::SurfaceNormal(p)",
"GeomSolids1002",
807 for (
G4int i=0; i<4; ++i)
812 if (d > dist) { dist = d; iside = i; }
851 if (tymin < tmp) tymin = tmp;
856 if (tymax > tmp) tymax = tmp;
872 if (txmin < tmp) txmin = tmp;
877 if (txmax > tmp) txmax = tmp;
912 return (dist > 0) ? dist : 0.;
923 return (dist > 0) ? dist : 0.;
932 return (dist > 0) ? dist : 0.;
941 return (dist > 0) ? dist : 0.;
964 n->set(0, 0, (p.
z() < 0) ? -1 : 1);
970 G4int iside = (vz < 0) ? -4 : -2;
991 if (tmax > tmp) { tmax = tmp; iside = i; }
1014 if (tmax > tmp) { tmax = tmp; iside = i; }
1024 n->set(0, 0, iside + 3);
1041 std::ostringstream message;
1042 G4int oldprc = message.precision(16);
1043 message <<
"Point p is outside (!?) of solid: " <<
GetName() <<
G4endl;
1044 message <<
"Position:\n";
1045 message <<
" p.x() = " << p.
x()/
mm <<
" mm\n";
1046 message <<
" p.y() = " << p.
y()/
mm <<
" mm\n";
1047 message <<
" p.z() = " << p.
z()/
mm <<
" mm";
1048 G4cout.precision(oldprc);
1049 G4Exception(
"G4Trap::DistanceToOut(p)",
"GeomSolids1002",
1068 return (dist < 0) ? -dist : 0.;
1079 return (dist < 0) ? -dist : 0.;
1088 return (dist < 0) ? -dist : 0.;
1097 return (dist < 0) ? -dist : 0.;
1118 return new G4Trap(*
this);
1132 G4int oldprc = os.precision(16);
1133 os <<
"-----------------------------------------------------------\n"
1134 <<
" *** Dump for solid: " <<
GetName() <<
" ***\n"
1135 <<
" ===================================================\n"
1136 <<
" Solid type: G4Trap\n"
1138 <<
" half length Z: " <<
fDz/
mm <<
" mm\n"
1139 <<
" half length Y, face -Dz: " <<
fDy1/
mm <<
" mm\n"
1140 <<
" half length X, face -Dz, side -Dy1: " <<
fDx1/
mm <<
" mm\n"
1141 <<
" half length X, face -Dz, side +Dy1: " <<
fDx2/
mm <<
" mm\n"
1142 <<
" half length Y, face +Dz: " <<
fDy2/
mm <<
" mm\n"
1143 <<
" half length X, face +Dz, side -Dy2: " <<
fDx3/
mm <<
" mm\n"
1144 <<
" half length X, face +Dz, side +Dy2: " <<
fDx4/
mm <<
" mm\n"
1145 <<
" theta: " << theta/
degree <<
" degrees\n"
1146 <<
" phi: " << phi/
degree <<
" degrees\n"
1147 <<
" alpha, face -Dz: " << alpha1/
degree <<
" degrees\n"
1148 <<
" alpha, face +Dz: " <<
alpha2/
degree <<
" degrees\n"
1149 <<
"-----------------------------------------------------------\n";
1150 os.precision(oldprc);
1161 for (
G4int i=0; i<8; ++i)
1163 G4int iy = (i==0 || i==1 || i==4 || i==5) ? 0 : 1;
1164 G4int ix = (i==0 || i==2 || i==4 || i==6) ? 2 : 3;
1180 constexpr G4int iface [6][4] =
1181 { {0,1,3,2}, {0,4,5,1}, {2,3,7,6}, {0,2,6,4}, {1,5,7,3}, {4,6,7,5} };
1191 k -= (select <=
fAreas[4]);
1192 k -= (select <=
fAreas[3]);
1193 k -= (select <=
fAreas[2]);
1194 k -= (select <=
fAreas[1]);
1195 k -= (select <=
fAreas[0]);
1199 G4int i0 = iface[k][0];
1200 G4int i1 = iface[k][1];
1201 G4int i2 = iface[k][2];
1202 G4int i3 = iface[k][3];
1204 if (select >
fAreas[k] - s2) i0 = i2;
1210 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
1211 return (1.-u-v)*pt[i0] + u*pt[i1] + v*pt[i3];
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
static const G4double pMax
static const G4double pMin
static constexpr double mm
static constexpr double degree
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
G4bool BoundingBoxVsVoxelLimits(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
G4bool fRebuildPolyhedron
G4CSGSolid & operator=(const G4CSGSolid &rhs)
G4double halfCarTolerance
G4ThreeVector GetPointOnSurface() 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)
G4Polyhedron * CreatePolyhedron() const
G4double GetAlpha2() const
G4double GetAlpha1() const
G4double GetTheta() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
G4double GetSurfaceArea()
G4double GetZHalfLength() const
EInside Inside(const G4ThreeVector &p) const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
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)
G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector &p) const
G4double GetCubicVolume()
G4bool MakePlane(const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3, const G4ThreeVector &p4, TrapSidePlane &plane)
G4GeometryType GetEntityType() const
std::ostream & StreamInfo(std::ostream &os) const
void GetVertices(G4ThreeVector pt[8]) const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const
void DescribeYourselfTo(G4VGraphicsScene &scene) const
G4Trap & operator=(const G4Trap &rhs)
virtual void AddSolid(const G4Box &)=0
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
static const G4double kInfinity
static double normal(HepRandomEngine *eptr)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments