36#if !defined(G4GEOM_USE_UPARA)
72 fDx = (pt[3].
x() - pt[2].x())*0.5;
73 fDy = (pt[2].
y() - pt[1].y())*0.5;
77 fTalpha = (pt[2].
x() + pt[3].x() - pt[1].x() - pt[0].x())*0.25/fDy;
78 fTthetaCphi = (pt[4].
x() + fDy*fTalpha + fDx)/fDz;
79 fTthetaSphi = (pt[4].
y() + fDy)/fDz;
86 G4double DzTthetaSphi = fDz*fTthetaSphi;
87 G4double DzTthetaCphi = fDz*fTthetaCphi;
88 v[0].
set(-DzTthetaCphi-DyTalpha-fDx, -DzTthetaSphi-fDy, -fDz);
89 v[1].
set(-DzTthetaCphi-DyTalpha+fDx, -DzTthetaSphi-fDy, -fDz);
90 v[2].
set(-DzTthetaCphi+DyTalpha-fDx, -DzTthetaSphi+fDy, -fDz);
91 v[3].
set(-DzTthetaCphi+DyTalpha+fDx, -DzTthetaSphi+fDy, -fDz);
92 v[4].
set( DzTthetaCphi-DyTalpha-fDx, DzTthetaSphi-fDy, fDz);
93 v[5].
set( DzTthetaCphi-DyTalpha+fDx, DzTthetaSphi-fDy, fDz);
94 v[6].
set( DzTthetaCphi+DyTalpha-fDx, DzTthetaSphi+fDy, fDz);
95 v[7].
set( DzTthetaCphi+DyTalpha+fDx, DzTthetaSphi+fDy, fDz);
99 for (
G4int i=0; i<8; ++i)
101 G4double delx = std::abs(pt[i].x() - v[i].x());
102 G4double dely = std::abs(pt[i].y() - v[i].y());
103 G4double delz = std::abs(pt[i].z() - v[i].z());
104 G4double discrepancy = std::max(std::max(delx,dely),delz);
107 std::ostringstream message;
108 G4long oldprc = message.precision(16);
109 message <<
"Invalid vertice coordinates for Solid: " <<
GetName()
110 <<
"\nVertix #" << i <<
", discrepancy = " << discrepancy
111 <<
"\n original : " << pt[i]
112 <<
"\n recomputed : " << v[i];
144 :
G4CSGSolid(rhs), halfCarTolerance(rhs.halfCarTolerance),
145 fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz), fTalpha(rhs.fTalpha),
146 fTthetaCphi(rhs.fTthetaCphi),fTthetaSphi(rhs.fTthetaSphi)
148 for (
G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
159 if (
this == &rhs) {
return *
this; }
167 halfCarTolerance = rhs.halfCarTolerance;
171 fTalpha = rhs.fTalpha;
172 fTthetaCphi = rhs.fTthetaCphi;
173 fTthetaSphi = rhs.fTthetaSphi;
174 for (
G4int i=0; i<4; ++i) { fPlanes[i] = rhs.fPlanes[i]; }
195 fTalpha = std::tan(pAlpha);
196 fTthetaCphi = std::tan(pTheta)*std::cos(pPhi);
197 fTthetaSphi = std::tan(pTheta)*std::sin(pPhi);
207void G4Para::CheckParameters()
213 std::ostringstream message;
214 message <<
"Invalid (too small or negative) dimensions for Solid: "
219 G4Exception(
"G4Para::CheckParameters()",
"GeomSolids0002",
228void G4Para::MakePlanes()
239 fPlanes[0].b = ynorm.
y();
240 fPlanes[0].c = ynorm.
z();
241 fPlanes[0].d = fPlanes[0].b*fDy;
244 fPlanes[1].b = -fPlanes[0].b;
245 fPlanes[1].c = -fPlanes[0].c;
246 fPlanes[1].d = fPlanes[0].d;
252 fPlanes[2].a = xnorm.
x();
253 fPlanes[2].b = xnorm.
y();
254 fPlanes[2].c = xnorm.
z();
255 fPlanes[2].d = fPlanes[2].a*fDx;
257 fPlanes[3].a = -fPlanes[2].a;
258 fPlanes[3].b = -fPlanes[2].b;
259 fPlanes[3].c = -fPlanes[2].c;
260 fPlanes[3].d = fPlanes[2].d;
325 std::min(-x0-x1-dx,-x0+x1-dx),x0-x1-dx),x0+x1-dx);
329 std::max(-x0-x1+dx,-x0+x1+dx),x0-x1+dx),x0+x1+dx);
332 G4double ymin = std::min(-y0-dy,y0-dy);
333 G4double ymax = std::max(-y0+dy,y0+dy);
335 pMin.
set(xmin,ymin,-dz);
336 pMax.
set(xmax,ymax, dz);
340 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
342 std::ostringstream message;
343 message <<
"Bad bounding box (min >= max) for solid: "
345 <<
"\npMin = " << pMin
346 <<
"\npMax = " << pMax;
347 G4Exception(
"G4Para::BoundingLimits()",
"GeomMgt0001",
374 return exist = pMin < pMax;
388 baseA[0].set(-x0-x1-dx,-y0-dy,-dz);
389 baseA[1].set(-x0-x1+dx,-y0-dy,-dz);
390 baseA[2].set(-x0+x1+dx,-y0+dy,-dz);
391 baseA[3].set(-x0+x1-dx,-y0+dy,-dz);
393 baseB[0].set(+x0-x1-dx, y0-dy, dz);
394 baseB[1].set(+x0-x1+dx, y0-dy, dz);
395 baseB[2].set(+x0+x1+dx, y0+dy, dz);
396 baseB[3].set(+x0+x1-dx, y0+dy, dz);
398 std::vector<const G4ThreeVectorList *> polygons(2);
399 polygons[0] = &baseA;
400 polygons[1] = &baseB;
414 G4double xx = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z();
415 G4double dx = std::abs(xx) + fPlanes[2].d;
417 G4double yy = fPlanes[0].b*p.
y()+fPlanes[0].c*p.
z();
418 G4double dy = std::abs(yy) + fPlanes[0].d;
424 if (dist > halfCarTolerance)
return kOutside;
440 if (std::abs(dz) <= halfCarTolerance)
442 nz = (p.
z() < 0) ? -1 : 1;
449 G4double yy = fPlanes[0].b*p.
y()+fPlanes[0].c*p.
z();
450 if (std::abs(fPlanes[0].
d + yy) <= halfCarTolerance)
456 else if (std::abs(fPlanes[1].
d - yy) <= halfCarTolerance)
466 G4double xx = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z();
467 if (std::abs(fPlanes[2].
d + xx) <= halfCarTolerance)
474 else if (std::abs(fPlanes[3].
d - xx) <= halfCarTolerance)
484 if (nsurf == 1)
return {nx,ny,nz};
491 std::ostringstream message;
492 G4int oldprc = message.precision(16);
493 message <<
"Point p is not on surface (!?) of solid: "
495 message <<
"Position:\n";
496 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
497 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
498 message <<
" p.z() = " << p.
z()/mm <<
" mm";
499 G4cout.precision(oldprc) ;
500 G4Exception(
"G4Para::SurfaceNormal(p)",
"GeomSolids1002",
504 return ApproxSurfaceNormal(p);
517 for (
G4int i=0; i<4; ++i)
521 fPlanes[i].c*p.
z() + fPlanes[i].d;
522 if (
d > dist) { dist =
d; iside = i; }
527 return { fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c };
529 return { 0, 0, (
G4double)((p.
z() < 0) ? -1 : 1) };
542 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() >= 0)
545 G4double dz = (invz < 0) ? fDz : -fDz;
551 G4double tmin0 = tzmin, tmax0 = tzmax;
552 G4double cos0 = fPlanes[0].b*v.
y() + fPlanes[0].c*v.
z();
553 G4double disy = fPlanes[0].b*p.
y() + fPlanes[0].c*p.
z();
554 G4double dis0 = fPlanes[0].d + disy;
555 if (dis0 >= -halfCarTolerance)
557 if (cos0 >= 0)
return kInfinity;
559 if (tmin0 < tmp) tmin0 = tmp;
564 if (tmax0 > tmp) tmax0 = tmp;
567 G4double tmin1 = tmin0, tmax1 = tmax0;
569 G4double dis1 = fPlanes[1].d - disy;
570 if (dis1 >= -halfCarTolerance)
572 if (cos1 >= 0)
return kInfinity;
574 if (tmin1 < tmp) tmin1 = tmp;
579 if (tmax1 > tmp) tmax1 = tmp;
584 G4double tmin2 = tmin1, tmax2 = tmax1;
585 G4double cos2 = fPlanes[2].a*v.
x() + fPlanes[2].b*v.
y() + fPlanes[2].c*v.
z();
586 G4double disx = fPlanes[2].a*p.
x() + fPlanes[2].b*p.
y() + fPlanes[2].c*p.
z();
587 G4double dis2 = fPlanes[2].d + disx;
588 if (dis2 >= -halfCarTolerance)
590 if (cos2 >= 0)
return kInfinity;
592 if (tmin2 < tmp) tmin2 = tmp;
597 if (tmax2 > tmp) tmax2 = tmp;
600 G4double tmin3 = tmin2, tmax3 = tmax2;
602 G4double dis3 = fPlanes[3].d - disx;
603 if (dis3 >= -halfCarTolerance)
605 if (cos3 >= 0)
return kInfinity;
607 if (tmin3 < tmp) tmin3 = tmp;
612 if (tmax3 > tmp) tmax3 = tmp;
617 G4double tmin = tmin3, tmax = tmax3;
618 if (tmax <= tmin + halfCarTolerance)
return kInfinity;
619 return (tmin < halfCarTolerance ) ? 0. : tmin;
629 G4double xx = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z();
630 G4double dx = std::abs(xx) + fPlanes[2].d;
632 G4double yy = fPlanes[0].b*p.
y()+fPlanes[0].c*p.
z();
633 G4double dy = std::abs(yy) + fPlanes[0].d;
639 return (dist > 0) ? dist : 0.;
654 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() > 0)
659 n->set(0, 0, (p.
z() < 0) ? -1 : 1);
665 G4int iside = (vz < 0) ? -4 : -2;
669 G4double cos0 = fPlanes[0].b*v.
y() + fPlanes[0].c*v.
z();
672 G4double dis0 = fPlanes[0].b*p.
y() + fPlanes[0].c*p.
z() + fPlanes[0].d;
673 if (dis0 >= -halfCarTolerance)
678 n->set(0, fPlanes[0].
b, fPlanes[0].
c);
683 if (tmax > tmp) { tmax = tmp; iside = 0; }
689 G4double dis1 = fPlanes[1].b*p.
y() + fPlanes[1].c*p.
z() + fPlanes[1].d;
690 if (dis1 >= -halfCarTolerance)
695 n->set(0, fPlanes[1].
b, fPlanes[1].
c);
700 if (tmax > tmp) { tmax = tmp; iside = 1; }
705 G4double cos2 = fPlanes[2].a*v.
x() + fPlanes[2].b*v.
y() + fPlanes[2].c*v.
z();
708 G4double dis2 = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z()+fPlanes[2].d;
709 if (dis2 >= -halfCarTolerance)
714 n->set(fPlanes[2].
a, fPlanes[2].
b, fPlanes[2].
c);
719 if (tmax > tmp) { tmax = tmp; iside = 2; }
725 G4double dis3 = fPlanes[3].a*p.
x()+fPlanes[3].b*p.
y()+fPlanes[3].c*p.
z()+fPlanes[3].d;
726 if (dis3 >= -halfCarTolerance)
731 n->set(fPlanes[3].
a, fPlanes[3].
b, fPlanes[3].
c);
736 if (tmax > tmp) { tmax = tmp; iside = 3; }
745 n->set(0, 0, iside + 3);
747 n->set(fPlanes[iside].
a, fPlanes[iside].
b, fPlanes[iside].
c);
762 std::ostringstream message;
763 G4int oldprc = message.precision(16);
764 message <<
"Point p is outside (!?) of solid: " <<
GetName() <<
G4endl;
765 message <<
"Position:\n";
766 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
767 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
768 message <<
" p.z() = " << p.
z()/mm <<
" mm";
769 G4cout.precision(oldprc) ;
770 G4Exception(
"G4Para::DistanceToOut(p)",
"GeomSolids1002",
775 G4double xx = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z();
776 G4double dx = std::abs(xx) + fPlanes[2].d;
778 G4double yy = fPlanes[0].b*p.
y()+fPlanes[0].c*p.
z();
779 G4double dy = std::abs(yy) + fPlanes[0].d;
785 return (dist < 0) ? -dist : 0.;
812 G4double alpha = std::atan(fTalpha);
813 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi +
814 fTthetaSphi*fTthetaSphi));
815 G4double phi = std::atan2(fTthetaSphi,fTthetaCphi);
817 G4long oldprc = os.precision(16);
818 os <<
"-----------------------------------------------------------\n"
819 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
820 <<
" ===================================================\n"
821 <<
" Solid type: G4Para\n"
823 <<
" half length X: " << fDx/mm <<
" mm\n"
824 <<
" half length Y: " << fDy/mm <<
" mm\n"
825 <<
" half length Z: " << fDz/mm <<
" mm\n"
826 <<
" alpha: " << alpha/degree <<
"degrees\n"
827 <<
" theta: " << theta/degree <<
"degrees\n"
828 <<
" phi: " << phi/degree <<
"degrees\n"
829 <<
"-----------------------------------------------------------\n";
830 os.precision(oldprc);
842 G4double DzTthetaSphi = fDz*fTthetaSphi;
843 G4double DzTthetaCphi = fDz*fTthetaCphi;
848 pt[0].
set(-DzTthetaCphi-DyTalpha-fDx, -DzTthetaSphi-fDy, -fDz);
849 pt[1].
set(-DzTthetaCphi-DyTalpha+fDx, -DzTthetaSphi-fDy, -fDz);
850 pt[2].
set(-DzTthetaCphi+DyTalpha-fDx, -DzTthetaSphi+fDy, -fDz);
851 pt[3].
set(-DzTthetaCphi+DyTalpha+fDx, -DzTthetaSphi+fDy, -fDz);
852 pt[4].
set( DzTthetaCphi-DyTalpha-fDx, DzTthetaSphi-fDy, fDz);
853 pt[5].
set( DzTthetaCphi-DyTalpha+fDx, DzTthetaSphi-fDy, fDz);
854 pt[6].
set( DzTthetaCphi+DyTalpha-fDx, DzTthetaSphi+fDy, fDz);
855 pt[7].
set( DzTthetaCphi+DyTalpha+fDx, DzTthetaSphi+fDy, fDz);
867 G4double sface[6] = { sxy, syz, syz, sxz, sxz, sxy };
868 for (
G4int i=1; i<6; ++i) { sface[i] += sface[i-1]; }
874 if (select <= sface[4]) k = 4;
875 if (select <= sface[3]) k = 3;
876 if (select <= sface[2]) k = 2;
877 if (select <= sface[1]) k = 1;
878 if (select <= sface[0]) k = 0;
882 G4int ip[6][3] = {{0,1,2}, {0,4,1}, {2,3,6}, {0,2,4}, {1,5,3}, {4,6,5}};
885 return (1.-u-v)*pt[ip[k][0]] + u*pt[ip[k][1]] + v*pt[ip[k][2]];
899 G4double phi = std::atan2(fTthetaSphi, fTthetaCphi);
900 G4double alpha = std::atan(fTalpha);
901 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi +
902 fTthetaSphi*fTthetaSphi));
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
Hep3Vector cross(const Hep3Vector &) const
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)
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
std::ostream & StreamInfo(std::ostream &os) const override
EInside Inside(const G4ThreeVector &p) const override
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const override
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
G4double GetSurfaceArea() override
G4Polyhedron * CreatePolyhedron() const override
G4double GetTanAlpha() const
G4GeometryType GetEntityType() const override
G4ThreeVector GetPointOnSurface() const override
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const override
G4Para & operator=(const G4Para &rhs)
G4Para(const G4String &pName, G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
G4VSolid * Clone() const override
void SetAllParameters(G4double pDx, G4double pDy, G4double pDz, G4double pAlpha, G4double pTheta, G4double pPhi)
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
G4double GetYHalfLength() const
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep) override
G4double GetZHalfLength() const
G4double GetCubicVolume() override
G4double GetXHalfLength() const
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
virtual void AddSolid(const G4Box &)=0
virtual void ComputeDimensions(G4Box &, const G4int, const G4VPhysicalVolume *) const