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();
103G4UTrap::G4UTrap(
const G4String& pName,
107 : Base_t(pName, 0.5*pZ, 0, 0, 0.5*pY,
108 0.5*pX, 0.5*pLTX, 0.5*(pLTX - pX)/pY,
109 0.5*pY, 0.5*pX, 0.5*pLTX,
115G4UTrap::G4UTrap(
const G4String& pName,
119 : Base_t(pName, pdx1, pdx2, pdy1, pdy2, pdz)
124G4UTrap::G4UTrap(
const G4String& pName,
127 : Base_t(pName, pdx, pdy, pdz, pAlpha, pTheta, pPhi)
132G4UTrap::G4UTrap(
const G4String& pName )
142G4UTrap::G4UTrap( __void__& a )
151G4UTrap::~G4UTrap() =
default;
157G4UTrap::G4UTrap(
const G4UTrap& rhs)
166G4UTrap& G4UTrap::operator = (
const G4UTrap& rhs)
170 if (
this == &rhs) {
return *
this; }
174 Base_t::operator=(rhs);
183G4double G4UTrap::GetZHalfLength()
const
187G4double G4UTrap::GetYHalfLength1()
const
191G4double G4UTrap::GetXHalfLength1()
const
195G4double G4UTrap::GetXHalfLength2()
const
199G4double G4UTrap::GetTanAlpha1()
const
201 return Base_t::GetTanAlpha1();
203G4double G4UTrap::GetYHalfLength2()
const
207G4double G4UTrap::GetXHalfLength3()
const
211G4double G4UTrap::GetXHalfLength4()
const
215G4double G4UTrap::GetTanAlpha2()
const
217 return Base_t::GetTanAlpha2();
221 return Base_t::GetPhi();
225 return Base_t::GetTheta();
229 return Base_t::GetAlpha1();
233 return Base_t::GetAlpha2();
238 plane.
a = GetStruct().GetPlane(n).fA;
239 plane.
b = GetStruct().GetPlane(n).fB;
240 plane.
c = GetStruct().GetPlane(n).fC;
241 plane.
d = GetStruct().GetPlane(n).fD;
246 G4double tanThetaSphi = GetTanThetaSinPhi();
247 G4double tanThetaCphi = GetTanThetaCosPhi();
248 G4double tan2Theta = tanThetaSphi*tanThetaSphi + tanThetaCphi*tanThetaCphi;
249 G4double cosTheta = 1.0 / std::sqrt(1 + tan2Theta);
250 return {tanThetaCphi*cosTheta, tanThetaSphi*cosTheta, cosTheta};
270 SetTanAlpha1(std::tan(pAlp1));
271 SetTanAlpha2(std::tan(pAlp2));
275 fRebuildPolyhedron =
true;
290 for (
unsigned int i=0; i<8; ++i)
292 upt[i] = U3Vector(pt[i].x(), pt[i].y(), pt[i].z());
294 fromCornersToParameters(upt);
295 fRebuildPolyhedron =
true;
302void G4UTrap::CheckParameters()
const
313 fDy1<=0 || fDx1<=0 || fDx2<=0 ||
314 fDy2<=0 || fDx3<=0 || fDx4<=0)
316 std::ostringstream message;
317 message <<
"Invalid Length Parameters for Solid: " << GetName()
318 <<
"\n X - " <<fDx1<<
", "<<fDx2<<
", "<<fDx3<<
", "<<fDx4
319 <<
"\n Y - " <<fDy1<<
", "<<fDy2
321 G4Exception(
"G4UTrap::CheckParameters()",
"GeomSolids0002",
342 G4double DzTthetaCphi = fDz*GetTanThetaCosPhi();
343 G4double DzTthetaSphi = fDz*GetTanThetaSinPhi();
344 G4double Dy1Talpha1 = fDy1*fTalpha1;
345 G4double Dy2Talpha2 = fDy2*fTalpha2;
347 pt[0].
set(-DzTthetaCphi-Dy1Talpha1-fDx1,-DzTthetaSphi-fDy1,-fDz);
348 pt[1].
set(-DzTthetaCphi-Dy1Talpha1+fDx1,-DzTthetaSphi-fDy1,-fDz);
349 pt[2].
set(-DzTthetaCphi+Dy1Talpha1-fDx2,-DzTthetaSphi+fDy1,-fDz);
350 pt[3].
set(-DzTthetaCphi+Dy1Talpha1+fDx2,-DzTthetaSphi+fDy1,-fDz);
351 pt[4].
set( DzTthetaCphi-Dy2Talpha2-fDx3, DzTthetaSphi-fDy2, fDz);
352 pt[5].
set( DzTthetaCphi-Dy2Talpha2+fDx3, DzTthetaSphi-fDy2, fDz);
353 pt[6].
set( DzTthetaCphi+Dy2Talpha2-fDx4, DzTthetaSphi+fDy2, fDz);
354 pt[7].
set( DzTthetaCphi+Dy2Talpha2+fDx4, DzTthetaSphi+fDy2, fDz);
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)
370 for (
G4int k=0; k<4; ++k)
373 G4double dist = plane.
a*p.
x() + plane.
b*p.
y() + plane.
c*p.
z() + plane.
d;
374 if (std::abs(dist) > std::abs(dmax)) dmax = dist;
378 std::ostringstream message;
379 message <<
"Side face " << side[i] <<
" is not planar for solid: "
380 << GetName() <<
"\nDiscrepancy: " << dmax/mm <<
" mm\n";
382 G4Exception(
"G4UTrap::CheckPlanarity()",
"GeomSolids0002",
406 return new G4UTrap(*
this);
415 static G4bool checkBBox =
true;
418 for (
G4int i=0; i<4; ++i) { planes[i] = GetSidePlane(i); }
420 G4double xmin = kInfinity, xmax = -kInfinity;
421 G4double ymin = kInfinity, ymax = -kInfinity;
423 for (
G4int i=0; i<8; ++i)
425 G4int iy = (i==0 || i==1 || i==4 || i==5) ? 0 : 1;
426 G4int ix = (i==0 || i==2 || i==4 || i==6) ? 2 : 3;
428 G4double y = -(planes[iy].
c*z + planes[iy].
d)/planes[iy].b;
429 G4double x = -(planes[ix].
b*y + planes[ix].
c*z + planes[ix].
d)/planes[ix].a;
430 if (x < xmin) xmin = x;
431 if (x > xmax) xmax = x;
432 if (y < ymin) ymin = y;
433 if (y > ymax) ymax = y;
436 pMin.
set(xmin,ymin,-dz);
437 pMax.
set(xmax,ymax, dz);
441 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
443 std::ostringstream message;
444 message <<
"Bad bounding box (min >= max) for solid: "
446 <<
"\npMin = " << pMin
447 <<
"\npMax = " << pMax;
448 G4Exception(
"G4UTrap::BoundingLimits()",
"GeomMgt0001",
460 if (std::abs(pMin.
x()-vmin.x()) > tolerance ||
461 std::abs(pMin.
y()-vmin.y()) > tolerance ||
462 std::abs(pMin.
z()-vmin.z()) > tolerance ||
463 std::abs(pMax.
x()-vmax.x()) > tolerance ||
464 std::abs(pMax.
y()-vmax.y()) > tolerance ||
465 std::abs(pMax.
z()-vmax.z()) > tolerance)
467 std::ostringstream message;
468 message <<
"Inconsistency in bounding boxes for solid: "
470 <<
"\nBBox min: wrapper = " << pMin <<
" solid = " << vmin
471 <<
"\nBBox max: wrapper = " << pMax <<
" solid = " << vmax;
472 G4Exception(
"G4UTrap::BoundingLimits()",
"GeomMgt0001",
484G4UTrap::CalculateExtent(
const EAxis pAxis,
494 BoundingLimits(bmin,bmax);
497 if (
true)
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
499 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
501 return exist = pMin < pMax;
507 for (
G4int i=0; i<4; ++i) { planes[i] = GetSidePlane(i); }
511 for (
G4int i=0; i<8; ++i)
513 G4int iy = (i==0 || i==1 || i==4 || i==5) ? 0 : 1;
514 G4int ix = (i==0 || i==2 || i==4 || i==6) ? 2 : 3;
516 G4double y = -(planes[iy].
c*z + planes[iy].
d)/planes[iy].b;
517 G4double x = -(planes[ix].
b*y + planes[ix].
c*z + planes[ix].
d)/planes[ix].a;
532 std::vector<const G4ThreeVectorList *> polygons(2);
533 polygons[0] = &baseA;
534 polygons[1] = &baseB;
537 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
549 GetXHalfLength1(), GetXHalfLength2(), GetAlpha1(),
551 GetXHalfLength3(), GetXHalfLength4(), GetAlpha2());
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const