35#if !defined(G4GEOM_USE_UTRD)
59 fDx1(pdx1), fDx2(pdx2), fDy1(pdy1), fDy2(pdy2), fDz(pdz)
72 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;
211 (fDx2-fDx1)*(fDy2-fDy1)/3 );
225 4*(fDx1*fDy1 + fDx2*fDy2) + 2*(fDx1+fDx2)*fHx + 2*(fDy1+fDy2)*fHy;
256 pMin.
set(-xmax,-ymax,-dz);
257 pMax.
set( xmax, ymax, dz);
261 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
263 std::ostringstream message;
264 message <<
"Bad bounding box (min >= max) for solid: "
266 <<
"\npMin = " << pMin
267 <<
"\npMax = " << pMax;
294 return exist = pMin < pMax;
306 baseA[0].set(-dx1,-dy1,-dz);
307 baseA[1].set( dx1,-dy1,-dz);
308 baseA[2].set( dx1, dy1,-dz);
309 baseA[3].set(-dx1, dy1,-dz);
310 baseB[0].set(-dx2,-dy2, dz);
311 baseB[1].set( dx2,-dy2, dz);
312 baseB[2].set( dx2, dy2, dz);
313 baseB[3].set(-dx2, dy2, dz);
315 std::vector<const G4ThreeVectorList *> polygons(2);
316 polygons[0] = &baseA;
317 polygons[1] = &baseB;
330 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
331 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
337 return (dist > halfCarTolerance) ?
kOutside :
353 if (std::abs(dz) <= halfCarTolerance)
355 nz = (p.
z() < 0) ? -1 : 1;
363 G4double dy2 = fPlanes[0].c*p.
z() + fPlanes[0].d;
364 if (std::abs(dy2 + dy1) <= halfCarTolerance)
370 if (std::abs(dy2 - dy1) <= halfCarTolerance)
381 G4double dx2 = fPlanes[2].c*p.
z() + fPlanes[2].d;
382 if (std::abs(dx2 + dx1) <= halfCarTolerance)
388 if (std::abs(dx2 - dx1) <= halfCarTolerance)
397 if (nsurf == 1)
return {nx,ny,nz};
404 std::ostringstream message;
405 G4long oldprc = message.precision(16);
406 message <<
"Point p is not on surface (!?) of solid: "
408 message <<
"Position:\n";
409 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
410 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
411 message <<
" p.z() = " << p.
z()/mm <<
" mm";
412 G4cout.precision(oldprc) ;
413 G4Exception(
"G4Trd::SurfaceNormal(p)",
"GeomSolids1002",
417 return ApproxSurfaceNormal(p);
430 for (
G4int i=0; i<4; ++i)
434 fPlanes[i].c*p.
z() + fPlanes[i].d;
435 if (
d > dist) { dist =
d; iside = i; }
440 return { fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c };
442 return { 0, 0, (
G4double)((p.
z() < 0) ? -1 : 1) };
455 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() >= 0)
458 G4double dz = (invz < 0) ? fDz : -fDz;
464 G4double tmin0 = tzmin, tmax0 = tzmax;
465 G4double ya = fPlanes[0].b*v.
y(), yb = fPlanes[0].c*v.
z();
466 G4double yc = fPlanes[0].b*p.
y(), yd = fPlanes[0].c*p.
z()+fPlanes[0].d;
469 if (dis0 >= -halfCarTolerance)
471 if (cos0 >= 0)
return kInfinity;
473 if (tmin0 < tmp) tmin0 = tmp;
478 if (tmax0 > tmp) tmax0 = tmp;
481 G4double tmin1 = tmin0, tmax1 = tmax0;
484 if (dis1 >= -halfCarTolerance)
486 if (cos1 >= 0)
return kInfinity;
488 if (tmin1 < tmp) tmin1 = tmp;
493 if (tmax1 > tmp) tmax1 = tmp;
498 G4double tmin2 = tmin1, tmax2 = tmax1;
499 G4double xa = fPlanes[2].a*v.
x(), xb = fPlanes[2].c*v.
z();
500 G4double xc = fPlanes[2].a*p.
x(), xd = fPlanes[2].c*p.
z()+fPlanes[2].d;
503 if (dis2 >= -halfCarTolerance)
505 if (cos2 >= 0)
return kInfinity;
507 if (tmin2 < tmp) tmin2 = tmp;
512 if (tmax2 > tmp) tmax2 = tmp;
515 G4double tmin3 = tmin2, tmax3 = tmax2;
518 if (dis3 >= -halfCarTolerance)
520 if (cos3 >= 0)
return kInfinity;
522 if (tmin3 < tmp) tmin3 = tmp;
527 if (tmax3 > tmp) tmax3 = tmp;
532 G4double tmin = tmin3, tmax = tmax3;
533 if (tmax <= tmin + halfCarTolerance)
return kInfinity;
534 return (tmin < halfCarTolerance ) ? 0. : tmin;
545 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
546 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
552 return (dist > 0) ? dist : 0.;
567 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() > 0)
572 n->set(0, 0, (p.
z() < 0) ? -1 : 1);
578 G4int iside = (vz < 0) ? -4 : -2;
585 G4double cosa = fPlanes[i].b*v.
y() + fPlanes[i].c*v.
z();
588 G4double dist = fPlanes[i].b*p.
y()+fPlanes[i].c*p.
z()+fPlanes[i].d;
589 if (dist >= -halfCarTolerance)
594 n->set(0, fPlanes[i].
b, fPlanes[i].
c);
599 if (tmax > tmp) { tmax = tmp; iside = i; }
607 G4double cosa = fPlanes[i].a*v.
x()+fPlanes[i].c*v.
z();
610 G4double dist = fPlanes[i].a*p.
x()+fPlanes[i].c*p.
z()+fPlanes[i].d;
611 if (dist >= -halfCarTolerance)
616 n->set(fPlanes[i].
a, fPlanes[i].
b, fPlanes[i].
c);
621 if (tmax > tmp) { tmax = tmp; iside = i; }
631 n->set(0, 0, iside + 3);
633 n->set(fPlanes[iside].
a, fPlanes[iside].
b, fPlanes[iside].
c);
648 std::ostringstream message;
649 G4long oldprc = message.precision(16);
650 message <<
"Point p is outside (!?) of solid: " <<
GetName() <<
G4endl;
651 message <<
"Position:\n";
652 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
653 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
654 message <<
" p.z() = " << p.
z()/mm <<
" mm";
656 G4Exception(
"G4Trd::DistanceToOut(p)",
"GeomSolids1002",
661 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
662 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
668 return (dist < 0) ? -dist : 0.;
686 return new G4Trd(*
this);
695 G4long oldprc = os.precision(16);
696 os <<
"-----------------------------------------------------------\n"
697 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
698 <<
" ===================================================\n"
699 <<
" Solid type: G4Trd\n"
701 <<
" half length X, surface -dZ: " << fDx1/mm <<
" mm \n"
702 <<
" half length X, surface +dZ: " << fDx2/mm <<
" mm \n"
703 <<
" half length Y, surface -dZ: " << fDy1/mm <<
" mm \n"
704 <<
" half length Y, surface +dZ: " << fDy2/mm <<
" mm \n"
705 <<
" half length Z : " << fDz/mm <<
" mm \n"
706 <<
"-----------------------------------------------------------\n";
707 os.precision(oldprc);
722 G4double ssurf[6] = { 4.*fDx1*fDy1, sxz, sxz, syz, syz, 4.*fDx2*fDy2 };
723 ssurf[1] += ssurf[0];
724 ssurf[2] += ssurf[1];
725 ssurf[3] += ssurf[2];
726 ssurf[4] += ssurf[3];
727 ssurf[5] += ssurf[4];
733 k -= (
G4int)(select <= ssurf[4]);
734 k -= (
G4int)(select <= ssurf[3]);
735 k -= (
G4int)(select <= ssurf[2]);
736 k -= (
G4int)(select <= ssurf[1]);
737 k -= (
G4int)(select <= ssurf[0]);
747 return { (2.*u - 1.)*fDx1, (2.*v - 1.)*fDy1, -fDz };
751 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
754 return (select <= ssurf[0] + fDx1*fHx) ?
760 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
763 return (select <= ssurf[1] + fDx1*fHx) ?
769 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
772 return (select <= ssurf[2] + fDy1*fHy) ?
778 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
781 return (select <= ssurf[3] + fDy1*fHy) ?
787 return { (2.*u - 1.)*fDx2, (2.*v - 1.)*fDy2, fDz };
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)
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)
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
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
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const