36#if !defined(G4GEOM_USE_UPARA)
78 fDx = (pt[3].
x() - pt[2].x())*0.5;
79 fDy = (pt[2].
y() - pt[1].y())*0.5;
83 fTalpha = (pt[2].
x() + pt[3].x() - pt[1].x() - pt[0].x())*0.25/fDy;
84 fTthetaCphi = (pt[4].
x() + fDy*fTalpha + fDx)/fDz;
85 fTthetaSphi = (pt[4].
y() + fDy)/fDz;
92 G4double DzTthetaSphi = fDz*fTthetaSphi;
93 G4double DzTthetaCphi = fDz*fTthetaCphi;
94 v[0].
set(-DzTthetaCphi-DyTalpha-fDx, -DzTthetaSphi-fDy, -fDz);
95 v[1].
set(-DzTthetaCphi-DyTalpha+fDx, -DzTthetaSphi-fDy, -fDz);
96 v[2].
set(-DzTthetaCphi+DyTalpha-fDx, -DzTthetaSphi+fDy, -fDz);
97 v[3].
set(-DzTthetaCphi+DyTalpha+fDx, -DzTthetaSphi+fDy, -fDz);
98 v[4].
set( DzTthetaCphi-DyTalpha-fDx, DzTthetaSphi-fDy, fDz);
99 v[5].
set( DzTthetaCphi-DyTalpha+fDx, DzTthetaSphi-fDy, fDz);
100 v[6].
set( DzTthetaCphi+DyTalpha-fDx, DzTthetaSphi+fDy, fDz);
101 v[7].
set( DzTthetaCphi+DyTalpha+fDx, DzTthetaSphi+fDy, fDz);
105 for (
G4int i=0; i<8; ++i)
107 G4double delx = std::abs(pt[i].x() - v[i].x());
108 G4double dely = std::abs(pt[i].y() - v[i].y());
109 G4double delz = std::abs(pt[i].z() - v[i].z());
110 G4double discrepancy = std::max(std::max(delx,dely),delz);
113 std::ostringstream message;
114 G4long oldprc = message.precision(16);
115 message <<
"Invalid vertice coordinates for Solid: " <<
GetName()
116 <<
"\nVertix #" << i <<
", discrepancy = " << discrepancy
117 <<
"\n original : " << pt[i]
118 <<
"\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;
290 std::min(-x0-x1-dx,-x0+x1-dx),x0-x1-dx),x0+x1-dx);
294 std::max(-x0-x1+dx,-x0+x1+dx),x0-x1+dx),x0+x1+dx);
297 G4double ymin = std::min(-y0-dy,y0-dy);
298 G4double ymax = std::max(-y0+dy,y0+dy);
300 pMin.
set(xmin,ymin,-dz);
301 pMax.
set(xmax,ymax, dz);
305 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
307 std::ostringstream message;
308 message <<
"Bad bounding box (min >= max) for solid: "
310 <<
"\npMin = " << pMin
311 <<
"\npMax = " << pMax;
312 G4Exception(
"G4Para::BoundingLimits()",
"GeomMgt0001",
339 return exist = pMin < pMax;
353 baseA[0].set(-x0-x1-dx,-y0-dy,-dz);
354 baseA[1].set(-x0-x1+dx,-y0-dy,-dz);
355 baseA[2].set(-x0+x1+dx,-y0+dy,-dz);
356 baseA[3].set(-x0+x1-dx,-y0+dy,-dz);
358 baseB[0].set(+x0-x1-dx, y0-dy, dz);
359 baseB[1].set(+x0-x1+dx, y0-dy, dz);
360 baseB[2].set(+x0+x1+dx, y0+dy, dz);
361 baseB[3].set(+x0+x1-dx, y0+dy, dz);
363 std::vector<const G4ThreeVectorList *> polygons(2);
364 polygons[0] = &baseA;
365 polygons[1] = &baseB;
379 G4double xx = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z();
380 G4double dx = std::abs(xx) + fPlanes[2].d;
382 G4double yy = fPlanes[0].b*p.
y()+fPlanes[0].c*p.
z();
383 G4double dy = std::abs(yy) + fPlanes[0].d;
389 if (dist > halfCarTolerance) {
return kOutside; }
406 if (std::abs(dz) <= halfCarTolerance)
408 nz = (p.
z() < 0) ? -1 : 1;
415 G4double yy = fPlanes[0].b*p.
y()+fPlanes[0].c*p.
z();
416 if (std::abs(fPlanes[0].
d + yy) <= halfCarTolerance)
422 else if (std::abs(fPlanes[1].
d - yy) <= halfCarTolerance)
432 G4double xx = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z();
433 if (std::abs(fPlanes[2].
d + xx) <= halfCarTolerance)
440 else if (std::abs(fPlanes[3].
d - xx) <= halfCarTolerance)
462 std::ostringstream message;
463 G4int oldprc = message.precision(16);
464 message <<
"Point p is not on surface (!?) of solid: "
466 message <<
"Position:\n";
467 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
468 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
469 message <<
" p.z() = " << p.
z()/mm <<
" mm";
470 G4cout.precision(oldprc) ;
471 G4Exception(
"G4Para::SurfaceNormal(p)",
"GeomSolids1002",
476 return ApproxSurfaceNormal(p);
488 for (
G4int i=0; i<4; ++i)
492 fPlanes[i].c*p.
z() + fPlanes[i].d;
493 if (
d > dist) { dist =
d; iside = i; }
499 return { fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c };
502 return { 0, 0, (
G4double)((p.
z() < 0) ? -1 : 1) };
515 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() >= 0)
521 G4double dz = (invz < 0) ? fDz : -fDz;
527 G4double tmin0 = tzmin, tmax0 = tzmax;
528 G4double cos0 = fPlanes[0].b*v.
y() + fPlanes[0].c*v.
z();
529 G4double disy = fPlanes[0].b*p.
y() + fPlanes[0].c*p.
z();
530 G4double dis0 = fPlanes[0].d + disy;
531 if (dis0 >= -halfCarTolerance)
533 if (cos0 >= 0) {
return kInfinity; }
535 if (tmin0 < tmp) { tmin0 = tmp; }
540 if (tmax0 > tmp) { tmax0 = tmp; }
543 G4double tmin1 = tmin0, tmax1 = tmax0;
545 G4double dis1 = fPlanes[1].d - disy;
546 if (dis1 >= -halfCarTolerance)
548 if (cos1 >= 0) {
return kInfinity; }
550 if (tmin1 < tmp) { tmin1 = tmp; }
555 if (tmax1 > tmp) { tmax1 = tmp; }
560 G4double tmin2 = tmin1, tmax2 = tmax1;
561 G4double cos2 = fPlanes[2].a*v.
x() + fPlanes[2].b*v.
y() + fPlanes[2].c*v.
z();
562 G4double disx = fPlanes[2].a*p.
x() + fPlanes[2].b*p.
y() + fPlanes[2].c*p.
z();
563 G4double dis2 = fPlanes[2].d + disx;
564 if (dis2 >= -halfCarTolerance)
566 if (cos2 >= 0) {
return kInfinity; }
568 if (tmin2 < tmp) { tmin2 = tmp; }
573 if (tmax2 > tmp) { tmax2 = tmp; }
576 G4double tmin3 = tmin2, tmax3 = tmax2;
578 G4double dis3 = fPlanes[3].d - disx;
579 if (dis3 >= -halfCarTolerance)
581 if (cos3 >= 0) {
return kInfinity; }
583 if (tmin3 < tmp) { tmin3 = tmp; }
588 if (tmax3 > tmp) { tmax3 = tmp; }
593 G4double tmin = tmin3, tmax = tmax3;
594 if (tmax <= tmin + halfCarTolerance) {
return kInfinity; }
596 return (tmin < halfCarTolerance ) ? 0. : tmin;
606 G4double xx = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z();
607 G4double dx = std::abs(xx) + fPlanes[2].d;
609 G4double yy = fPlanes[0].b*p.
y()+fPlanes[0].c*p.
z();
610 G4double dy = std::abs(yy) + fPlanes[0].d;
616 return (dist > 0) ? dist : 0.;
631 if ((std::abs(p.
z()) - fDz) >= -halfCarTolerance && p.
z()*v.
z() > 0)
636 n->set(0, 0, (p.
z() < 0) ? -1 : 1);
642 G4int iside = (vz < 0) ? -4 : -2;
646 G4double cos0 = fPlanes[0].b*v.
y() + fPlanes[0].c*v.
z();
649 G4double dis0 = fPlanes[0].b*p.
y() + fPlanes[0].c*p.
z() + fPlanes[0].d;
650 if (dis0 >= -halfCarTolerance)
655 n->set(0, fPlanes[0].
b, fPlanes[0].
c);
660 if (tmax > tmp) { tmax = tmp; iside = 0; }
666 G4double dis1 = fPlanes[1].b*p.
y() + fPlanes[1].c*p.
z() + fPlanes[1].d;
667 if (dis1 >= -halfCarTolerance)
672 n->set(0, fPlanes[1].
b, fPlanes[1].
c);
677 if (tmax > tmp) { tmax = tmp; iside = 1; }
682 G4double cos2 = fPlanes[2].a*v.
x() + fPlanes[2].b*v.
y() + fPlanes[2].c*v.
z();
685 G4double dis2 = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z()+fPlanes[2].d;
686 if (dis2 >= -halfCarTolerance)
691 n->set(fPlanes[2].
a, fPlanes[2].
b, fPlanes[2].
c);
696 if (tmax > tmp) { tmax = tmp; iside = 2; }
702 G4double dis3 = fPlanes[3].a*p.
x()+fPlanes[3].b*p.
y()
703 + fPlanes[3].c*p.
z()+fPlanes[3].d;
704 if (dis3 >= -halfCarTolerance)
709 n->set(fPlanes[3].
a, fPlanes[3].
b, fPlanes[3].
c);
714 if (tmax > tmp) { tmax = tmp; iside = 3; }
722 (iside < 0) ? (n->set(0, 0, iside + 3))
723 : (n->set(fPlanes[iside].
a, fPlanes[iside].
b, fPlanes[iside].
c));
738 std::ostringstream message;
739 G4int oldprc = message.precision(16);
740 message <<
"Point p is outside (!?) of solid: " <<
GetName() <<
G4endl;
741 message <<
"Position:\n";
742 message <<
" p.x() = " << p.
x()/mm <<
" mm\n";
743 message <<
" p.y() = " << p.
y()/mm <<
" mm\n";
744 message <<
" p.z() = " << p.
z()/mm <<
" mm";
745 G4cout.precision(oldprc) ;
746 G4Exception(
"G4Para::DistanceToOut(p)",
"GeomSolids1002",
751 G4double xx = fPlanes[2].a*p.
x()+fPlanes[2].b*p.
y()+fPlanes[2].c*p.
z();
752 G4double dx = std::abs(xx) + fPlanes[2].d;
754 G4double yy = fPlanes[0].b*p.
y()+fPlanes[0].c*p.
z();
755 G4double dy = std::abs(yy) + fPlanes[0].d;
761 return (dist < 0) ? -dist : 0.;
797 G4double alpha = std::atan(fTalpha);
798 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi +
799 fTthetaSphi*fTthetaSphi));
800 G4double phi = std::atan2(fTthetaSphi,fTthetaCphi);
802 G4long oldprc = os.precision(16);
803 os <<
"-----------------------------------------------------------\n"
804 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
805 <<
" ===================================================\n"
806 <<
" Solid type: G4Para\n"
808 <<
" half length X: " << fDx/mm <<
" mm\n"
809 <<
" half length Y: " << fDy/mm <<
" mm\n"
810 <<
" half length Z: " << fDz/mm <<
" mm\n"
811 <<
" alpha: " << alpha/degree <<
"degrees\n"
812 <<
" theta: " << theta/degree <<
"degrees\n"
813 <<
" phi: " << phi/degree <<
"degrees\n"
814 <<
"-----------------------------------------------------------\n";
815 os.precision(oldprc);
827 G4double sxz = fDx*fDz*std::sqrt(1. +
sqr(fTthetaSphi));
828 G4double syz = fDy*fDz*std::sqrt(1. +
sqr(fTalpha) +
sqr(fTalpha*fTthetaSphi - fTthetaCphi));
839 z = (select < 0.5*sxy) ? -fDz : fDz;
841 else if (select < sxy + sxz)
844 y = (select < sxy + 0.5*sxz) ? -fDy : fDy;
849 x = (select < sxy + sxz + 0.5*syz) ? -fDx : fDx;
853 return { x + y*fTalpha + z*fTthetaCphi, y + z*fTthetaSphi, z };
881 G4double sxz = fDx*fDz*std::sqrt(1. +
sqr(fTthetaSphi));
882 G4double syz = fDy*fDz*std::sqrt(1. +
sqr(fTalpha) +
sqr(fTalpha*fTthetaSphi - fTthetaCphi));
900 G4double phi = std::atan2(fTthetaSphi, fTthetaCphi);
901 G4double alpha = std::atan(fTalpha);
902 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi +
903 fTthetaSphi*fTthetaSphi));
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)
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
G4bool IsFaceted() 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
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...