61 #if !defined(G4GEOM_USE_UTET)
63 const char G4Tet::CVSVers[]=
"$Id: G4Tet.cc 101118 2016-11-07 09:10:59Z gcosmo $";
88 using namespace CLHEP;
104 :
G4VSolid(pName), fRebuildPolyhedron(false), fpPolyhedron(0), warningFlag(0)
124 fCubicVolume = std::fabs(signed_vol) / 6.;
137 fDx=(fXMax-fXMin)*0.5; fDy=(fYMax-fYMin)*0.5; fDz=(fZMax-fZMin)*0.5;
139 fMiddle=
G4ThreeVector(fXMax+fXMin, fYMax+fYMin, fZMax+fZMin)*0.5;
145 G4bool degenerate=std::fabs(signed_vol) < 1e-9*fMaxSize*fMaxSize*fMaxSize;
147 if(degeneracyFlag) *degeneracyFlag=degenerate;
151 "Degenerate tetrahedron not allowed.");
154 fTol=1e-9*(std::fabs(fXMin)+std::fabs(fXMax)+std::fabs(fYMin)
155 +std::fabs(fYMax)+std::fabs(fZMin)+std::fabs(fZMax));
183 fNormal123=normal123.
unit();
184 fNormal134=normal134.
unit();
185 fNormal142=normal142.
unit();
186 fNormal234=normal234.
unit();
188 fCdotN123=fCenter123.
dot(fNormal123);
189 fCdotN134=fCenter134.
dot(fNormal134);
190 fCdotN142=fCenter142.
dot(fNormal142);
191 fCdotN234=fCenter234.
dot(fNormal234);
200 :
G4VSolid(a), fCubicVolume(0.), fSurfaceArea(0.),
201 fRebuildPolyhedron(false), fpPolyhedron(0),
202 fAnchor(0,0,0), fP2(0,0,0), fP3(0,0,0), fP4(0,0,0), fMiddle(0,0,0),
203 fNormal123(0,0,0), fNormal142(0,0,0), fNormal134(0,0,0),
204 fNormal234(0,0,0), warningFlag(0),
205 fCdotN123(0.), fCdotN142(0.), fCdotN134(0.), fCdotN234(0.),
206 fXMin(0.), fXMax(0.), fYMin(0.), fYMax(0.), fZMin(0.), fZMax(0.),
207 fDx(0.), fDy(0.), fDz(0.), fTol(0.), fMaxSize(0.)
217 delete fpPolyhedron; fpPolyhedron = 0;
226 fCubicVolume(rhs.fCubicVolume), fSurfaceArea(rhs.fSurfaceArea),
227 fRebuildPolyhedron(false), fpPolyhedron(0), fAnchor(rhs.fAnchor),
228 fP2(rhs.fP2), fP3(rhs.fP3), fP4(rhs.fP4), fMiddle(rhs.fMiddle),
229 fNormal123(rhs.fNormal123), fNormal142(rhs.fNormal142),
230 fNormal134(rhs.fNormal134), fNormal234(rhs.fNormal234),
231 warningFlag(rhs.warningFlag), fCdotN123(rhs.fCdotN123),
232 fCdotN142(rhs.fCdotN142), fCdotN134(rhs.fCdotN134),
233 fCdotN234(rhs.fCdotN234), fXMin(rhs.fXMin), fXMax(rhs.fXMax),
234 fYMin(rhs.fYMin), fYMax(rhs.fYMax), fZMin(rhs.fZMin), fZMax(rhs.fZMax),
235 fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz), fTol(rhs.fTol),
236 fMaxSize(rhs.fMaxSize)
249 if (
this == &rhs) {
return *
this; }
257 fCubicVolume = rhs.fCubicVolume; fSurfaceArea = rhs.fSurfaceArea;
258 fAnchor = rhs.fAnchor;
259 fP2 = rhs.fP2; fP3 = rhs.fP3; fP4 = rhs.fP4; fMiddle = rhs.fMiddle;
260 fNormal123 = rhs.fNormal123; fNormal142 = rhs.fNormal142;
261 fNormal134 = rhs.fNormal134; fNormal234 = rhs.fNormal234;
262 warningFlag = rhs.warningFlag; fCdotN123 = rhs.fCdotN123;
263 fCdotN142 = rhs.fCdotN142; fCdotN134 = rhs.fCdotN134;
264 fCdotN234 = rhs.fCdotN234; fXMin = rhs.fXMin; fXMax = rhs.fXMax;
265 fYMin = rhs.fYMin; fYMax = rhs.fYMax; fZMin = rhs.fZMin; fZMax = rhs.fZMax;
266 fDx = rhs.fDx; fDy = rhs.fDy; fDz = rhs.fDz; fTol = rhs.fTol;
267 fMaxSize = rhs.fMaxSize;
268 fRebuildPolyhedron =
false;
269 delete fpPolyhedron; fpPolyhedron = 0;
284 G4Tet *
object=
new G4Tet(
"temp",anchor,p2,p3,p4,&result);
306 pMin.
set(fXMin,fYMin,fZMin);
307 pMax.
set(fXMax,fYMax,fZMax);
311 if (pMin.
x() >= pMax.
x() || pMin.
y() >= pMax.
y() || pMin.
z() >= pMax.
z())
313 std::ostringstream message;
314 message <<
"Bad bounding box (min >= max) for solid: "
316 <<
"\npMin = " << pMin
317 <<
"\npMax = " << pMax;
340 if (
true)
return bbox.
CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
344 return exist = (pMin < pMax) ?
true :
false;
352 anchor[0].set(vec[0].
x(),vec[0].y(),vec[0].
z());
355 base[0].set(vec[1].
x(),vec[1].y(),vec[1].
z());
356 base[1].set(vec[2].
x(),vec[2].y(),vec[2].
z());
357 base[2].set(vec[3].
x(),vec[3].y(),vec[3].
z());
359 std::vector<const G4ThreeVectorList *> polygons(2);
360 polygons[0] = &anchor;
379 if ( (r123=p.
dot(fNormal123)-fCdotN123) > fTol ||
380 (r134=p.
dot(fNormal134)-fCdotN134) > fTol ||
381 (r142=p.
dot(fNormal142)-fCdotN142) > fTol ||
382 (r234=p.
dot(fNormal234)-fCdotN234) > fTol )
386 else if( (r123 < -fTol)&&(r134 < -fTol)&&(r142 < -fTol)&&(r234 < -fTol) )
405 G4double r123=std::fabs(p.
dot(fNormal123)-fCdotN123);
406 G4double r134=std::fabs(p.
dot(fNormal134)-fCdotN134);
407 G4double r142=std::fabs(p.
dot(fNormal142)-fCdotN142);
408 G4double r234=std::fabs(p.
dot(fNormal234)-fCdotN234);
423 sumnorm += fNormal134;
429 sumnorm += fNormal142;
434 sumnorm += fNormal234;
439 if( noSurfaces == 1 )
445 return sumnorm.
unit();
451 if( (r123<=r134) && (r123<=r142) && (r123<=r234) ) {
return fNormal123; }
452 else if ( (r134<=r142) && (r134<=r234) ) {
return fNormal134; }
453 else if (r142 <= r234) {
return fNormal142; }
471 vdotn=-vu.dot(fNormal123);
474 t=(p.
dot(fNormal123)-fCdotN123)/vdotn;
475 if( (t>=-fTol) && (t<tmin) )
477 hp=p+vu*(t+extraDistance);
478 if ( ( hp.dot(fNormal134)-fCdotN134 < 0.0 ) &&
479 ( hp.dot(fNormal142)-fCdotN142 < 0.0 ) &&
480 ( hp.dot(fNormal234)-fCdotN234 < 0.0 ) )
487 vdotn=-vu.
dot(fNormal134);
490 t=(p.
dot(fNormal134)-fCdotN134)/vdotn;
491 if( (t>=-fTol) && (t<tmin) )
493 hp=p+vu*(t+extraDistance);
494 if ( ( hp.dot(fNormal123)-fCdotN123 < 0.0 ) &&
495 ( hp.dot(fNormal142)-fCdotN142 < 0.0 ) &&
496 ( hp.dot(fNormal234)-fCdotN234 < 0.0 ) )
503 vdotn=-vu.
dot(fNormal142);
506 t=(p.
dot(fNormal142)-fCdotN142)/vdotn;
507 if( (t>=-fTol) && (t<tmin) )
509 hp=p+vu*(t+extraDistance);
510 if ( ( hp.dot(fNormal123)-fCdotN123 < 0.0 ) &&
511 ( hp.dot(fNormal134)-fCdotN134 < 0.0 ) &&
512 ( hp.dot(fNormal234)-fCdotN234 < 0.0 ) )
519 vdotn=-vu.
dot(fNormal234);
522 t=(p.
dot(fNormal234)-fCdotN234)/vdotn;
523 if( (t>=-fTol) && (t<tmin) )
525 hp=p+vu*(t+extraDistance);
526 if ( ( hp.dot(fNormal123)-fCdotN123 < 0.0 ) &&
527 ( hp.dot(fNormal134)-fCdotN134 < 0.0 ) &&
528 ( hp.dot(fNormal142)-fCdotN142 < 0.0 ) )
546 G4double dd=(p-fMiddle).mag() - fMaxSize - fTol;
563 vdotn=vu.dot(fNormal123);
566 t1=(fCdotN123-p.
dot(fNormal123))/vdotn;
569 vdotn=vu.dot(fNormal134);
572 t2=(fCdotN134-p.
dot(fNormal134))/vdotn;
575 vdotn=vu.dot(fNormal142);
578 t3=(fCdotN142-p.
dot(fNormal142))/vdotn;
581 vdotn=vu.dot(fNormal234);
584 t4=(fCdotN234-p.
dot(fNormal234))/vdotn;
589 if (warningFlag && (tt ==
kInfinity || tt < -fTol))
592 std::ostringstream message;
593 message <<
"No good intersection found or already outside!?" <<
G4endl
594 <<
"p = " << p /
mm <<
"mm" <<
G4endl
596 <<
"t1, t2, t3, t4 (mm) "
597 << t1/
mm <<
", " << t2/
mm <<
", " << t3/
mm <<
", " << t4/
mm;
598 G4Exception(
"G4Tet::DistanceToOut(p,v,...)",
"GeomSolids1002",
605 else if(calcNorm && n)
608 if(tt==t1) { normal=fNormal123; }
609 else if (tt==t2) { normal=fNormal134; }
610 else if (tt==t3) { normal=fNormal142; }
611 else if (tt==t4) { normal=fNormal234; }
613 if(validNorm) { *validNorm=
true; }
628 t1=fCdotN123-p.
dot(fNormal123);
629 t2=fCdotN134-p.
dot(fNormal134);
630 t3=fCdotN142-p.
dot(fNormal142);
631 t4=fCdotN234-p.
dot(fNormal234);
637 return (tmin < fTol)? 0:tmin;
655 return new G4Tet(*
this);
664 G4int oldprc = os.precision(16);
665 os <<
"-----------------------------------------------------------\n"
666 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
667 <<
" ===================================================\n"
668 <<
" Solid type: G4Tet\n"
670 <<
" anchor: " << fAnchor/
mm <<
" mm \n"
671 <<
" p2: " << fP2/
mm <<
" mm \n"
672 <<
" p3: " << fP3/
mm <<
" mm \n"
673 <<
" p4: " << fP4/
mm <<
" mm \n"
674 <<
" normal123: " << fNormal123 <<
" \n"
675 <<
" normal134: " << fNormal134 <<
" \n"
676 <<
" normal142: " << fNormal142 <<
" \n"
677 <<
" normal234: " << fNormal234 <<
" \n"
678 <<
"-----------------------------------------------------------\n";
679 os.precision(oldprc);
703 area = 0.5*(v.
cross(w)).mag();
705 return (p2 + lambda1*w + lambda2*v);
714 G4double chose,aOne,aTwo,aThree,aFour;
717 p1 = GetPointOnFace(fAnchor,fP2,fP3,aOne);
718 p2 = GetPointOnFace(fAnchor,fP4,fP3,aTwo);
719 p3 = GetPointOnFace(fAnchor,fP4,fP2,aThree);
720 p4 = GetPointOnFace(fP4,fP3,fP2,aFour);
723 if( (chose>=0.) && (chose <aOne) ) {
return p1;}
724 else if( (chose>=aOne) && (chose < aOne+aTwo) ) {
return p2;}
725 else if( (chose>=aOne+aTwo) && (chose<aOne+aTwo+aThree) ) {
return p3;}
735 std::vector<G4ThreeVector> vertices(4);
736 vertices[0] = fAnchor;
779 return G4VisExtent (fXMin, fXMax, fYMin, fYMax, fZMin, fZMax);
790 const G4int faces[4][4]={{1,3,2,0},{1,4,3,0},{1,2,4,0},{2,3,4,0}};
791 xyz[0][0]=fAnchor.
x(); xyz[0][1]=fAnchor.
y(); xyz[0][2]=fAnchor.
z();
792 xyz[1][0]=fP2.
x(); xyz[1][1]=fP2.
y(); xyz[1][2]=fP2.
z();
793 xyz[2][0]=fP3.
x(); xyz[2][1]=fP3.
y(); xyz[2][2]=fP3.
z();
794 xyz[3][0]=fP4.
x(); xyz[3][1]=fP4.
y(); xyz[3][2]=fP4.
z();
808 fRebuildPolyhedron ||
815 fRebuildPolyhedron =
false;
G4double G4ParticleHPJENDLHEData::G4double result
void set(double x, double y, double z)
ThreeVector shoot(const G4int Ap, const G4int Af)
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
static constexpr double mm
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
G4ThreeVector GetPointOnSurface() const
double dot(const Hep3Vector &) const
std::vector< ExP01TrackerHit * > a
G4int createPolyhedron(G4int Nnodes, G4int Nfaces, const G4double xyz[][3], const G4int faces[][4])
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4GeometryType GetEntityType() const
virtual void AddSolid(const G4Box &)=0
const XML_Char int const XML_Char int const XML_Char * base
#define G4MUTEX_INITIALIZER
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
static double normal(HepRandomEngine *eptr)
std::vector< G4ThreeVector > GetVertices() const
void DescribeYourselfTo(G4VGraphicsScene &scene) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
static G4bool CheckDegeneracy(G4ThreeVector anchor, G4ThreeVector p2, G4ThreeVector p3, G4ThreeVector p4)
G4bool BoundingBoxVsVoxelLimits(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
void Extent(G4ThreeVector &pMin, G4ThreeVector &pMax) const
std::vector< G4ThreeVector > G4ThreeVectorList
G4Polyhedron * CreatePolyhedron() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
std::ostream & StreamInfo(std::ostream &os) const
static G4int GetNumberOfRotationSteps()
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4double GetCubicVolume()
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4double GetSurfaceArea()
EInside Inside(const G4ThreeVector &p) const
G4VisExtent GetExtent() const
G4VSolid & operator=(const G4VSolid &rhs)
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
Hep3Vector cross(const Hep3Vector &) const
G4Tet & operator=(const G4Tet &rhs)
void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
G4Polyhedron * GetPolyhedron() const
G4Tet(const G4String &pName, G4ThreeVector anchor, G4ThreeVector p2, G4ThreeVector p3, G4ThreeVector p4, G4bool *degeneracyFlag=0)
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const