43 const G4int handedness,
54 axis0min, axis1min, axis0max, axis1max),
55 fKappa(kappa), fTanStereo(tanstereo),
56 fTan2Stereo(tanstereo*tanstereo), fR0(r0), fR02(r0*r0), fDPhi(twopi)
60 G4Exception(
"G4TwistTubsHypeSide::G4TwistTubsHypeSide()",
62 "Should swap axis0 and axis1!");
64 fInside.gp.
set(kInfinity, kInfinity, kInfinity);
98 fTanStereo = TanInnerStereo;
103 fTanStereo = TanOuterStereo;
106 fTan2Stereo = fTanStereo * fTanStereo;
112 fInside.gp.
set(kInfinity, kInfinity, kInfinity);
115 SetCorners(EndInnerRadius, EndOuterRadius, DPhi, EndPhi, EndZ) ;
165 normal = normal.
unit();
187 if (fInside.gp == gp)
189 return fInside.inside;
199 return fInside.inside;
206 if (distanceToOut < -halftol)
212 G4int areacode = GetAreaCode(p);
223 if (distanceToOut <= halftol)
234 G4cout <<
"WARNING - G4TwistTubsHypeSide::Inside()" <<
G4endl
235 <<
" Invalid option !" <<
G4endl
236 <<
" name, areacode, distanceToOut = "
237 <<
GetName() <<
", " << std::hex << areacode
238 << std::dec <<
", " << distanceToOut <<
G4endl;
242 return fInside.inside;
307 for (
auto i=0; i<2; ++i)
309 distance[i] = kInfinity;
312 gxx[i].
set(kInfinity, kInfinity, kInfinity);
342 if (vrho == 0 || (vrho/absvz) <= (absvz*std::fabs(fTanStereo)/absvz))
345 distance[0] = kInfinity;
347 isvalid[0], 0, validate, &gp, &gv);
353 G4double xxz = std::sqrt(fR02 / (vslope2 - fTan2Stereo))
354 * (vz / std::fabs(vz)) ;
356 xx[0].
set(t*v.
x(), t*v.
y(), xxz);
361 xx[0].
set(v.
x()*fR0, v.
y()*fR0, 0);
363 distance[0] = xx[0].
mag();
368 areacode[0] = GetAreaCode(xx[0]);
371 if (distance[0] >= 0) isvalid[0] =
true;
376 areacode[0] = GetAreaCode(xx[0],
false);
379 if (distance[0] >= 0) isvalid[0] =
true;
385 if (distance[0] >= 0) isvalid[0] =
true;
389 isvalid[0], 1, validate, &gp, &gv);
399 * ( p.
x() * v.
x() + p.
y() * v.
y() - p.
z() * v.
z() * fTan2Stereo );
400 G4double c = p.
x()*p.
x() + p.
y()*p.
y() - fR02 - p.
z()*p.
z()*fTan2Stereo;
409 xx[0] = p + distance[0]*v;
414 areacode[0] = GetAreaCode(xx[0]);
417 if (distance[0] >= 0) isvalid[0] =
true;
422 areacode[0] = GetAreaCode(xx[0],
false);
425 if (distance[0] >= 0) isvalid[0] =
true;
431 if (distance[0] >= 0) isvalid[0] =
true;
435 isvalid[0], 1, validate, &gp, &gv);
445 isvalid[0], 0, validate, &gp, &gv);
453 G4double tmpdist[2] = {kInfinity, kInfinity};
456 G4bool tmpisvalid[2] = {
false,
false};
458 for (
auto i=0; i<2; ++i)
460 tmpdist[i] = factor*(-b -
D);
462 tmpxx[i] = p + tmpdist[i]*v;
466 tmpareacode[i] = GetAreaCode(tmpxx[i]);
469 if (tmpdist[i] >= 0) tmpisvalid[i] =
true;
475 tmpareacode[i] = GetAreaCode(tmpxx[i],
false);
478 if (tmpdist[i] >= 0) tmpisvalid[i] =
true;
485 if (tmpdist[i] >= 0) tmpisvalid[i] =
true;
490 if (tmpdist[0] <= tmpdist[1])
492 distance[0] = tmpdist[0];
493 distance[1] = tmpdist[1];
498 areacode[0] = tmpareacode[0];
499 areacode[1] = tmpareacode[1];
500 isvalid[0] = tmpisvalid[0];
501 isvalid[1] = tmpisvalid[1];
505 distance[0] = tmpdist[1];
506 distance[1] = tmpdist[0];
511 areacode[0] = tmpareacode[1];
512 areacode[1] = tmpareacode[0];
513 isvalid[0] = tmpisvalid[1];
514 isvalid[1] = tmpisvalid[0];
518 isvalid[0], 2, validate, &gp, &gv);
520 isvalid[1], 2, validate, &gp, &gv);
529 isvalid[0], 0, validate, &gp, &gv);
568 for (
auto i=0; i<2; ++i)
570 distance[i] = kInfinity;
572 gxx[i].
set(kInfinity, kInfinity, kInfinity);
585 for (
auto i=0; i<2; ++i)
590 if ((gp - lastgxx[0]).mag() < halftol || (gp - lastgxx[1]).mag() < halftol)
609 G4double r1 = std::sqrt(fR02 + pz * pz * fTan2Stereo);
613 if (prho > r1 + halftol)
620 G4double z2 = (prho * fTanStereo + pz) / (1 + fTan2Stereo);
621 G4double r2 = std::sqrt(fR02 + z2 * z2 * fTan2Stereo);
630 distance[0] = (pabsz - xx1).mag();
639 else if (prho < r1 - halftol)
646 xx1.
set(r1, 0. , pz);
651 xx1.
set(t * pabsz.
x(), t * pabsz.
y() , pz);
667 xx2.
set(r2, 0. , 0.);
672 xx2.
set(t * pabsz.
x(), t * pabsz.
y() , 0.);
682 xx.
set(p.
x(), p.
y(), pz);
715 G4int phiareacode = GetAreaCodeInPhi(xx);
723 if (isoutsideinphi) isoutside =
true;
728 if (isoutsideinphi) isoutside =
true;
739 if (xx.
z() <=
fAxisMin[zaxis] - ctol) isoutside =
true;
742 else if (xx.
z() >
fAxisMax[zaxis] - ctol)
748 if (xx.
z() >=
fAxisMax[zaxis] + ctol) isoutside =
true;
756 G4int tmpareacode = areacode & (~sInside);
757 areacode = tmpareacode;
768 G4int phiareacode = GetAreaCodeInPhi(xx,
false);
809 std::ostringstream message;
810 message <<
"Feature NOT implemented !" <<
G4endl
812 <<
" fAxis[1] = " <<
fAxis[1];
852 G4int tmpareacode = areacode & (~sInside);
853 areacode = tmpareacode;
874void G4TwistTubsHypeSide::SetCorners(
G4double EndInnerRadius[2],
887 for (
auto i=0; i<2; ++i)
889 endRad[i] = (
fHandedness == 1 ? EndOuterRadius[i] : EndInnerRadius[i]);
898 x = endRad[zmin]*std::cos(endPhi[zmin] - halfdphi);
899 y = endRad[zmin]*std::sin(endPhi[zmin] - halfdphi);
904 x = endRad[zmin]*std::cos(endPhi[zmin] + halfdphi);
905 y = endRad[zmin]*std::sin(endPhi[zmin] + halfdphi);
910 x = endRad[zmax]*std::cos(endPhi[zmax] + halfdphi);
911 y = endRad[zmax]*std::sin(endPhi[zmax] + halfdphi);
916 x = endRad[zmax]*std::cos(endPhi[zmax] - halfdphi);
917 y = endRad[zmax]*std::sin(endPhi[zmax] - halfdphi);
924 std::ostringstream message;
925 message <<
"Feature NOT implemented !" <<
G4endl
927 <<
" fAxis[1] = " <<
fAxis[1];
936void G4TwistTubsHypeSide::SetCorners()
940 "Method NOT implemented !");
946void G4TwistTubsHypeSide::SetBoundaries()
957 direction = direction.
unit();
963 direction = direction.
unit();
969 direction = direction.
unit();
975 direction = direction.
unit();
981 std::ostringstream message;
982 message <<
"Feature NOT implemented !" <<
G4endl
984 <<
" fAxis[1] = " <<
fAxis[1];
985 G4Exception(
"G4TwistTubsHypeSide::SetBoundaries()",
1006 for (
G4int i = 0 ; i<n ; ++i )
1010 for (
G4int j = 0 ; j<k ; ++j )
1012 nnode =
GetNode(i,j,k,n,iside) ;
1019 x = xmin + j*(xmax-xmin)/(k-1) ;
1023 x = xmax - j*(xmax-xmin)/(k-1) ;
1028 xyz[nnode][0] = p.
x() ;
1029 xyz[nnode][1] = p.
y() ;
1030 xyz[nnode][2] = p.
z() ;
1032 if ( i<n-1 && j<k-1 )
1034 nface =
GetFace(i,j,k,n,iside) ;
1036 * (
GetNode(i ,j ,k,n,iside)+1) ;
1038 * (
GetNode(i+1,j ,k,n,iside)+1) ;
1040 * (
GetNode(i+1,j+1,k,n,iside)+1) ;
1042 * (
GetNode(i ,j+1,k,n,iside)+1) ;
G4double D(G4double temp)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
G4double GetRadialTolerance() const
static G4GeometryTolerance * GetInstance()
G4ThreeVector GetNormal(const G4ThreeVector &xx, G4bool isGlobal=false) override
G4int DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol) override
EInside Inside(const G4ThreeVector &gp)
~G4TwistTubsHypeSide() override
G4ThreeVector SurfacePoint(G4double, G4double, G4bool isGlobal=false) override
G4double GetBoundaryMin(G4double phi) override
G4TwistTubsHypeSide(const G4String &name, const G4RotationMatrix &rot, const G4ThreeVector &tlate, const G4int handedness, const G4double kappa, const G4double tanstereo, const G4double r0, const EAxis axis0=kPhi, const EAxis axis1=kZAxis, G4double axis0min=-kInfinity, G4double axis1min=-kInfinity, G4double axis0max=kInfinity, G4double axis1max=kInfinity)
G4double GetRhoAtPZ(const G4ThreeVector &p, G4bool isglobal=false) const
void GetFacets(G4int m, G4int n, G4double xyz[][3], G4int faces[][4], G4int iside) override
G4double GetBoundaryMax(G4double phi) override
G4int GetAreacode(G4int i) const
G4double GetDistance(G4int i) const
G4bool IsValid(G4int i) const
void SetCurrentStatus(G4int i, G4ThreeVector &xx, G4double &dist, G4int &areacode, G4bool &isvalid, G4int nxx, EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=nullptr)
G4ThreeVector GetXX(G4int i) const
void ResetfDone(EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=nullptr)
virtual G4int AmIOnLeftSide(const G4ThreeVector &me, const G4ThreeVector &vec, G4bool withTol=true)
static const G4int sC0Min1Min
static const G4int sC0Min1Max
G4int GetNode(G4int i, G4int j, G4int m, G4int n, G4int iside)
static const G4int sOutside
G4ThreeVector ComputeGlobalDirection(const G4ThreeVector &lp) const
static const G4int sAxisMax
static const G4int sAxis0
G4int GetFace(G4int i, G4int j, G4int m, G4int n, G4int iside)
G4int GetEdgeVisibility(G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation)
G4double DistanceToLine(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &d, G4ThreeVector &xx)
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
static const G4int sAxisPhi
static const G4int sAxisMin
static const G4int sC0Max1Max
static const G4int sAxis1
virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode, const G4ThreeVector &p) const
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const
virtual void SetBoundary(const G4int &axiscode, const G4ThreeVector &direction, const G4ThreeVector &x0, const G4int &boundarytype)
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const
void SetCorner(G4int areacode, G4double x, G4double y, G4double z)
G4ThreeVector GetCorner(G4int areacode) const
static const G4int sBoundary
static const G4int sAxisZ
G4bool IsOutside(G4int areacode) const
static const G4int sCorner
static const G4int sC0Max1Min
static const G4int sInside
virtual G4String GetName() const
CurrentStatus fCurStatWithV
G4bool IsBoundary(G4int areacode, G4bool testbitmode=false) const
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const
G4SurfCurNormal fCurrentNormal