35#if !defined(G4GEOM_USE_UTRD)
65 fDx1(pdx1), fDx2(pdx2), fDy1(pdy1), fDy2(pdy2), fDz(pdz)
78 fDx1(1.), fDx2(1.), fDy1(1.), fDy2(1.), fDz(1.)
88 :
G4CSGSolid(rhs), halfCarTolerance(rhs.halfCarTolerance),
89 fDx1(rhs.fDx1), fDx2(rhs.fDx2),
90 fDy1(rhs.fDy1), fDy2(rhs.fDy2), fDz(rhs.fDz),
91 fHx(rhs.fHx), fHy(rhs.fHy)
93 for (
G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
104 if (
this == &rhs) {
return *
this; }
112 halfCarTolerance = rhs.halfCarTolerance;
113 fDx1 = rhs.fDx1; fDx2 = rhs.fDx2;
114 fDy1 = rhs.fDy1; fDy2 = rhs.fDy2;
116 fHx = rhs.fHx; fHy = rhs.fHy;
117 for (
G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
135 fDx1 = pdx1; fDx2 = pdx2;
136 fDy1 = pdy1; fDy2 = pdy2;
147void G4Trd::CheckParameters()
150 if ((fDx1 < 0 || fDx2 < 0 || fDy1 < 0 || fDy2 < 0 || fDz < dmin) ||
151 (fDx1 < dmin && fDx2 < dmin) ||
152 (fDy1 < dmin && fDy2 < dmin))
154 std::ostringstream message;
155 message <<
"Invalid (too small or negative) dimensions for Solid: "
157 <<
"\n X - " << fDx1 <<
", " << fDx2
158 <<
"\n Y - " << fDy1 <<
", " << fDy2
160 G4Exception(
"G4Trd::CheckParameters()",
"GeomSolids0002",
169void G4Trd::MakePlanes()
174 fHx = std::sqrt(dy*dy + dz*dz);
175 fHy = std::sqrt(dx*dx + dz*dz);
180 fPlanes[0].b = -dz/fHx;
181 fPlanes[0].c = dy/fHx;
182 fPlanes[0].d = fPlanes[0].b*fDy1 + fPlanes[0].c*fDz;
184 fPlanes[1].a = fPlanes[0].a;
185 fPlanes[1].b = -fPlanes[0].b;
186 fPlanes[1].c = fPlanes[0].c;
187 fPlanes[1].d = fPlanes[0].d;
191 fPlanes[2].a = -dz/fHy;
193 fPlanes[2].c = dx/fHy;
194 fPlanes[2].d = fPlanes[2].a*fDx1 + fPlanes[2].c*fDz;
196 fPlanes[3].a = -fPlanes[2].a;
197 fPlanes[3].b = fPlanes[2].b;
198 fPlanes[3].c = fPlanes[2].c;
199 fPlanes[3].d = fPlanes[2].d;
228 pMin.
set(-xmax,-ymax,-dz);
229 pMax.
set( xmax, ymax, dz);
233 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
235 std::ostringstream message;
236 message <<
"Bad bounding box (min >= max) for solid: "
238 <<
"\npMin = " << pMin
239 <<
"\npMax = " << pMax;
266 return exist = pMin < pMax;
278 baseA[0].set(-dx1,-dy1,-dz);
279 baseA[1].set( dx1,-dy1,-dz);
280 baseA[2].set( dx1, dy1,-dz);
281 baseA[3].set(-dx1, dy1,-dz);
282 baseB[0].set(-dx2,-dy2, dz);
283 baseB[1].set( dx2,-dy2, dz);
284 baseB[2].set( dx2, dy2, dz);
285 baseB[3].set(-dx2, dy2, dz);
287 std::vector<const G4ThreeVectorList *> polygons(2);
288 polygons[0] = &baseA;
289 polygons[1] = &baseB;
302 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
303 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
309 return (dist > halfCarTolerance) ?
kOutside :
325 if (std::abs(dz) <= halfCarTolerance)
327 nz = (p.
z() < 0) ? -1 : 1;
335 G4double dy2 = fPlanes[0].c*p.
z() + fPlanes[0].d;
336 if (std::abs(dy2 + dy1) <= halfCarTolerance)
342 if (std::abs(dy2 - dy1) <= halfCarTolerance)
353 G4double dx2 = fPlanes[2].c*p.
z() + fPlanes[2].d;
354 if (std::abs(dx2 + dx1) <= halfCarTolerance)
360 if (std::abs(dx2 - dx1) <= halfCarTolerance)
381 std::ostringstream message;
382 G4long oldprc = message.precision(16);
383 message <<
"Point p is not on surface (!?) of solid: "
385 message <<
"Position:\n";
386 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
387 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
388 message <<
" p.z() = " << p.
z()/mm <<
" mm";
389 G4cout.precision(oldprc) ;
390 G4Exception(
"G4Trd::SurfaceNormal(p)",
"GeomSolids1002",
394 return ApproxSurfaceNormal(p);
406 for (
G4int i=0; i<4; ++i)
410 fPlanes[i].c*p.
z() + fPlanes[i].d;
411 if (
d > dist) { dist =
d; iside = i; }
417 return { fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c };
420 return { 0, 0, (
G4double)((p.
z() < 0) ? -1 : 1) };
433 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() >= 0)
438 G4double dz = (invz < 0) ? fDz : -fDz;
444 G4double tmin0 = tzmin, tmax0 = tzmax;
445 G4double ya = fPlanes[0].b*v.
y(), yb = fPlanes[0].c*v.
z();
446 G4double yc = fPlanes[0].b*p.
y(), yd = fPlanes[0].c*p.
z()+fPlanes[0].d;
449 if (dis0 >= -halfCarTolerance)
451 if (cos0 >= 0) {
return kInfinity; }
453 if (tmin0 < tmp) { tmin0 = tmp; }
458 if (tmax0 > tmp) { tmax0 = tmp; }
461 G4double tmin1 = tmin0, tmax1 = tmax0;
464 if (dis1 >= -halfCarTolerance)
466 if (cos1 >= 0) {
return kInfinity; }
468 if (tmin1 < tmp) { tmin1 = tmp; }
473 if (tmax1 > tmp) { tmax1 = tmp; }
478 G4double tmin2 = tmin1, tmax2 = tmax1;
479 G4double xa = fPlanes[2].a*v.
x(), xb = fPlanes[2].c*v.
z();
480 G4double xc = fPlanes[2].a*p.
x(), xd = fPlanes[2].c*p.
z()+fPlanes[2].d;
483 if (dis2 >= -halfCarTolerance)
485 if (cos2 >= 0) {
return kInfinity; }
487 if (tmin2 < tmp) { tmin2 = tmp; }
492 if (tmax2 > tmp) { tmax2 = tmp; }
495 G4double tmin3 = tmin2, tmax3 = tmax2;
498 if (dis3 >= -halfCarTolerance)
500 if (cos3 >= 0) {
return kInfinity; }
502 if (tmin3 < tmp) { tmin3 = tmp; }
507 if (tmax3 > tmp) { tmax3 = tmp; }
512 G4double tmin = tmin3, tmax = tmax3;
513 if (tmax <= tmin + halfCarTolerance) {
return kInfinity;
515 return (tmin < halfCarTolerance ) ? 0. : tmin;
526 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
527 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
533 return (dist > 0) ? dist : 0.;
548 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() > 0)
553 n->set(0, 0, (p.
z() < 0) ? -1 : 1);
559 G4int iside = (vz < 0) ? -4 : -2;
566 G4double cosa = fPlanes[i].b*v.
y() + fPlanes[i].c*v.
z();
569 G4double dist = fPlanes[i].b*p.
y()+fPlanes[i].c*p.
z()+fPlanes[i].d;
570 if (dist >= -halfCarTolerance)
575 n->set(0, fPlanes[i].
b, fPlanes[i].
c);
580 if (tmax > tmp) { tmax = tmp; iside = i; }
588 G4double cosa = fPlanes[i].a*v.
x()+fPlanes[i].c*v.
z();
591 G4double dist = fPlanes[i].a*p.
x()+fPlanes[i].c*p.
z()+fPlanes[i].d;
592 if (dist >= -halfCarTolerance)
597 n->set(fPlanes[i].
a, fPlanes[i].
b, fPlanes[i].
c);
602 if (tmax > tmp) { tmax = tmp; iside = i; }
613 n->set(0, 0, iside + 3);
617 n->set(fPlanes[iside].
a, fPlanes[iside].
b, fPlanes[iside].
c);
633 std::ostringstream message;
634 G4long oldprc = message.precision(16);
635 message <<
"Point p is outside (!?) of solid: " <<
GetName() <<
G4endl;
636 message <<
"Position:\n";
637 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
638 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
639 message <<
" p.z() = " << p.
z()/mm <<
" mm";
641 G4Exception(
"G4Trd::DistanceToOut(p)",
"GeomSolids1002",
646 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
647 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
653 return (dist < 0) ? -dist : 0.;
680 return new G4Trd(*
this);
689 G4long oldprc = os.precision(16);
690 os <<
"-----------------------------------------------------------\n"
691 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
692 <<
" ===================================================\n"
693 <<
" Solid type: G4Trd\n"
695 <<
" half length X, surface -dZ: " << fDx1/mm <<
" mm \n"
696 <<
" half length X, surface +dZ: " << fDx2/mm <<
" mm \n"
697 <<
" half length Y, surface -dZ: " << fDy1/mm <<
" mm \n"
698 <<
" half length Y, surface +dZ: " << fDy2/mm <<
" mm \n"
699 <<
" half length Z : " << fDz/mm <<
" mm \n"
700 <<
"-----------------------------------------------------------\n";
701 os.precision(oldprc);
717 G4double stotal = sbase + 2.*(sxz + syz);
725 G4bool ifbottom = (select < sbot);
726 G4double x = (ifbottom) ? fDx1 : fDx2;
727 G4double y = (ifbottom) ? fDy1 : fDy2;
728 G4double z = (ifbottom) ? -fDz : fDz;
729 p.
set((2.*u - 1.)*x, (2.*v - 1.)*y, z);
731 else if (select < sbase + 2.*sxz)
733 G4double ysign = (select < sbase + sxz) ? 1. : -1.;
734 if (ysign < 0.) { select -= sxz; }
744 p = p0*(1. - u - v) + p1*u + p2*v;
749 G4double xsign = (select < sbase + 2.*sxz + syz) ? 1. : -1.;
750 if (xsign < 0.) { select -= syz; }
760 p = p0*(1. - u - v) + p1*u + p2*v;
775 fCubicVolume = 2*fDz*((fDx1+fDx2)*(fDy1+fDy2) + (fDx2-fDx1)*(fDy2-fDy1)/3);
790 fSurfaceArea = 4*(fDx1*fDy1+fDx2*fDy2)+2*(fDx1+fDx2)*fHx+2*(fDy1+fDy2)*fHy;
G4TemplateAutoLock< G4Mutex > G4AutoLock
const G4double kCarTolerance
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4double G4QuickRand(uint32_t seed=0)
#define G4MUTEX_INITIALIZER
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
G4BoundingEnvelope is a helper class to facilitate calculation of the extent of a solid within the li...
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(const G4String &pName)
G4CSGSolid & operator=(const G4CSGSolid &rhs)
void SetAllParameters(G4double pdx1, G4double pdx2, G4double pdy1, G4double pdy2, G4double pdz)
G4double GetXHalfLength2() const
std::ostream & StreamInfo(std::ostream &os) const override
G4Trd(const G4String &pName, G4double pdx1, G4double pdx2, G4double pdy1, G4double pdy2, G4double pdz)
G4double GetSurfaceArea() override
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const override
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
EInside Inside(const G4ThreeVector &p) const override
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
G4Trd & operator=(const G4Trd &rhs)
G4double GetYHalfLength2() const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
G4Polyhedron * CreatePolyhedron() const override
G4double GetXHalfLength1() const
G4ThreeVector GetPointOnSurface() const override
G4double GetYHalfLength1() const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
G4bool IsFaceted() const override
G4double GetCubicVolume() override
G4GeometryType GetEntityType() const override
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep) override
G4double GetZHalfLength() const
G4VSolid * Clone() const override
virtual void AddSolid(const G4Box &)=0
G4VPVParameterisation ia an abstract base class for Parameterisation, able to compute the transformat...
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4VSolid(const G4String &name)
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...