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.)
90 :
G4CSGSolid(rhs), halfCarTolerance(rhs.halfCarTolerance),
91 fDx1(rhs.fDx1), fDx2(rhs.fDx2),
92 fDy1(rhs.fDy1), fDy2(rhs.fDy2), fDz(rhs.fDz),
93 fHx(rhs.fHx), fHy(rhs.fHy)
95 for (
G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
106 if (
this == &rhs) {
return *
this; }
114 halfCarTolerance = rhs.halfCarTolerance;
115 fDx1 = rhs.fDx1; fDx2 = rhs.fDx2;
116 fDy1 = rhs.fDy1; fDy2 = rhs.fDy2;
118 fHx = rhs.fHx; fHy = rhs.fHy;
119 for (
G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
137 fDx1 = pdx1; fDx2 = pdx2;
138 fDy1 = pdy1; fDy2 = pdy2;
149void G4Trd::CheckParameters()
152 if ((fDx1 < 0 || fDx2 < 0 || fDy1 < 0 || fDy2 < 0 || fDz < dmin) ||
153 (fDx1 < dmin && fDx2 < dmin) ||
154 (fDy1 < dmin && fDy2 < dmin))
156 std::ostringstream message;
157 message <<
"Invalid (too small or negative) dimensions for Solid: "
159 <<
"\n X - " << fDx1 <<
", " << fDx2
160 <<
"\n Y - " << fDy1 <<
", " << fDy2
162 G4Exception(
"G4Trd::CheckParameters()",
"GeomSolids0002",
171void G4Trd::MakePlanes()
176 fHx = std::sqrt(dy*dy + dz*dz);
177 fHy = std::sqrt(dx*dx + dz*dz);
182 fPlanes[0].b = -dz/fHx;
183 fPlanes[0].c = dy/fHx;
184 fPlanes[0].d = fPlanes[0].b*fDy1 + fPlanes[0].c*fDz;
186 fPlanes[1].a = fPlanes[0].a;
187 fPlanes[1].b = -fPlanes[0].b;
188 fPlanes[1].c = fPlanes[0].c;
189 fPlanes[1].d = fPlanes[0].d;
193 fPlanes[2].a = -dz/fHy;
195 fPlanes[2].c = dx/fHy;
196 fPlanes[2].d = fPlanes[2].a*fDx1 + fPlanes[2].c*fDz;
198 fPlanes[3].a = -fPlanes[2].a;
199 fPlanes[3].b = fPlanes[2].b;
200 fPlanes[3].c = fPlanes[2].c;
201 fPlanes[3].d = fPlanes[2].d;
213 (fDx2-fDx1)*(fDy2-fDy1)/3 );
227 4*(fDx1*fDy1 + fDx2*fDy2) + 2*(fDx1+fDx2)*fHx + 2*(fDy1+fDy2)*fHy;
258 pMin.
set(-xmax,-ymax,-dz);
259 pMax.
set( xmax, ymax, dz);
263 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
265 std::ostringstream message;
266 message <<
"Bad bounding box (min >= max) for solid: "
268 <<
"\npMin = " << pMin
269 <<
"\npMax = " << pMax;
296 return exist = (pMin < pMax) ?
true :
false;
308 baseA[0].set(-dx1,-dy1,-dz);
309 baseA[1].set( dx1,-dy1,-dz);
310 baseA[2].set( dx1, dy1,-dz);
311 baseA[3].set(-dx1, dy1,-dz);
312 baseB[0].set(-dx2,-dy2, dz);
313 baseB[1].set( dx2,-dy2, dz);
314 baseB[2].set( dx2, dy2, dz);
315 baseB[3].set(-dx2, dy2, dz);
317 std::vector<const G4ThreeVectorList *> polygons(2);
318 polygons[0] = &baseA;
319 polygons[1] = &baseB;
332 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
333 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
339 return (dist > halfCarTolerance) ?
kOutside :
355 if (std::abs(dz) <= halfCarTolerance)
357 nz = (p.
z() < 0) ? -1 : 1;
365 G4double dy2 = fPlanes[0].c*p.
z() + fPlanes[0].d;
366 if (std::abs(dy2 + dy1) <= halfCarTolerance)
372 if (std::abs(dy2 - dy1) <= halfCarTolerance)
383 G4double dx2 = fPlanes[2].c*p.
z() + fPlanes[2].d;
384 if (std::abs(dx2 + dx1) <= halfCarTolerance)
390 if (std::abs(dx2 - dx1) <= halfCarTolerance)
406 std::ostringstream message;
407 G4long oldprc = message.precision(16);
408 message <<
"Point p is not on surface (!?) of solid: "
410 message <<
"Position:\n";
411 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
412 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
413 message <<
" p.z() = " << p.
z()/mm <<
" mm";
414 G4cout.precision(oldprc) ;
415 G4Exception(
"G4Trd::SurfaceNormal(p)",
"GeomSolids1002",
419 return ApproxSurfaceNormal(p);
432 for (
G4int i=0; i<4; ++i)
436 fPlanes[i].c*p.
z() + fPlanes[i].d;
437 if (
d > dist) { dist =
d; iside = i; }
457 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() >= 0)
460 G4double dz = (invz < 0) ? fDz : -fDz;
466 G4double tmin0 = tzmin, tmax0 = tzmax;
467 G4double ya = fPlanes[0].b*v.
y(), yb = fPlanes[0].c*v.
z();
468 G4double yc = fPlanes[0].b*p.
y(), yd = fPlanes[0].c*p.
z()+fPlanes[0].d;
471 if (dis0 >= -halfCarTolerance)
473 if (cos0 >= 0)
return kInfinity;
475 if (tmin0 < tmp) tmin0 = tmp;
480 if (tmax0 > tmp) tmax0 = tmp;
483 G4double tmin1 = tmin0, tmax1 = tmax0;
486 if (dis1 >= -halfCarTolerance)
488 if (cos1 >= 0)
return kInfinity;
490 if (tmin1 < tmp) tmin1 = tmp;
495 if (tmax1 > tmp) tmax1 = tmp;
500 G4double tmin2 = tmin1, tmax2 = tmax1;
501 G4double xa = fPlanes[2].a*v.
x(), xb = fPlanes[2].c*v.
z();
502 G4double xc = fPlanes[2].a*p.
x(), xd = fPlanes[2].c*p.
z()+fPlanes[2].d;
505 if (dis2 >= -halfCarTolerance)
507 if (cos2 >= 0)
return kInfinity;
509 if (tmin2 < tmp) tmin2 = tmp;
514 if (tmax2 > tmp) tmax2 = tmp;
517 G4double tmin3 = tmin2, tmax3 = tmax2;
520 if (dis3 >= -halfCarTolerance)
522 if (cos3 >= 0)
return kInfinity;
524 if (tmin3 < tmp) tmin3 = tmp;
529 if (tmax3 > tmp) tmax3 = tmp;
534 G4double tmin = tmin3, tmax = tmax3;
535 if (tmax <= tmin + halfCarTolerance)
return kInfinity;
536 return (tmin < halfCarTolerance ) ? 0. : tmin;
547 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
548 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
554 return (dist > 0) ? dist : 0.;
569 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() > 0)
574 n->set(0, 0, (p.
z() < 0) ? -1 : 1);
580 G4int iside = (vz < 0) ? -4 : -2;
587 G4double cosa = fPlanes[i].b*v.
y() + fPlanes[i].c*v.
z();
590 G4double dist = fPlanes[i].b*p.
y()+fPlanes[i].c*p.
z()+fPlanes[i].d;
591 if (dist >= -halfCarTolerance)
596 n->set(0, fPlanes[i].
b, fPlanes[i].
c);
601 if (tmax > tmp) { tmax = tmp; iside = i; }
609 G4double cosa = fPlanes[i].a*v.
x()+fPlanes[i].c*v.
z();
612 G4double dist = fPlanes[i].a*p.
x()+fPlanes[i].c*p.
z()+fPlanes[i].d;
613 if (dist >= -halfCarTolerance)
618 n->set(fPlanes[i].
a, fPlanes[i].
b, fPlanes[i].
c);
623 if (tmax > tmp) { tmax = tmp; iside = i; }
633 n->set(0, 0, iside + 3);
635 n->set(fPlanes[iside].
a, fPlanes[iside].
b, fPlanes[iside].
c);
650 std::ostringstream message;
651 G4long oldprc = message.precision(16);
652 message <<
"Point p is outside (!?) of solid: " <<
GetName() <<
G4endl;
653 message <<
"Position:\n";
654 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
655 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
656 message <<
" p.z() = " << p.
z()/mm <<
" mm";
658 G4Exception(
"G4Trd::DistanceToOut(p)",
"GeomSolids1002",
663 G4double dx = fPlanes[3].a*std::abs(p.
x())+fPlanes[3].c*p.
z()+fPlanes[3].d;
664 G4double dy = fPlanes[1].b*std::abs(p.
y())+fPlanes[1].c*p.
z()+fPlanes[1].d;
670 return (dist < 0) ? -dist : 0.;
688 return new G4Trd(*
this);
697 G4long oldprc = os.precision(16);
698 os <<
"-----------------------------------------------------------\n"
699 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
700 <<
" ===================================================\n"
701 <<
" Solid type: G4Trd\n"
703 <<
" half length X, surface -dZ: " << fDx1/mm <<
" mm \n"
704 <<
" half length X, surface +dZ: " << fDx2/mm <<
" mm \n"
705 <<
" half length Y, surface -dZ: " << fDy1/mm <<
" mm \n"
706 <<
" half length Y, surface +dZ: " << fDy2/mm <<
" mm \n"
707 <<
" half length Z : " << fDz/mm <<
" mm \n"
708 <<
"-----------------------------------------------------------\n";
709 os.precision(oldprc);
724 G4double ssurf[6] = { 4.*fDx1*fDy1, sxz, sxz, syz, syz, 4.*fDx2*fDy2 };
725 ssurf[1] += ssurf[0];
726 ssurf[2] += ssurf[1];
727 ssurf[3] += ssurf[2];
728 ssurf[4] += ssurf[3];
729 ssurf[5] += ssurf[4];
735 k -= (select <= ssurf[4]);
736 k -= (select <= ssurf[3]);
737 k -= (select <= ssurf[2]);
738 k -= (select <= ssurf[1]);
739 k -= (select <= ssurf[0]);
749 return G4ThreeVector((2.*u - 1.)*fDx1, (2.*v - 1.)*fDy1, -fDz);
753 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
756 return (select <= ssurf[0] + fDx1*fHx) ?
762 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
765 return (select <= ssurf[1] + fDx1*fHx) ?
771 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
774 return (select <= ssurf[2] + fDy1*fHy) ?
780 if (u + v > 1.) { u = 1. - u; v = 1. - v; }
783 return (select <= ssurf[3] + fDy1*fHy) ?
789 return G4ThreeVector((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
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
EInside Inside(const G4ThreeVector &p) const
G4Trd(const G4String &pName, G4double pdx1, G4double pdx2, G4double pdy1, G4double pdy2, G4double pdz)
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
void DescribeYourselfTo(G4VGraphicsScene &scene) const
G4Trd & operator=(const G4Trd &rhs)
G4double GetYHalfLength2() const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
std::ostream & StreamInfo(std::ostream &os) const
G4ThreeVector GetPointOnSurface() const
G4double GetXHalfLength1() const
G4GeometryType GetEntityType() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4double GetYHalfLength1() const
G4double GetSurfaceArea()
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const
G4Polyhedron * CreatePolyhedron() const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
G4double GetCubicVolume()
G4double GetZHalfLength() const
virtual void AddSolid(const G4Box &)=0
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const