34#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
46G4UTrap::G4UTrap(
const G4String& pName,
53 : Base_t(pName, pdz, pTheta, pPhi, pdy1, pdx1, pdx2,
54 pAlp1, pdy2, pdx3, pdx4, pAlp2)
62G4UTrap::G4UTrap(
const G4String& pName,
69 && pt[0].z() == pt[1].z()
70 && pt[0].z() == pt[2].z()
71 && pt[0].z() == pt[3].z()
74 && pt[4].z() == pt[5].z()
75 && pt[4].z() == pt[6].z()
76 && pt[4].z() == pt[7].z()
80 && pt[0].y() == pt[1].y()
81 && pt[2].y() == pt[3].y()
82 && pt[4].y() == pt[5].y()
83 && pt[6].y() == pt[7].y()
85 && std::abs(pt[0].y()+pt[2].y()+pt[4].y()+pt[6].y()) <
kCarTolerance
86 && std::abs(pt[0].x()+pt[1].x()+pt[4].x()+pt[5].x() +
89 std::ostringstream message;
90 message <<
"Invalid vertice coordinates for Solid: " << GetName();
100G4UTrap::G4UTrap(
const G4String& pName,
104 : Base_t(pName, pZ, pY, pX, pLTX)
109G4UTrap::G4UTrap(
const G4String& pName,
113 : Base_t(pName, pdx1, pdx2, pdy1, pdy2, pdz)
118G4UTrap::G4UTrap(
const G4String& pName,
121 : Base_t(pName, pdx, pdy, pdz, pAlpha, pTheta, pPhi)
126G4UTrap::G4UTrap(
const G4String& pName )
136G4UTrap::G4UTrap( __void__& a )
153G4UTrap::G4UTrap(
const G4UTrap& rhs)
162G4UTrap& G4UTrap::operator = (
const G4UTrap& rhs)
166 if (
this == &rhs) {
return *
this; }
170 Base_t::operator=(rhs);
179G4double G4UTrap::GetZHalfLength()
const
183G4double G4UTrap::GetYHalfLength1()
const
187G4double G4UTrap::GetXHalfLength1()
const
191G4double G4UTrap::GetXHalfLength2()
const
195G4double G4UTrap::GetTanAlpha1()
const
197 return Base_t::GetTanAlpha1();
199G4double G4UTrap::GetYHalfLength2()
const
203G4double G4UTrap::GetXHalfLength3()
const
207G4double G4UTrap::GetXHalfLength4()
const
211G4double G4UTrap::GetTanAlpha2()
const
213 return Base_t::GetTanAlpha2();
217 return Base_t::GetPhi();
221 return Base_t::GetTheta();
225 return Base_t::GetAlpha1();
229 return Base_t::GetAlpha2();
234 plane.
a = GetStruct().GetPlane(n).fA;
235 plane.
b = GetStruct().GetPlane(n).fB;
236 plane.
c = GetStruct().GetPlane(n).fC;
237 plane.
d = GetStruct().GetPlane(n).fD;
242 G4double tanThetaSphi = GetTanThetaSinPhi();
243 G4double tanThetaCphi = GetTanThetaCosPhi();
244 G4double tan2Theta = tanThetaSphi*tanThetaSphi + tanThetaCphi*tanThetaCphi;
245 G4double cosTheta = 1.0 / std::sqrt(1 + tan2Theta);
246 return G4ThreeVector(tanThetaCphi*cosTheta, tanThetaSphi*cosTheta, cosTheta);
266 SetTanAlpha1(std::tan(pAlp1));
267 SetTanAlpha1(std::tan(pAlp2));
271 fRebuildPolyhedron =
true;
286 for (
unsigned int i=0; i<8; ++i)
288 upt[i] = U3Vector(pt[i].x(), pt[i].y(), pt[i].z());
290 fromCornersToParameters(upt);
291 fRebuildPolyhedron =
true;
298void G4UTrap::CheckParameters()
const
309 fDy1<=0 || fDx1<=0 || fDx2<=0 ||
310 fDy2<=0 || fDx3<=0 || fDx4<=0)
312 std::ostringstream message;
313 message <<
"Invalid Length Parameters for Solid: " << GetName()
314 <<
"\n X - " <<fDx1<<
", "<<fDx2<<
", "<<fDx3<<
", "<<fDx4
315 <<
"\n Y - " <<fDy1<<
", "<<fDy2
317 G4Exception(
"G4UTrap::CheckParameters()",
"GeomSolids0002",
340 G4double DzTthetaCphi = fDz*std::tan(theta)*std::cos(phi);
341 G4double DzTthetaSphi = fDz*std::tan(theta)*std::sin(phi);
342 G4double Dy1Talpha1 = fDy1*fTalpha1;
343 G4double Dy2Talpha2 = fDy2*fTalpha2;
345 pt[0].
set(-DzTthetaCphi-Dy1Talpha1-fDx1,-DzTthetaSphi-fDy1,-fDz);
346 pt[1].
set(-DzTthetaCphi-Dy1Talpha1+fDx1,-DzTthetaSphi-fDy1,-fDz);
347 pt[2].
set(-DzTthetaCphi+Dy1Talpha1-fDx2,-DzTthetaSphi+fDy1,-fDz);
348 pt[3].
set(-DzTthetaCphi+Dy1Talpha1+fDx2,-DzTthetaSphi+fDy1,-fDz);
349 pt[4].
set( DzTthetaCphi-Dy2Talpha2-fDx3, DzTthetaSphi-fDy2, fDz);
350 pt[5].
set( DzTthetaCphi-Dy2Talpha2+fDx3, DzTthetaSphi-fDy2, fDz);
351 pt[6].
set( DzTthetaCphi+Dy2Talpha2-fDx4, DzTthetaSphi+fDy2, fDz);
352 pt[7].
set( DzTthetaCphi+Dy2Talpha2+fDx4, DzTthetaSphi+fDy2, fDz);
361 constexpr G4int iface[4][4] = { {0,4,5,1}, {2,3,7,6}, {0,2,6,4}, {1,5,7,3} };
362 const static G4String side[4] = {
"~-Y",
"~+Y",
"~-X",
"~+X" };
364 for (
G4int i=0; i<4; ++i)
368 for (
G4int k=0; k<4; ++k)
371 G4double dist = plane.
a*p.
x() + plane.
b*p.
y() + plane.
c*p.
z() + plane.
d;
372 if (std::abs(dist) > std::abs(dmax)) dmax = dist;
376 std::ostringstream message;
377 message <<
"Side face " << side[i] <<
" is not planar for solid: "
378 << GetName() <<
"\nDiscrepancy: " << dmax/mm <<
" mm\n";
380 G4Exception(
"G4UTrap::CheckPlanarity()",
"GeomSolids0002",
404 return new G4UTrap(*
this);
413 static G4bool checkBBox =
true;
416 for (
G4int i=0; i<4; ++i) { planes[i] = GetSidePlane(i); }
418 G4double xmin = kInfinity, xmax = -kInfinity;
419 G4double ymin = kInfinity, ymax = -kInfinity;
421 for (
G4int i=0; i<8; ++i)
423 G4int iy = (i==0 || i==1 || i==4 || i==5) ? 0 : 1;
424 G4int ix = (i==0 || i==2 || i==4 || i==6) ? 2 : 3;
426 G4double y = -(planes[iy].
c*z + planes[iy].
d)/planes[iy].b;
427 G4double x = -(planes[ix].
b*y + planes[ix].
c*z + planes[ix].
d)/planes[ix].a;
428 if (x < xmin) xmin = x;
429 if (x > xmax) xmax = x;
430 if (y < ymin) ymin = y;
431 if (y > ymax) ymax = y;
434 pMin.
set(xmin,ymin,-dz);
435 pMax.
set(xmax,ymax, dz);
439 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
441 std::ostringstream message;
442 message <<
"Bad bounding box (min >= max) for solid: "
444 <<
"\npMin = " << pMin
445 <<
"\npMax = " << pMax;
446 G4Exception(
"G4UTrap::BoundingLimits()",
"GeomMgt0001",
458 if (std::abs(pMin.
x()-vmin.x()) > tolerance ||
459 std::abs(pMin.
y()-vmin.y()) > tolerance ||
460 std::abs(pMin.
z()-vmin.z()) > tolerance ||
461 std::abs(pMax.
x()-vmax.x()) > tolerance ||
462 std::abs(pMax.
y()-vmax.y()) > tolerance ||
463 std::abs(pMax.
z()-vmax.z()) > tolerance)
465 std::ostringstream message;
466 message <<
"Inconsistency in bounding boxes for solid: "
468 <<
"\nBBox min: wrapper = " << pMin <<
" solid = " << vmin
469 <<
"\nBBox max: wrapper = " << pMax <<
" solid = " << vmax;
470 G4Exception(
"G4UTrap::BoundingLimits()",
"GeomMgt0001",
482G4UTrap::CalculateExtent(
const EAxis pAxis,
492 BoundingLimits(bmin,bmax);
495 if (
true)
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
497 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
499 return exist = (pMin < pMax) ?
true :
false;
505 for (
G4int i=0; i<4; ++i) { planes[i] = GetSidePlane(i); }
509 for (
G4int i=0; i<8; ++i)
511 G4int iy = (i==0 || i==1 || i==4 || i==5) ? 0 : 1;
512 G4int ix = (i==0 || i==2 || i==4 || i==6) ? 2 : 3;
514 G4double y = -(planes[iy].
c*z + planes[iy].
d)/planes[iy].b;
515 G4double x = -(planes[ix].
b*y + planes[ix].
c*z + planes[ix].
d)/planes[ix].a;
530 std::vector<const G4ThreeVectorList *> polygons(2);
531 polygons[0] = &baseA;
532 polygons[1] = &baseB;
535 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
547 GetXHalfLength1(), GetXHalfLength2(), GetAlpha1(),
549 GetXHalfLength3(), GetXHalfLength4(), GetAlpha2());
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const