Geant4-11
Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
G4GenericTrap Class Reference

#include <G4GenericTrap.hh>

Inheritance diagram for G4GenericTrap:
G4VSolid

Public Member Functions

void BoundingLimits (G4ThreeVector &pMin, G4ThreeVector &pMax) const
 
G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
 
G4VSolidClone () const
 
virtual void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
G4PolyhedronCreatePolyhedron () const
 
void DescribeYourselfTo (G4VGraphicsScene &scene) const
 
G4double DistanceToIn (const G4ThreeVector &p) const
 
G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const
 
G4double DistanceToOut (const G4ThreeVector &p) const
 
G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const
 
void DumpInfo () const
 
G4double EstimateCubicVolume (G4int nStat, G4double epsilon) const
 
G4double EstimateSurfaceArea (G4int nStat, G4double ell) const
 
 G4GenericTrap (__void__ &)
 
 G4GenericTrap (const G4GenericTrap &rhs)
 
 G4GenericTrap (const G4String &name, G4double halfZ, const std::vector< G4TwoVector > &vertices)
 
virtual G4VSolidGetConstituentSolid (G4int no)
 
virtual const G4VSolidGetConstituentSolid (G4int no) const
 
G4double GetCubicVolume ()
 
virtual G4DisplacedSolidGetDisplacedSolidPtr ()
 
virtual const G4DisplacedSolidGetDisplacedSolidPtr () const
 
G4GeometryType GetEntityType () const
 
G4VisExtent GetExtent () const
 
G4String GetName () const
 
G4int GetNofVertices () const
 
G4ThreeVector GetPointOnSurface () const
 
G4PolyhedronGetPolyhedron () const
 
G4double GetSurfaceArea ()
 
G4double GetTolerance () const
 
G4double GetTwistAngle (G4int index) const
 
G4TwoVector GetVertex (G4int index) const
 
const std::vector< G4TwoVector > & GetVertices () const
 
G4int GetVisSubdivisions () const
 
G4double GetZHalfLength () const
 
EInside Inside (const G4ThreeVector &p) const
 
G4bool IsTwisted () const
 
G4GenericTrapoperator= (const G4GenericTrap &rhs)
 
G4bool operator== (const G4VSolid &s) const
 
void SetName (const G4String &name)
 
void SetVisSubdivisions (G4int subdiv)
 
std::ostream & StreamInfo (std::ostream &os) const
 
G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const
 
 ~G4GenericTrap ()
 

Protected Member Functions

void CalculateClippedPolygonExtent (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipBetweenSections (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipCrossSection (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipPolygon (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
 

Protected Attributes

G4PolyhedronfpPolyhedron = nullptr
 
G4bool fRebuildPolyhedron = false
 
G4double kCarTolerance
 

Private Types

enum  ESide {
  kUndef , kXY0 , kXY1 , kXY2 ,
  kXY3 , kMZ , kPZ
}
 

Private Member Functions

G4bool CheckOrder (const std::vector< G4TwoVector > &vertices) const
 
void ClipPolygonToSimpleLimits (G4ThreeVectorList &pPolygon, G4ThreeVectorList &outputPolygon, const G4VoxelLimits &pVoxelLimit) const
 
void ComputeBBox ()
 
G4bool ComputeIsTwisted ()
 
G4TessellatedSolidCreateTessellatedSolid () const
 
G4double DistToPlane (const G4ThreeVector &p, const G4ThreeVector &v, const G4int ipl) const
 
G4double DistToTriangle (const G4ThreeVector &p, const G4ThreeVector &v, const G4int ipl) const
 
G4double GetFaceCubicVolume (const G4ThreeVector &p0, const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3) const
 
G4double GetFaceSurfaceArea (const G4ThreeVector &p0, const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3) const
 
G4ThreeVector GetMaximumBBox () const
 
G4ThreeVector GetMinimumBBox () const
 
G4double GetTwistedFaceSurfaceArea (const G4ThreeVector &p0, const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3) const
 
EInside InsidePolygone (const G4ThreeVector &p, const std::vector< G4TwoVector > &poly) const
 
G4bool IsSegCrossing (const G4TwoVector &a, const G4TwoVector &b, const G4TwoVector &c, const G4TwoVector &d) const
 
G4bool IsSegCrossingZ (const G4TwoVector &a, const G4TwoVector &b, const G4TwoVector &c, const G4TwoVector &d) const
 
G4VFacetMakeDownFacet (const std::vector< G4ThreeVector > &fromVertices, G4int ind1, G4int ind2, G4int ind3) const
 
G4VFacetMakeSideFacet (const G4ThreeVector &downVertex0, const G4ThreeVector &downVertex1, const G4ThreeVector &upVertex1, const G4ThreeVector &upVertex0) const
 
G4VFacetMakeUpFacet (const std::vector< G4ThreeVector > &fromVertices, G4int ind1, G4int ind2, G4int ind3) const
 
G4ThreeVector NormalToPlane (const G4ThreeVector &p, const G4int ipl) const
 
void ReorderVertices (std::vector< G4ThreeVector > &vertices) const
 
G4double SafetyToFace (const G4ThreeVector &p, const G4int iseg) const
 
void SetTwistAngle (G4int index, G4double twist)
 

Private Attributes

G4double fCubicVolume = 0.0
 
G4double fDz
 
G4bool fIsTwisted = false
 
G4ThreeVector fMaxBBoxVector
 
G4ThreeVector fMinBBoxVector
 
G4String fshapeName
 
G4double fSurfaceArea = 0.0
 
G4TessellatedSolidfTessellatedSolid = nullptr
 
G4double fTwist [4]
 
std::vector< G4TwoVectorfVertices
 
G4int fVisSubdivisions = 0
 
G4double halfCarTolerance
 

Static Private Attributes

static const G4int fgkNofVertices = 8
 
static const G4double fgkTolerance = 1E-3
 

Detailed Description

Definition at line 79 of file G4GenericTrap.hh.

Member Enumeration Documentation

◆ ESide

enum G4GenericTrap::ESide
private
Enumerator
kUndef 
kXY0 
kXY1 
kXY2 
kXY3 
kMZ 
kPZ 

Definition at line 221 of file G4GenericTrap.hh.

Constructor & Destructor Documentation

◆ G4GenericTrap() [1/3]

G4GenericTrap::G4GenericTrap ( const G4String name,
G4double  halfZ,
const std::vector< G4TwoVector > &  vertices 
)

Definition at line 65 of file G4GenericTrap.cc.

67 : G4VSolid(name), fDz(halfZ), fVertices(),
69{
70 // General constructor
71 const G4double min_length=5*1.e-6;
72 G4double length = 0.;
73 G4int k=0;
74 G4String errorDescription = "InvalidSetup in \" ";
75 errorDescription += name;
76 errorDescription += "\"";
77
79
80 // Check vertices size
81
82 if ( G4int(vertices.size()) != fgkNofVertices )
83 {
84 G4Exception("G4GenericTrap::G4GenericTrap()", "GeomSolids0002",
85 FatalErrorInArgument, "Number of vertices != 8");
86 }
87
88 // Check dZ
89 //
90 if (halfZ < kCarTolerance)
91 {
92 G4Exception("G4GenericTrap::G4GenericTrap()", "GeomSolids0002",
93 FatalErrorInArgument, "dZ is too small or negative");
94 }
95
96 // Check Ordering and Copy vertices
97 //
98 if(CheckOrder(vertices))
99 {
100 for (G4int i=0; i<fgkNofVertices; ++i) {fVertices.push_back(vertices[i]);}
101 }
102 else
103 {
104 for (auto i=0; i <4; ++i) {fVertices.push_back(vertices[3-i]);}
105 for (auto i=0; i <4; ++i) {fVertices.push_back(vertices[7-i]);}
106 }
107
108 // Check length of segments and Adjust
109 //
110 for (auto j=0; j<2; ++j)
111 {
112 for (auto i=1; i<4; ++i)
113 {
114 k = j*4+i;
115 length = (fVertices[k]-fVertices[k-1]).mag();
116 if ( ( length < min_length) && ( length > kCarTolerance ) )
117 {
118 std::ostringstream message;
119 message << "Length segment is too small." << G4endl
120 << "Distance between " << fVertices[k-1] << " and "
121 << fVertices[k] << " is only " << length << " mm !";
122 G4Exception("G4GenericTrap::G4GenericTrap()", "GeomSolids1001",
123 JustWarning, message, "Vertices will be collapsed.");
124 fVertices[k]=fVertices[k-1];
125 }
126 }
127 }
128
129 // Compute Twist
130 //
131 for( auto i=0; i<4; ++i) { fTwist[i]=0.; }
133
134 // Compute Bounding Box
135 //
136 ComputeBBox();
137
138 // If not twisted - create tessellated solid
139 // (an alternative implementation for testing)
140 //
141#ifdef G4TESS_TEST
143#endif
144}
@ JustWarning
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
std::vector< G4TwoVector > fVertices
static const G4int fgkNofVertices
G4double halfCarTolerance
G4double fTwist[4]
G4ThreeVector fMinBBoxVector
G4ThreeVector fMaxBBoxVector
G4bool ComputeIsTwisted()
G4TessellatedSolid * fTessellatedSolid
G4TessellatedSolid * CreateTessellatedSolid() const
G4bool CheckOrder(const std::vector< G4TwoVector > &vertices) const
G4VSolid(const G4String &name)
Definition: G4VSolid.cc:57
G4double kCarTolerance
Definition: G4VSolid.hh:299
const char * name(G4int ptype)

References CheckOrder(), ComputeBBox(), ComputeIsTwisted(), CreateTessellatedSolid(), FatalErrorInArgument, fgkNofVertices, fIsTwisted, fTessellatedSolid, fTwist, fVertices, G4endl, G4Exception(), halfCarTolerance, JustWarning, G4VSolid::kCarTolerance, and G4InuclParticleNames::name().

Referenced by Clone().

◆ ~G4GenericTrap()

G4GenericTrap::~G4GenericTrap ( )

Definition at line 158 of file G4GenericTrap.cc.

159{
160 delete fTessellatedSolid;
161}

References fTessellatedSolid.

◆ G4GenericTrap() [2/3]

G4GenericTrap::G4GenericTrap ( __void__ &  a)

Definition at line 148 of file G4GenericTrap.cc.

149 : G4VSolid(a), halfCarTolerance(0.), fDz(0.), fVertices(),
151{
152 // Fake default constructor - sets only member data and allocates memory
153 // for usage restricted to object persistency.
154}

◆ G4GenericTrap() [3/3]

G4GenericTrap::G4GenericTrap ( const G4GenericTrap rhs)

Definition at line 165 of file G4GenericTrap.cc.

166 : G4VSolid(rhs),
168 fDz(rhs.fDz), fVertices(rhs.fVertices),
173{
174 for (auto i=0; i<4; ++i) { fTwist[i] = rhs.fTwist[i]; }
175#ifdef G4TESS_TEST
176 if (rhs.fTessellatedSolid && !fIsTwisted )
178#endif
179}
G4int fVisSubdivisions
G4double fCubicVolume
G4double fSurfaceArea

References CreateTessellatedSolid(), fIsTwisted, fTessellatedSolid, and fTwist.

Member Function Documentation

◆ BoundingLimits()

void G4GenericTrap::BoundingLimits ( G4ThreeVector pMin,
G4ThreeVector pMax 
) const
virtual

Reimplemented from G4VSolid.

Definition at line 1176 of file G4GenericTrap.cc.

1178{
1179 pMin = GetMinimumBBox();
1180 pMax = GetMaximumBBox();
1181
1182 // Check correctness of the bounding box
1183 //
1184 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
1185 {
1186 std::ostringstream message;
1187 message << "Bad bounding box (min >= max) for solid: "
1188 << GetName() << " !"
1189 << "\npMin = " << pMin
1190 << "\npMax = " << pMax;
1191 G4Exception("G4GenericTrap::BoundingLimits()", "GeomMgt0001",
1192 JustWarning, message);
1193 DumpInfo();
1194 }
1195}
static const G4double pMax
static const G4double pMin
G4ThreeVector GetMinimumBBox() const
G4ThreeVector GetMaximumBBox() const
G4String GetName() const
void DumpInfo() const

References G4VSolid::DumpInfo(), G4Exception(), GetMaximumBBox(), GetMinimumBBox(), G4VSolid::GetName(), JustWarning, pMax, and pMin.

Referenced by CalculateExtent().

◆ CalculateClippedPolygonExtent()

void G4VSolid::CalculateClippedPolygonExtent ( G4ThreeVectorList pPolygon,
const G4VoxelLimits pVoxelLimit,
const EAxis  pAxis,
G4double pMin,
G4double pMax 
) const
protectedinherited

Definition at line 489 of file G4VSolid.cc.

494{
495 G4int noLeft,i;
496 G4double component;
497
498 ClipPolygon(pPolygon,pVoxelLimit,pAxis);
499 noLeft = pPolygon.size();
500
501 if ( noLeft )
502 {
503 for (i=0; i<noLeft; ++i)
504 {
505 component = pPolygon[i].operator()(pAxis);
506
507 if (component < pMin)
508 {
509 pMin = component;
510 }
511 if (component > pMax)
512 {
513 pMax = component;
514 }
515 }
516 }
517}
void ClipPolygon(G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
Definition: G4VSolid.cc:539

References G4VSolid::ClipPolygon(), pMax, and pMin.

Referenced by G4VSolid::ClipBetweenSections(), and G4VSolid::ClipCrossSection().

◆ CalculateExtent()

G4bool G4GenericTrap::CalculateExtent ( const EAxis  pAxis,
const G4VoxelLimits pVoxelLimit,
const G4AffineTransform pTransform,
G4double pmin,
G4double pmax 
) const
virtual

Implements G4VSolid.

Definition at line 1200 of file G4GenericTrap.cc.

1204{
1205 G4ThreeVector bmin, bmax;
1206 G4bool exist;
1207
1208 // Check bounding box (bbox)
1209 //
1210 BoundingLimits(bmin,bmax);
1211 G4BoundingEnvelope bbox(bmin,bmax);
1212#ifdef G4BBOX_EXTENT
1213 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
1214#endif
1215 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
1216 {
1217 return exist = (pMin < pMax) ? true : false;
1218 }
1219
1220 // Set bounding envelope (benv) and calculate extent
1221 //
1222 // To build the bounding envelope with plane faces each side face of
1223 // the trapezoid is subdivided in triangles. Subdivision is done by
1224 // duplication of vertices in the bases in a way that the envelope be
1225 // a convex polyhedron (some faces of the envelope can be degenerate)
1226 //
1227 G4double dz = GetZHalfLength();
1228 G4ThreeVectorList baseA(8), baseB(8);
1229 for (G4int i=0; i<4; ++i)
1230 {
1231 G4TwoVector va = GetVertex(i);
1232 G4TwoVector vb = GetVertex(i+4);
1233 baseA[2*i].set(va.x(),va.y(),-dz);
1234 baseB[2*i].set(vb.x(),vb.y(), dz);
1235 }
1236 for (G4int i=0; i<4; ++i)
1237 {
1238 G4int k1=2*i, k2=(2*i+2)%8;
1239 G4double ax = (baseA[k2].x()-baseA[k1].x());
1240 G4double ay = (baseA[k2].y()-baseA[k1].y());
1241 G4double bx = (baseB[k2].x()-baseB[k1].x());
1242 G4double by = (baseB[k2].y()-baseB[k1].y());
1243 G4double znorm = ax*by - ay*bx;
1244 baseA[k1+1] = (znorm < 0.0) ? baseA[k2] : baseA[k1];
1245 baseB[k1+1] = (znorm < 0.0) ? baseB[k1] : baseB[k2];
1246 }
1247
1248 std::vector<const G4ThreeVectorList *> polygons(2);
1249 polygons[0] = &baseA;
1250 polygons[1] = &baseB;
1251
1252 G4BoundingEnvelope benv(bmin,bmax,polygons);
1253 exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
1254 return exist;
1255}
std::vector< G4ThreeVector > G4ThreeVectorList
bool G4bool
Definition: G4Types.hh:86
double x() const
double y() const
G4double GetZHalfLength() const
G4TwoVector GetVertex(G4int index) const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const

References G4BoundingEnvelope::BoundingBoxVsVoxelLimits(), BoundingLimits(), G4BoundingEnvelope::CalculateExtent(), GetVertex(), GetZHalfLength(), pMax, pMin, CLHEP::Hep2Vector::x(), and CLHEP::Hep2Vector::y().

◆ CheckOrder()

G4bool G4GenericTrap::CheckOrder ( const std::vector< G4TwoVector > &  vertices) const
private

Definition at line 1560 of file G4GenericTrap.cc.

1561{
1562 // Test if the vertices are in a clockwise order, if not reorder them.
1563 // Also test if they're well defined without crossing opposite segments
1564
1565 G4bool clockwise_order=true;
1566 G4double sum1 = 0.;
1567 G4double sum2 = 0.;
1568 G4int j;
1569
1570 for (G4int i=0; i<4; ++i)
1571 {
1572 j = (i+1)%4;
1573 sum1 += vertices[i].x()*vertices[j].y() - vertices[j].x()*vertices[i].y();
1574 sum2 += vertices[i+4].x()*vertices[j+4].y()
1575 - vertices[j+4].x()*vertices[i+4].y();
1576 }
1577 if (sum1*sum2 < -fgkTolerance)
1578 {
1579 std::ostringstream message;
1580 message << "Lower/upper faces defined with opposite clockwise - "
1581 << GetName();
1582 G4Exception("G4GenericTrap::CheckOrder()", "GeomSolids0002",
1583 FatalException, message);
1584 }
1585
1586 if ((sum1 > 0.)||(sum2 > 0.))
1587 {
1588 std::ostringstream message;
1589 message << "Vertices must be defined in clockwise XY planes - "
1590 << GetName();
1591 G4Exception("G4GenericTrap::CheckOrder()", "GeomSolids1001",
1592 JustWarning,message, "Re-ordering...");
1593 clockwise_order = false;
1594 }
1595
1596 // Check for illegal crossings
1597 //
1598 G4bool illegal_cross = false;
1599 illegal_cross = IsSegCrossingZ(vertices[0],vertices[4],
1600 vertices[1],vertices[5]);
1601
1602 if (!illegal_cross)
1603 {
1604 illegal_cross = IsSegCrossingZ(vertices[2],vertices[6],
1605 vertices[3],vertices[7]);
1606 }
1607 // +/- dZ planes
1608 if (!illegal_cross)
1609 {
1610 illegal_cross = IsSegCrossing(vertices[0],vertices[1],
1611 vertices[2],vertices[3]);
1612 }
1613 if (!illegal_cross)
1614 {
1615 illegal_cross = IsSegCrossing(vertices[0],vertices[3],
1616 vertices[1],vertices[2]);
1617 }
1618 if (!illegal_cross)
1619 {
1620 illegal_cross = IsSegCrossing(vertices[4],vertices[5],
1621 vertices[6],vertices[7]);
1622 }
1623 if (!illegal_cross)
1624 {
1625 illegal_cross = IsSegCrossing(vertices[4],vertices[7],
1626 vertices[5],vertices[6]);
1627 }
1628
1629 if (illegal_cross)
1630 {
1631 std::ostringstream message;
1632 message << "Malformed polygone with opposite sides - " << GetName();
1633 G4Exception("G4GenericTrap::CheckOrderAndSetup()",
1634 "GeomSolids0002", FatalException, message);
1635 }
1636 return clockwise_order;
1637}
@ FatalException
G4bool IsSegCrossingZ(const G4TwoVector &a, const G4TwoVector &b, const G4TwoVector &c, const G4TwoVector &d) const
static const G4double fgkTolerance
G4bool IsSegCrossing(const G4TwoVector &a, const G4TwoVector &b, const G4TwoVector &c, const G4TwoVector &d) const

References FatalException, fgkTolerance, G4Exception(), G4VSolid::GetName(), IsSegCrossing(), IsSegCrossingZ(), and JustWarning.

Referenced by G4GenericTrap().

◆ ClipBetweenSections()

void G4VSolid::ClipBetweenSections ( G4ThreeVectorList pVertices,
const G4int  pSectionIndex,
const G4VoxelLimits pVoxelLimit,
const EAxis  pAxis,
G4double pMin,
G4double pMax 
) const
protectedinherited

Definition at line 444 of file G4VSolid.cc.

449{
450 G4ThreeVectorList polygon;
451 polygon.reserve(4);
452 polygon.push_back((*pVertices)[pSectionIndex]);
453 polygon.push_back((*pVertices)[pSectionIndex+4]);
454 polygon.push_back((*pVertices)[pSectionIndex+5]);
455 polygon.push_back((*pVertices)[pSectionIndex+1]);
456 CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
457 polygon.clear();
458
459 polygon.push_back((*pVertices)[pSectionIndex+1]);
460 polygon.push_back((*pVertices)[pSectionIndex+5]);
461 polygon.push_back((*pVertices)[pSectionIndex+6]);
462 polygon.push_back((*pVertices)[pSectionIndex+2]);
463 CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
464 polygon.clear();
465
466 polygon.push_back((*pVertices)[pSectionIndex+2]);
467 polygon.push_back((*pVertices)[pSectionIndex+6]);
468 polygon.push_back((*pVertices)[pSectionIndex+7]);
469 polygon.push_back((*pVertices)[pSectionIndex+3]);
470 CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
471 polygon.clear();
472
473 polygon.push_back((*pVertices)[pSectionIndex+3]);
474 polygon.push_back((*pVertices)[pSectionIndex+7]);
475 polygon.push_back((*pVertices)[pSectionIndex+4]);
476 polygon.push_back((*pVertices)[pSectionIndex]);
477 CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
478 return;
479}
void CalculateClippedPolygonExtent(G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
Definition: G4VSolid.cc:489

References G4VSolid::CalculateClippedPolygonExtent(), pMax, and pMin.

◆ ClipCrossSection()

void G4VSolid::ClipCrossSection ( G4ThreeVectorList pVertices,
const G4int  pSectionIndex,
const G4VoxelLimits pVoxelLimit,
const EAxis  pAxis,
G4double pMin,
G4double pMax 
) const
protectedinherited

Definition at line 414 of file G4VSolid.cc.

419{
420
421 G4ThreeVectorList polygon;
422 polygon.reserve(4);
423 polygon.push_back((*pVertices)[pSectionIndex]);
424 polygon.push_back((*pVertices)[pSectionIndex+1]);
425 polygon.push_back((*pVertices)[pSectionIndex+2]);
426 polygon.push_back((*pVertices)[pSectionIndex+3]);
427 CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
428 return;
429}

References G4VSolid::CalculateClippedPolygonExtent(), pMax, and pMin.

◆ ClipPolygon()

void G4VSolid::ClipPolygon ( G4ThreeVectorList pPolygon,
const G4VoxelLimits pVoxelLimit,
const EAxis  pAxis 
) const
protectedinherited

Definition at line 539 of file G4VSolid.cc.

542{
543 G4ThreeVectorList outputPolygon;
544
545 if ( pVoxelLimit.IsLimited() )
546 {
547 if (pVoxelLimit.IsXLimited() ) // && pAxis != kXAxis)
548 {
549 G4VoxelLimits simpleLimit1;
550 simpleLimit1.AddLimit(kXAxis,pVoxelLimit.GetMinXExtent(),kInfinity);
551 ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
552
553 pPolygon.clear();
554
555 if ( !outputPolygon.size() ) return;
556
557 G4VoxelLimits simpleLimit2;
558 simpleLimit2.AddLimit(kXAxis,-kInfinity,pVoxelLimit.GetMaxXExtent());
559 ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
560
561 if ( !pPolygon.size() ) return;
562 else outputPolygon.clear();
563 }
564 if ( pVoxelLimit.IsYLimited() ) // && pAxis != kYAxis)
565 {
566 G4VoxelLimits simpleLimit1;
567 simpleLimit1.AddLimit(kYAxis,pVoxelLimit.GetMinYExtent(),kInfinity);
568 ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
569
570 // Must always clear pPolygon - for clip to simpleLimit2 and in case of
571 // early exit
572
573 pPolygon.clear();
574
575 if ( !outputPolygon.size() ) return;
576
577 G4VoxelLimits simpleLimit2;
578 simpleLimit2.AddLimit(kYAxis,-kInfinity,pVoxelLimit.GetMaxYExtent());
579 ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
580
581 if ( !pPolygon.size() ) return;
582 else outputPolygon.clear();
583 }
584 if ( pVoxelLimit.IsZLimited() ) // && pAxis != kZAxis)
585 {
586 G4VoxelLimits simpleLimit1;
587 simpleLimit1.AddLimit(kZAxis,pVoxelLimit.GetMinZExtent(),kInfinity);
588 ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
589
590 // Must always clear pPolygon - for clip to simpleLimit2 and in case of
591 // early exit
592
593 pPolygon.clear();
594
595 if ( !outputPolygon.size() ) return;
596
597 G4VoxelLimits simpleLimit2;
598 simpleLimit2.AddLimit(kZAxis,-kInfinity,pVoxelLimit.GetMaxZExtent());
599 ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
600
601 // Return after final clip - no cleanup
602 }
603 }
604}
void ClipPolygonToSimpleLimits(G4ThreeVectorList &pPolygon, G4ThreeVectorList &outputPolygon, const G4VoxelLimits &pVoxelLimit) const
Definition: G4VSolid.cc:612
G4bool IsYLimited() const
G4double GetMinZExtent() const
void AddLimit(const EAxis pAxis, const G4double pMin, const G4double pMax)
G4bool IsXLimited() const
G4double GetMaxYExtent() const
G4double GetMaxZExtent() const
G4double GetMinYExtent() const
G4double GetMinXExtent() const
G4bool IsZLimited() const
G4bool IsLimited() const
G4double GetMaxXExtent() const
@ kYAxis
Definition: geomdefs.hh:56
@ kXAxis
Definition: geomdefs.hh:55
@ kZAxis
Definition: geomdefs.hh:57
static const G4double kInfinity
Definition: geomdefs.hh:41

References G4VoxelLimits::AddLimit(), G4VSolid::ClipPolygonToSimpleLimits(), G4VoxelLimits::GetMaxXExtent(), G4VoxelLimits::GetMaxYExtent(), G4VoxelLimits::GetMaxZExtent(), G4VoxelLimits::GetMinXExtent(), G4VoxelLimits::GetMinYExtent(), G4VoxelLimits::GetMinZExtent(), G4VoxelLimits::IsLimited(), G4VoxelLimits::IsXLimited(), G4VoxelLimits::IsYLimited(), G4VoxelLimits::IsZLimited(), kInfinity, kXAxis, kYAxis, and kZAxis.

Referenced by G4VSolid::CalculateClippedPolygonExtent().

◆ ClipPolygonToSimpleLimits()

void G4VSolid::ClipPolygonToSimpleLimits ( G4ThreeVectorList pPolygon,
G4ThreeVectorList outputPolygon,
const G4VoxelLimits pVoxelLimit 
) const
privateinherited

Definition at line 612 of file G4VSolid.cc.

615{
616 G4int i;
617 G4int noVertices=pPolygon.size();
618 G4ThreeVector vEnd,vStart;
619
620 for (i = 0 ; i < noVertices ; ++i )
621 {
622 vStart = pPolygon[i];
623 if ( i == noVertices-1 ) vEnd = pPolygon[0];
624 else vEnd = pPolygon[i+1];
625
626 if ( pVoxelLimit.Inside(vStart) )
627 {
628 if (pVoxelLimit.Inside(vEnd))
629 {
630 // vStart and vEnd inside -> output end point
631 //
632 outputPolygon.push_back(vEnd);
633 }
634 else
635 {
636 // vStart inside, vEnd outside -> output crossing point
637 //
638 pVoxelLimit.ClipToLimits(vStart,vEnd);
639 outputPolygon.push_back(vEnd);
640 }
641 }
642 else
643 {
644 if (pVoxelLimit.Inside(vEnd))
645 {
646 // vStart outside, vEnd inside -> output inside section
647 //
648 pVoxelLimit.ClipToLimits(vStart,vEnd);
649 outputPolygon.push_back(vStart);
650 outputPolygon.push_back(vEnd);
651 }
652 else // Both point outside -> no output
653 {
654 // outputPolygon.push_back(vStart);
655 // outputPolygon.push_back(vEnd);
656 }
657 }
658 }
659}
G4bool ClipToLimits(G4ThreeVector &pStart, G4ThreeVector &pEnd) const
G4bool Inside(const G4ThreeVector &pVec) const

References G4VoxelLimits::ClipToLimits(), and G4VoxelLimits::Inside().

Referenced by G4VSolid::ClipPolygon().

◆ Clone()

G4VSolid * G4GenericTrap::Clone ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1266 of file G4GenericTrap.cc.

1267{
1268 return new G4GenericTrap(*this);
1269}
G4GenericTrap(const G4String &name, G4double halfZ, const std::vector< G4TwoVector > &vertices)

References G4GenericTrap().

◆ ComputeBBox()

void G4GenericTrap::ComputeBBox ( )
private

Definition at line 1959 of file G4GenericTrap.cc.

1960{
1961 // Computes bounding box for a shape.
1962
1963 G4double minX, maxX, minY, maxY;
1964 minX = maxX = fVertices[0].x();
1965 minY = maxY = fVertices[0].y();
1966
1967 for (G4int i=1; i< fgkNofVertices; i++)
1968 {
1969 if (minX>fVertices[i].x()) { minX=fVertices[i].x(); }
1970 if (maxX<fVertices[i].x()) { maxX=fVertices[i].x(); }
1971 if (minY>fVertices[i].y()) { minY=fVertices[i].y(); }
1972 if (maxY<fVertices[i].y()) { maxY=fVertices[i].y(); }
1973 }
1974 fMinBBoxVector = G4ThreeVector(minX,minY,-fDz);
1975 fMaxBBoxVector = G4ThreeVector(maxX,maxY, fDz);
1976}

References fDz, fgkNofVertices, fMaxBBoxVector, fMinBBoxVector, and fVertices.

Referenced by G4GenericTrap().

◆ ComputeDimensions()

void G4VSolid::ComputeDimensions ( G4VPVParameterisation p,
const G4int  n,
const G4VPhysicalVolume pRep 
)
virtualinherited

◆ ComputeIsTwisted()

G4bool G4GenericTrap::ComputeIsTwisted ( )
private

Definition at line 1512 of file G4GenericTrap.cc.

1513{
1514 // Computes tangents of twist angles (angles between projections on XY plane
1515 // of corresponding -dz +dz edges).
1516
1517 G4bool twisted = false;
1518 G4double dx1, dy1, dx2, dy2;
1519 G4int nv = fgkNofVertices/2;
1520
1521 for ( G4int i=0; i<4; ++i )
1522 {
1523 dx1 = fVertices[(i+1)%nv].x()-fVertices[i].x();
1524 dy1 = fVertices[(i+1)%nv].y()-fVertices[i].y();
1525 if ( (dx1 == 0) && (dy1 == 0) ) { continue; }
1526
1527 dx2 = fVertices[nv+(i+1)%nv].x()-fVertices[nv+i].x();
1528 dy2 = fVertices[nv+(i+1)%nv].y()-fVertices[nv+i].y();
1529
1530 if ( dx2 == 0 && dy2 == 0 ) { continue; }
1531 G4double twist_angle = std::fabs(dy1*dx2 - dx1*dy2);
1532 if ( twist_angle < fgkTolerance ) { continue; }
1533 twisted = true;
1534 SetTwistAngle(i,twist_angle);
1535
1536 // Check on big angles, potentially navigation problem
1537
1538 twist_angle = std::acos( (dx1*dx2 + dy1*dy2)
1539 / (std::sqrt(dx1*dx1+dy1*dy1)
1540 * std::sqrt(dx2*dx2+dy2*dy2)) );
1541
1542 if ( std::fabs(twist_angle) > 0.5*pi+kCarTolerance )
1543 {
1544 std::ostringstream message;
1545 message << "Twisted Angle is bigger than 90 degrees - " << GetName()
1546 << G4endl
1547 << " Potential problem of malformed Solid !" << G4endl
1548 << " TwistANGLE = " << twist_angle
1549 << "*rad for lateral plane N= " << i;
1550 G4Exception("G4GenericTrap::ComputeIsTwisted()", "GeomSolids1002",
1551 JustWarning, message);
1552 }
1553 }
1554
1555 return twisted;
1556}
static constexpr double pi
Definition: G4SIunits.hh:55
void SetTwistAngle(G4int index, G4double twist)

References fgkNofVertices, fgkTolerance, fVertices, G4endl, G4Exception(), G4VSolid::GetName(), JustWarning, G4VSolid::kCarTolerance, pi, and SetTwistAngle().

Referenced by G4GenericTrap().

◆ CreatePolyhedron()

G4Polyhedron * G4GenericTrap::CreatePolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 2041 of file G4GenericTrap.cc.

2042{
2043
2044#ifdef G4TESS_TEST
2045 if ( fTessellatedSolid != nullptr )
2046 {
2048 }
2049#endif
2050
2051 // Approximation of Twisted Side
2052 // Construct extra Points, if Twisted Side
2053 //
2054 G4PolyhedronArbitrary* polyhedron;
2055 size_t nVertices, nFacets;
2056
2057 G4int subdivisions=0;
2058 G4int i;
2059 if(fIsTwisted)
2060 {
2061 if ( GetVisSubdivisions()!= 0 )
2062 {
2063 subdivisions=GetVisSubdivisions();
2064 }
2065 else
2066 {
2067 // Estimation of Number of Subdivisions for smooth visualisation
2068 //
2069 G4double maxTwist=0.;
2070 for(i=0; i<4; ++i)
2071 {
2072 if(GetTwistAngle(i)>maxTwist) { maxTwist=GetTwistAngle(i); }
2073 }
2074
2075 // Computes bounding vectors for the shape
2076 //
2077 G4double Dx,Dy;
2078 G4ThreeVector minVec = GetMinimumBBox();
2079 G4ThreeVector maxVec = GetMaximumBBox();
2080 Dx = 0.5*(maxVec.x()- minVec.y());
2081 Dy = 0.5*(maxVec.y()- minVec.y());
2082 if (Dy > Dx) { Dx=Dy; }
2083
2084 subdivisions=8*G4int(maxTwist/(Dx*Dx*Dx)*fDz);
2085 if (subdivisions<4) { subdivisions=4; }
2086 if (subdivisions>30) { subdivisions=30; }
2087 }
2088 }
2089 G4int sub4=4*subdivisions;
2090 nVertices = 8+subdivisions*4;
2091 nFacets = 6+subdivisions*4;
2092 G4double cf=1./(subdivisions+1);
2093 polyhedron = new G4PolyhedronArbitrary (nVertices, nFacets);
2094
2095 // Add Vertex
2096 //
2097 for (i=0; i<4; ++i)
2098 {
2099 polyhedron->AddVertex(G4ThreeVector(fVertices[i].x(),
2100 fVertices[i].y(),-fDz));
2101 }
2102 for( i=0; i<subdivisions; ++i)
2103 {
2104 for(G4int j=0;j<4;j++)
2105 {
2106 G4TwoVector u=fVertices[j]+cf*(i+1)*( fVertices[j+4]-fVertices[j]);
2107 polyhedron->AddVertex(G4ThreeVector(u.x(),u.y(),-fDz+cf*2*fDz*(i+1)));
2108 }
2109 }
2110 for (i=4; i<8; ++i)
2111 {
2112 polyhedron->AddVertex(G4ThreeVector(fVertices[i].x(),
2113 fVertices[i].y(),fDz));
2114 }
2115
2116 // Add Facets
2117 //
2118 polyhedron->AddFacet(1,4,3,2); //Z-plane
2119 for (i=0; i<subdivisions+1; ++i)
2120 {
2121 G4int is=i*4;
2122 polyhedron->AddFacet(5+is,8+is,4+is,1+is);
2123 polyhedron->AddFacet(8+is,7+is,3+is,4+is);
2124 polyhedron->AddFacet(7+is,6+is,2+is,3+is);
2125 polyhedron->AddFacet(6+is,5+is,1+is,2+is);
2126 }
2127 polyhedron->AddFacet(5+sub4,6+sub4,7+sub4,8+sub4); //Z-plane
2128
2129 polyhedron->SetReferences();
2130 polyhedron->InvertFacets();
2131
2132 return (G4Polyhedron*) polyhedron;
2133}
double x() const
double y() const
G4double GetTwistAngle(G4int index) const
G4int GetVisSubdivisions() const
void AddFacet(const G4int iv1, const G4int iv2, const G4int iv3, const G4int iv4=0)
void AddVertex(const G4ThreeVector &v)
virtual G4Polyhedron * CreatePolyhedron() const

References G4PolyhedronArbitrary::AddFacet(), G4PolyhedronArbitrary::AddVertex(), G4TessellatedSolid::CreatePolyhedron(), fDz, fIsTwisted, fTessellatedSolid, fVertices, GetMaximumBBox(), GetMinimumBBox(), GetTwistAngle(), GetVisSubdivisions(), G4PolyhedronArbitrary::InvertFacets(), G4PolyhedronArbitrary::SetReferences(), CLHEP::Hep3Vector::x(), CLHEP::Hep2Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep2Vector::y().

Referenced by GetPolyhedron().

◆ CreateTessellatedSolid()

G4TessellatedSolid * G4GenericTrap::CreateTessellatedSolid ( ) const
private

Definition at line 1898 of file G4GenericTrap.cc.

1899{
1900 // 3D vertices
1901 //
1902 G4int nv = fgkNofVertices/2;
1903 std::vector<G4ThreeVector> downVertices;
1904 for ( G4int i=0; i<nv; ++i )
1905 {
1906 downVertices.push_back(G4ThreeVector(fVertices[i].x(),
1907 fVertices[i].y(), -fDz));
1908 }
1909
1910 std::vector<G4ThreeVector> upVertices;
1911 for ( G4int i=nv; i<2*nv; ++i )
1912 {
1913 upVertices.push_back(G4ThreeVector(fVertices[i].x(),
1914 fVertices[i].y(), fDz));
1915 }
1916
1917 // Reorder vertices if they are not ordered anti-clock wise
1918 //
1919 G4ThreeVector cross
1920 = (downVertices[1]-downVertices[0]).cross(downVertices[2]-downVertices[1]);
1921 G4ThreeVector cross1
1922 = (upVertices[1]-upVertices[0]).cross(upVertices[2]-upVertices[1]);
1923 if ( (cross.z() > 0.0) || (cross1.z() > 0.0) )
1924 {
1925 ReorderVertices(downVertices);
1926 ReorderVertices(upVertices);
1927 }
1928
1929 G4TessellatedSolid* tessellatedSolid = new G4TessellatedSolid(GetName());
1930
1931 G4VFacet* facet = 0;
1932 facet = MakeDownFacet(downVertices, 0, 1, 2);
1933 if (facet) { tessellatedSolid->AddFacet( facet ); }
1934 facet = MakeDownFacet(downVertices, 0, 2, 3);
1935 if (facet) { tessellatedSolid->AddFacet( facet ); }
1936 facet = MakeUpFacet(upVertices, 0, 2, 1);
1937 if (facet) { tessellatedSolid->AddFacet( facet ); }
1938 facet = MakeUpFacet(upVertices, 0, 3, 2);
1939 if (facet) { tessellatedSolid->AddFacet( facet ); }
1940
1941 // The quadrangular sides
1942 //
1943 for ( G4int i = 0; i < nv; ++i )
1944 {
1945 G4int j = (i+1) % nv;
1946 facet = MakeSideFacet(downVertices[j], downVertices[i],
1947 upVertices[i], upVertices[j]);
1948
1949 if ( facet ) { tessellatedSolid->AddFacet( facet ); }
1950 }
1951
1952 tessellatedSolid->SetSolidClosed(true);
1953
1954 return tessellatedSolid;
1955}
double z() const
G4VFacet * MakeUpFacet(const std::vector< G4ThreeVector > &fromVertices, G4int ind1, G4int ind2, G4int ind3) const
G4VFacet * MakeDownFacet(const std::vector< G4ThreeVector > &fromVertices, G4int ind1, G4int ind2, G4int ind3) const
void ReorderVertices(std::vector< G4ThreeVector > &vertices) const
G4VFacet * MakeSideFacet(const G4ThreeVector &downVertex0, const G4ThreeVector &downVertex1, const G4ThreeVector &upVertex1, const G4ThreeVector &upVertex0) const
G4bool AddFacet(G4VFacet *aFacet)
void SetSolidClosed(const G4bool t)

References G4TessellatedSolid::AddFacet(), fDz, fgkNofVertices, fVertices, G4VSolid::GetName(), MakeDownFacet(), MakeSideFacet(), MakeUpFacet(), ReorderVertices(), G4TessellatedSolid::SetSolidClosed(), and CLHEP::Hep3Vector::z().

Referenced by G4GenericTrap(), and operator=().

◆ DescribeYourselfTo()

void G4GenericTrap::DescribeYourselfTo ( G4VGraphicsScene scene) const
virtual

Implements G4VSolid.

Definition at line 2006 of file G4GenericTrap.cc.

2007{
2008
2009#ifdef G4TESS_TEST
2010 if ( fTessellatedSolid )
2011 {
2013 }
2014#endif
2015
2016 scene.AddSolid(*this);
2017}
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const
virtual void AddSolid(const G4Box &)=0

References G4VGraphicsScene::AddSolid(), G4TessellatedSolid::DescribeYourselfTo(), and fTessellatedSolid.

◆ DistanceToIn() [1/2]

G4double G4GenericTrap::DistanceToIn ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 800 of file G4GenericTrap.cc.

801{
802 // Computes the closest distance from given point to this shape
803
804#ifdef G4TESS_TEST
805 if ( fTessellatedSolid )
806 {
808 }
809#endif
810
811 G4double safz = std::fabs(p.z())-fDz;
812 if(safz<0) { safz=0; }
813
814 G4int iseg;
815 G4double safe = safz;
816 G4double safxy = safz;
817
818 for (iseg=0; iseg<4; ++iseg)
819 {
820 safxy = SafetyToFace(p,iseg);
821 if (safxy>safe) { safe=safxy; }
822 }
823
824 return safe;
825}
G4double SafetyToFace(const G4ThreeVector &p, const G4int iseg) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const

References G4TessellatedSolid::DistanceToIn(), fDz, fTessellatedSolid, SafetyToFace(), and CLHEP::Hep3Vector::z().

◆ DistanceToIn() [2/2]

G4double G4GenericTrap::DistanceToIn ( const G4ThreeVector p,
const G4ThreeVector v 
) const
virtual

Implements G4VSolid.

Definition at line 732 of file G4GenericTrap.cc.

734{
735#ifdef G4TESS_TEST
736 if ( fTessellatedSolid )
737 {
738 return fTessellatedSolid->DistanceToIn(p, v);
739 }
740#endif
741
742 G4double dist[5];
744
745 // Check lateral faces
746 //
747 G4int i;
748 for (i=0; i<4; ++i)
749 {
750 dist[i]=DistToPlane(p, v, i);
751 }
752
753 // Check Z planes
754 //
755 dist[4]=kInfinity;
756 if (std::fabs(p.z())>fDz-halfCarTolerance)
757 {
758 if (v.z())
759 {
760 G4ThreeVector pt;
761 if (p.z()>0)
762 {
763 dist[4] = (fDz-p.z())/v.z();
764 }
765 else
766 {
767 dist[4] = (-fDz-p.z())/v.z();
768 }
769 if (dist[4]<-halfCarTolerance)
770 {
771 dist[4]=kInfinity;
772 }
773 else
774 {
775 if(dist[4]<halfCarTolerance)
776 {
777 if(p.z()>0) { n=G4ThreeVector(0,0,1); }
778 else { n=G4ThreeVector(0,0,-1); }
779 if (n.dot(v)<0) { dist[4]=0.; }
780 else { dist[4]=kInfinity; }
781 }
782 pt=p+dist[4]*v;
783 if (Inside(pt)==kOutside) { dist[4]=kInfinity; }
784 }
785 }
786 }
787 G4double distmin = dist[0];
788 for (i=1; i<5 ; ++i)
789 {
790 if (dist[i] < distmin) { distmin = dist[i]; }
791 }
792
793 if (distmin<halfCarTolerance) { distmin=0.; }
794
795 return distmin;
796}
EInside Inside(const G4ThreeVector &p) const
G4double DistToPlane(const G4ThreeVector &p, const G4ThreeVector &v, const G4int ipl) const
@ kOutside
Definition: geomdefs.hh:68

References G4TessellatedSolid::DistanceToIn(), DistToPlane(), fDz, fTessellatedSolid, halfCarTolerance, Inside(), kInfinity, kOutside, CLHEP::detail::n, and CLHEP::Hep3Vector::z().

◆ DistanceToOut() [1/2]

G4double G4GenericTrap::DistanceToOut ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 1149 of file G4GenericTrap.cc.

1150{
1151
1152#ifdef G4TESS_TEST
1153 if ( fTessellatedSolid )
1154 {
1156 }
1157#endif
1158
1159 G4double safz = fDz-std::fabs(p.z());
1160 if (safz<0) { safz = 0; }
1161
1162 G4double safe = safz;
1163 G4double safxy = safz;
1164
1165 for (G4int iseg=0; iseg<4; ++iseg)
1166 {
1167 safxy = std::fabs(SafetyToFace(p,iseg));
1168 if (safxy < safe) { safe = safxy; }
1169 }
1170
1171 return safe;
1172}
virtual G4double DistanceToOut(const G4ThreeVector &p) const

References G4TessellatedSolid::DistanceToOut(), fDz, fTessellatedSolid, SafetyToFace(), and CLHEP::Hep3Vector::z().

◆ DistanceToOut() [2/2]

G4double G4GenericTrap::DistanceToOut ( const G4ThreeVector p,
const G4ThreeVector v,
const G4bool  calcNorm = false,
G4bool validNorm = nullptr,
G4ThreeVector n = nullptr 
) const
virtual

Implements G4VSolid.

Definition at line 904 of file G4GenericTrap.cc.

909{
910#ifdef G4TESS_TEST
911 if ( fTessellatedSolid )
912 {
913 return fTessellatedSolid->DistanceToOut(p, v, calcNorm, validNorm, n);
914 }
915#endif
916
917 G4double distmin;
918 G4bool lateral_cross = false;
919 ESide side = kUndef;
920
921 if (calcNorm) { *validNorm = true; } // All normals are valid
922
923 if (v.z() < 0)
924 {
925 distmin=(-fDz-p.z())/v.z();
926 if (calcNorm) { side=kMZ; *n=G4ThreeVector(0,0,-1); }
927 }
928 else
929 {
930 if (v.z() > 0)
931 {
932 distmin = (fDz-p.z())/v.z();
933 if (calcNorm) { side=kPZ; *n=G4ThreeVector(0,0,1); }
934 }
935 else { distmin = kInfinity; }
936 }
937
938 G4double dz2 =0.5/fDz;
939 G4double xa,xb,xc,xd;
940 G4double ya,yb,yc,yd;
941
942 for (G4int ipl=0; ipl<4; ++ipl)
943 {
944 G4int j = (ipl+1)%4;
945 xa=fVertices[ipl].x();
946 ya=fVertices[ipl].y();
947 xb=fVertices[ipl+4].x();
948 yb=fVertices[ipl+4].y();
949 xc=fVertices[j].x();
950 yc=fVertices[j].y();
951 xd=fVertices[4+j].x();
952 yd=fVertices[4+j].y();
953
954 if ( ((std::fabs(xb-xd)+std::fabs(yb-yd))<halfCarTolerance)
955 || ((std::fabs(xa-xc)+std::fabs(ya-yc))<halfCarTolerance) )
956 {
957 G4double q=DistToTriangle(p,v,ipl) ;
958 if ( (q>=0) && (q<distmin) )
959 {
960 distmin=q;
961 lateral_cross=true;
962 side=ESide(ipl+1);
963 }
964 continue;
965 }
966 G4double tx1 =dz2*(xb-xa);
967 G4double ty1 =dz2*(yb-ya);
968 G4double tx2 =dz2*(xd-xc);
969 G4double ty2 =dz2*(yd-yc);
970 G4double dzp =fDz+p.z();
971 G4double xs1 =xa+tx1*dzp;
972 G4double ys1 =ya+ty1*dzp;
973 G4double xs2 =xc+tx2*dzp;
974 G4double ys2 =yc+ty2*dzp;
975 G4double dxs =xs2-xs1;
976 G4double dys =ys2-ys1;
977 G4double dtx =tx2-tx1;
978 G4double dty =ty2-ty1;
979 G4double a = (dtx*v.y()-dty*v.x()+(tx1*ty2-tx2*ty1)*v.z())*v.z();
980 G4double b = dxs*v.y()-dys*v.x()+(dtx*p.y()-dty*p.x()+ty2*xs1-ty1*xs2
981 + tx1*ys2-tx2*ys1)*v.z();
982 G4double c=dxs*p.y()-dys*p.x()+xs1*ys2-xs2*ys1;
984
985 if (std::fabs(a) < kCarTolerance)
986 {
987 if (std::fabs(b) < kCarTolerance) { continue; }
988 q=-c/b;
989
990 // Check for Point on the Surface
991 //
992 if ((q > -halfCarTolerance) && (q < distmin))
993 {
994 if (q < halfCarTolerance)
995 {
996 if (NormalToPlane(p,ipl).dot(v)<0.) { continue; }
997 }
998 distmin =q;
999 lateral_cross=true;
1000 side=ESide(ipl+1);
1001 }
1002 continue;
1003 }
1004 G4double d=b*b-4*a*c;
1005 if (d >= 0.)
1006 {
1007 if (a > 0) { q=0.5*(-b-std::sqrt(d))/a; }
1008 else { q=0.5*(-b+std::sqrt(d))/a; }
1009
1010 // Check for Point on the Surface
1011 //
1012 if (q > -halfCarTolerance )
1013 {
1014 if (q < distmin)
1015 {
1016 if(q < halfCarTolerance)
1017 {
1018 if (NormalToPlane(p,ipl).dot(v)<0.) // Check second root
1019 {
1020 if (a > 0) { q=0.5*(-b+std::sqrt(d))/a; }
1021 else { q=0.5*(-b-std::sqrt(d))/a; }
1022 if (( q > halfCarTolerance) && (q < distmin))
1023 {
1024 distmin=q;
1025 lateral_cross = true;
1026 side=ESide(ipl+1);
1027 }
1028 continue;
1029 }
1030 }
1031 distmin = q;
1032 lateral_cross = true;
1033 side=ESide(ipl+1);
1034 }
1035 }
1036 else
1037 {
1038 if (a > 0) { q=0.5*(-b+std::sqrt(d))/a; }
1039 else { q=0.5*(-b-std::sqrt(d))/a; }
1040
1041 // Check for Point on the Surface
1042 //
1043 if ((q > -halfCarTolerance) && (q < distmin))
1044 {
1045 if (q < halfCarTolerance)
1046 {
1047 if (NormalToPlane(p,ipl).dot(v)<0.) // Check second root
1048 {
1049 if (a > 0) { q=0.5*(-b-std::sqrt(d))/a; }
1050 else { q=0.5*(-b+std::sqrt(d))/a; }
1051 if ( ( q > halfCarTolerance) && (q < distmin) )
1052 {
1053 distmin=q;
1054 lateral_cross = true;
1055 side=ESide(ipl+1);
1056 }
1057 continue;
1058 }
1059 }
1060 distmin =q;
1061 lateral_cross = true;
1062 side=ESide(ipl+1);
1063 }
1064 }
1065 }
1066 }
1067 if (!lateral_cross) // Make sure that track crosses the top or bottom
1068 {
1069 if (distmin >= kInfinity) { distmin=kCarTolerance; }
1070 G4ThreeVector pt=p+distmin*v;
1071
1072 // Check if propagated point is in the polygon
1073 //
1074 G4int i=0;
1075 if (v.z()>0.) { i=4; }
1076 std::vector<G4TwoVector> xy;
1077 for ( G4int j=0; j<4; j++) { xy.push_back(fVertices[i+j]); }
1078
1079 // Check Inside
1080 //
1081 if (InsidePolygone(pt,xy)==kOutside)
1082 {
1083 if(calcNorm)
1084 {
1085 if (v.z()>0) {side= kPZ; *n = G4ThreeVector(0,0,1);}
1086 else { side=kMZ; *n = G4ThreeVector(0,0,-1);}
1087 }
1088 return 0.;
1089 }
1090 else
1091 {
1092 if(v.z()>0) {side=kPZ;}
1093 else {side=kMZ;}
1094 }
1095 }
1096
1097 if (calcNorm)
1098 {
1099 G4ThreeVector pt=p+v*distmin;
1100 switch (side)
1101 {
1102 case kXY0:
1103 *n=NormalToPlane(pt,0);
1104 break;
1105 case kXY1:
1106 *n=NormalToPlane(pt,1);
1107 break;
1108 case kXY2:
1109 *n=NormalToPlane(pt,2);
1110 break;
1111 case kXY3:
1112 *n=NormalToPlane(pt,3);
1113 break;
1114 case kPZ:
1115 *n=G4ThreeVector(0,0,1);
1116 break;
1117 case kMZ:
1118 *n=G4ThreeVector(0,0,-1);
1119 break;
1120 default:
1121 DumpInfo();
1122 std::ostringstream message;
1123 G4int oldprc = message.precision(16);
1124 message << "Undefined side for valid surface normal to solid." << G4endl
1125 << "Position:" << G4endl
1126 << " p.x() = " << p.x()/mm << " mm" << G4endl
1127 << " p.y() = " << p.y()/mm << " mm" << G4endl
1128 << " p.z() = " << p.z()/mm << " mm" << G4endl
1129 << "Direction:" << G4endl
1130 << " v.x() = " << v.x() << G4endl
1131 << " v.y() = " << v.y() << G4endl
1132 << " v.z() = " << v.z() << G4endl
1133 << "Proposed distance :" << G4endl
1134 << " distmin = " << distmin/mm << " mm";
1135 message.precision(oldprc);
1136 G4Exception("G4GenericTrap::DistanceToOut(p,v,..)",
1137 "GeomSolids1002", JustWarning, message);
1138 break;
1139 }
1140 }
1141
1142 if (distmin<halfCarTolerance) { distmin=0.; }
1143
1144 return distmin;
1145}
ESide
Definition: G4Cons.cc:61
static constexpr double mm
Definition: G4SIunits.hh:95
double dot(const Hep3Vector &) const
EInside InsidePolygone(const G4ThreeVector &p, const std::vector< G4TwoVector > &poly) const
G4double DistToTriangle(const G4ThreeVector &p, const G4ThreeVector &v, const G4int ipl) const
G4ThreeVector NormalToPlane(const G4ThreeVector &p, const G4int ipl) const

References G4TessellatedSolid::DistanceToOut(), DistToTriangle(), CLHEP::Hep3Vector::dot(), G4VSolid::DumpInfo(), fDz, fTessellatedSolid, fVertices, G4endl, G4Exception(), halfCarTolerance, InsidePolygone(), JustWarning, G4VSolid::kCarTolerance, kInfinity, kMZ, kOutside, kPZ, kUndef, kXY0, kXY1, kXY2, kXY3, mm, CLHEP::detail::n, NormalToPlane(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

◆ DistToPlane()

G4double G4GenericTrap::DistToPlane ( const G4ThreeVector p,
const G4ThreeVector v,
const G4int  ipl 
) const
private

Definition at line 574 of file G4GenericTrap.cc.

577{
578 // Computes distance to plane ipl :
579 // ipl=0 : points 0,4,1,5
580 // ipl=1 : points 1,5,2,6
581 // ipl=2 : points 2,6,3,7
582 // ipl=3 : points 3,7,0,4
583
584 G4double xa,xb,xc,xd,ya,yb,yc,yd;
585
586 G4int j = (ipl+1)%4;
587
588 xa=fVertices[ipl].x();
589 ya=fVertices[ipl].y();
590 xb=fVertices[ipl+4].x();
591 yb=fVertices[ipl+4].y();
592 xc=fVertices[j].x();
593 yc=fVertices[j].y();
594 xd=fVertices[4+j].x();
595 yd=fVertices[4+j].y();
596
597 G4double dz2 =0.5/fDz;
598 G4double tx1 =dz2*(xb-xa);
599 G4double ty1 =dz2*(yb-ya);
600 G4double tx2 =dz2*(xd-xc);
601 G4double ty2 =dz2*(yd-yc);
602 G4double dzp =fDz+p.z();
603 G4double xs1 =xa+tx1*dzp;
604 G4double ys1 =ya+ty1*dzp;
605 G4double xs2 =xc+tx2*dzp;
606 G4double ys2 =yc+ty2*dzp;
607 G4double dxs =xs2-xs1;
608 G4double dys =ys2-ys1;
609 G4double dtx =tx2-tx1;
610 G4double dty =ty2-ty1;
611
612 G4double a = (dtx*v.y()-dty*v.x()+(tx1*ty2-tx2*ty1)*v.z())*v.z();
613 G4double b = dxs*v.y()-dys*v.x()+(dtx*p.y()-dty*p.x()+ty2*xs1-ty1*xs2
614 + tx1*ys2-tx2*ys1)*v.z();
615 G4double c=dxs*p.y()-dys*p.x()+xs1*ys2-xs2*ys1;
617 G4double x1,x2,y1,y2,xp,yp,zi;
618
619 if (std::fabs(a)<kCarTolerance)
620 {
621 if (std::fabs(b)<kCarTolerance) { return kInfinity; }
622 q=-c/b;
623
624 // Check if Point is on the Surface
625
626 if (q>-halfCarTolerance)
627 {
628 if (q<halfCarTolerance)
629 {
630 if (NormalToPlane(p,ipl).dot(v)<=0)
631 { if(Inside(p) != kOutside) { return 0.; } }
632 else
633 { return kInfinity; }
634 }
635
636 // Check the Intersection
637 //
638 zi=p.z()+q*v.z();
639 if (std::fabs(zi)<fDz)
640 {
641 x1=xs1+tx1*v.z()*q;
642 x2=xs2+tx2*v.z()*q;
643 xp=p.x()+q*v.x();
644 y1=ys1+ty1*v.z()*q;
645 y2=ys2+ty2*v.z()*q;
646 yp=p.y()+q*v.y();
647 zi = (xp-x1)*(xp-x2)+(yp-y1)*(yp-y2);
648 if (zi<=halfCarTolerance) { return q; }
649 }
650 }
651 return kInfinity;
652 }
653 G4double d=b*b-4*a*c;
654 if (d>=0)
655 {
656 if (a>0) { q=0.5*(-b-std::sqrt(d))/a; }
657 else { q=0.5*(-b+std::sqrt(d))/a; }
658
659 // Check if Point is on the Surface
660 //
661 if (q>-halfCarTolerance)
662 {
663 if(q<halfCarTolerance)
664 {
665 if (NormalToPlane(p,ipl).dot(v)<=0)
666 {
667 if(Inside(p)!= kOutside) { return 0.; }
668 }
669 else // Check second root; return kInfinity
670 {
671 if (a>0) { q=0.5*(-b+std::sqrt(d))/a; }
672 else { q=0.5*(-b-std::sqrt(d))/a; }
673 if (q<=halfCarTolerance) { return kInfinity; }
674 }
675 }
676 // Check the Intersection
677 //
678 zi=p.z()+q*v.z();
679 if (std::fabs(zi)<fDz)
680 {
681 x1=xs1+tx1*v.z()*q;
682 x2=xs2+tx2*v.z()*q;
683 xp=p.x()+q*v.x();
684 y1=ys1+ty1*v.z()*q;
685 y2=ys2+ty2*v.z()*q;
686 yp=p.y()+q*v.y();
687 zi = (xp-x1)*(xp-x2)+(yp-y1)*(yp-y2);
688 if (zi<=halfCarTolerance) { return q; }
689 }
690 }
691 if (a>0) { q=0.5*(-b+std::sqrt(d))/a; }
692 else { q=0.5*(-b-std::sqrt(d))/a; }
693
694 // Check if Point is on the Surface
695 //
696 if (q>-halfCarTolerance)
697 {
698 if(q<halfCarTolerance)
699 {
700 if (NormalToPlane(p,ipl).dot(v)<=0)
701 {
702 if(Inside(p) != kOutside) { return 0.; }
703 }
704 else // Check second root; return kInfinity.
705 {
706 if (a>0) { q=0.5*(-b-std::sqrt(d))/a; }
707 else { q=0.5*(-b+std::sqrt(d))/a; }
708 if (q<=halfCarTolerance) { return kInfinity; }
709 }
710 }
711 // Check the Intersection
712 //
713 zi=p.z()+q*v.z();
714 if (std::fabs(zi)<fDz)
715 {
716 x1=xs1+tx1*v.z()*q;
717 x2=xs2+tx2*v.z()*q;
718 xp=p.x()+q*v.x();
719 y1=ys1+ty1*v.z()*q;
720 y2=ys2+ty2*v.z()*q;
721 yp=p.y()+q*v.y();
722 zi = (xp-x1)*(xp-x2)+(yp-y1)*(yp-y2);
723 if (zi<=halfCarTolerance) { return q; }
724 }
725 }
726 }
727 return kInfinity;
728}

References CLHEP::Hep3Vector::dot(), fDz, fVertices, halfCarTolerance, Inside(), G4VSolid::kCarTolerance, kInfinity, kOutside, NormalToPlane(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by DistanceToIn().

◆ DistToTriangle()

G4double G4GenericTrap::DistToTriangle ( const G4ThreeVector p,
const G4ThreeVector v,
const G4int  ipl 
) const
private

Definition at line 849 of file G4GenericTrap.cc.

851{
852 G4double xa=fVertices[ipl].x();
853 G4double ya=fVertices[ipl].y();
854 G4double xb=fVertices[ipl+4].x();
855 G4double yb=fVertices[ipl+4].y();
856 G4int j=(ipl+1)%4;
857 G4double xc=fVertices[j].x();
858 G4double yc=fVertices[j].y();
859 G4double zab=2*fDz;
860 G4double zac=0;
861
862 if ( (std::fabs(xa-xc)+std::fabs(ya-yc)) < halfCarTolerance )
863 {
864 xc=fVertices[j+4].x();
865 yc=fVertices[j+4].y();
866 zac=2*fDz;
867 zab=2*fDz;
868
869 //Line case
870 //
871 if ( (std::fabs(xb-xc)+std::fabs(yb-yc)) < halfCarTolerance )
872 {
873 return kInfinity;
874 }
875 }
876 G4double a=(yb-ya)*zac-(yc-ya)*zab;
877 G4double b=(xc-xa)*zab-(xb-xa)*zac;
878 G4double c=(xb-xa)*(yc-ya)-(xc-xa)*(yb-ya);
879 G4double d=-xa*a-ya*b+fDz*c;
880 G4double t=a*v.x()+b*v.y()+c*v.z();
881
882 if (t!=0)
883 {
884 t=-(a*p.x()+b*p.y()+c*p.z()+d)/t;
885 }
886 if ( (t<halfCarTolerance) && (t>-halfCarTolerance) )
887 {
888 if (NormalToPlane(p,ipl).dot(v)<kCarTolerance)
889 {
890 t=kInfinity;
891 }
892 else
893 {
894 t=0;
895 }
896 }
897 if (Inside(p+v*t) != kSurface) { t=kInfinity; }
898
899 return t;
900}
@ kSurface
Definition: geomdefs.hh:69

References CLHEP::Hep3Vector::dot(), fDz, fVertices, halfCarTolerance, Inside(), G4VSolid::kCarTolerance, kInfinity, kSurface, NormalToPlane(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by DistanceToOut().

◆ DumpInfo()

void G4VSolid::DumpInfo ( ) const
inlineinherited

Referenced by G4Cons::ApproxSurfaceNormal(), G4CutTubs::ApproxSurfaceNormal(), G4Sphere::ApproxSurfaceNormal(), G4Torus::ApproxSurfaceNormal(), G4Tubs::ApproxSurfaceNormal(), G4ReflectedSolid::BoundingLimits(), G4DisplacedSolid::BoundingLimits(), G4IntersectionSolid::BoundingLimits(), G4ScaledSolid::BoundingLimits(), G4SubtractionSolid::BoundingLimits(), G4UnionSolid::BoundingLimits(), G4Box::BoundingLimits(), G4Cons::BoundingLimits(), G4CutTubs::BoundingLimits(), G4Orb::BoundingLimits(), G4Para::BoundingLimits(), G4Sphere::BoundingLimits(), G4Torus::BoundingLimits(), G4Trap::BoundingLimits(), G4Trd::BoundingLimits(), G4Tubs::BoundingLimits(), G4EllipticalCone::BoundingLimits(), G4ExtrudedSolid::BoundingLimits(), G4GenericPolycone::BoundingLimits(), BoundingLimits(), G4Hype::BoundingLimits(), G4Paraboloid::BoundingLimits(), G4Polycone::BoundingLimits(), G4Polyhedra::BoundingLimits(), G4TessellatedSolid::BoundingLimits(), G4TwistedTubs::BoundingLimits(), G4ParameterisationBoxX::ComputeDimensions(), G4ParameterisationBoxY::ComputeDimensions(), G4ParameterisationBoxZ::ComputeDimensions(), G4ParameterisationConsRho::ComputeDimensions(), G4ParameterisationConsPhi::ComputeDimensions(), G4ParameterisationConsZ::ComputeDimensions(), G4ParameterisationParaX::ComputeDimensions(), G4ParameterisationParaY::ComputeDimensions(), G4ParameterisationParaZ::ComputeDimensions(), G4ParameterisationPolyconeRho::ComputeDimensions(), G4ParameterisationPolyconePhi::ComputeDimensions(), G4ParameterisationPolyconeZ::ComputeDimensions(), G4ParameterisationPolyhedraRho::ComputeDimensions(), G4ParameterisationPolyhedraPhi::ComputeDimensions(), G4ParameterisationPolyhedraZ::ComputeDimensions(), G4ParameterisationTrdX::ComputeDimensions(), G4ParameterisationTrdY::ComputeDimensions(), G4ParameterisationTrdZ::ComputeDimensions(), G4ParameterisationTubsRho::ComputeDimensions(), G4ParameterisationTubsPhi::ComputeDimensions(), G4ParameterisationTubsZ::ComputeDimensions(), G4ReflectedSolid::ComputeDimensions(), G4DisplacedSolid::ComputeDimensions(), G4ScaledSolid::ComputeDimensions(), G4ParameterisedNavigation::ComputeStep(), G4ReplicaNavigation::ComputeStep(), G4DisplacedSolid::CreatePolyhedron(), G4ScaledSolid::CreatePolyhedron(), G4SubtractionSolid::DistanceToIn(), G4Box::DistanceToOut(), G4Orb::DistanceToOut(), G4Para::DistanceToOut(), G4Trap::DistanceToOut(), G4Trd::DistanceToOut(), G4Paraboloid::DistanceToOut(), G4VTwistedFaceted::DistanceToOut(), G4Cons::DistanceToOut(), G4CutTubs::DistanceToOut(), G4Sphere::DistanceToOut(), G4Torus::DistanceToOut(), G4Tubs::DistanceToOut(), G4Ellipsoid::DistanceToOut(), G4EllipticalCone::DistanceToOut(), G4EllipticalTube::DistanceToOut(), DistanceToOut(), export_G4VSolid(), G4Polycone::G4Polycone(), G4Polyhedra::G4Polyhedra(), G4BooleanSolid::GetConstituentSolid(), G4NavigationLogger::PostComputeStepLog(), G4Box::SurfaceNormal(), G4Para::SurfaceNormal(), G4Trap::SurfaceNormal(), G4Trd::SurfaceNormal(), G4Ellipsoid::SurfaceNormal(), G4EllipticalCone::SurfaceNormal(), G4EllipticalTube::SurfaceNormal(), G4ExtrudedSolid::SurfaceNormal(), and G4Tet::SurfaceNormal().

◆ EstimateCubicVolume()

G4double G4VSolid::EstimateCubicVolume ( G4int  nStat,
G4double  epsilon 
) const
inherited

Definition at line 203 of file G4VSolid.cc.

204{
205 G4int iInside=0;
206 G4double px,py,pz,minX,maxX,minY,maxY,minZ,maxZ,volume,halfepsilon;
208 EInside in;
209
210 // values needed for CalculateExtent signature
211
212 G4VoxelLimits limit; // Unlimited
213 G4AffineTransform origin;
214
215 // min max extents of pSolid along X,Y,Z
216
217 CalculateExtent(kXAxis,limit,origin,minX,maxX);
218 CalculateExtent(kYAxis,limit,origin,minY,maxY);
219 CalculateExtent(kZAxis,limit,origin,minZ,maxZ);
220
221 // limits
222
223 if(nStat < 100) nStat = 100;
224 if(epsilon > 0.01) epsilon = 0.01;
225 halfepsilon = 0.5*epsilon;
226
227 for(auto i = 0; i < nStat; ++i )
228 {
229 px = minX-halfepsilon+(maxX-minX+epsilon)*G4QuickRand();
230 py = minY-halfepsilon+(maxY-minY+epsilon)*G4QuickRand();
231 pz = minZ-halfepsilon+(maxZ-minZ+epsilon)*G4QuickRand();
232 p = G4ThreeVector(px,py,pz);
233 in = Inside(p);
234 if(in != kOutside) ++iInside;
235 }
236 volume = (maxX-minX+epsilon)*(maxY-minY+epsilon)
237 * (maxZ-minZ+epsilon)*iInside/nStat;
238 return volume;
239}
G4double epsilon(G4double density, G4double temperature)
static const G4int maxZ
G4double G4QuickRand()
Definition: G4QuickRand.hh:34
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
virtual EInside Inside(const G4ThreeVector &p) const =0
EInside
Definition: geomdefs.hh:67

References G4VSolid::CalculateExtent(), epsilon(), G4QuickRand(), G4VSolid::Inside(), kOutside, kXAxis, kYAxis, kZAxis, and maxZ.

Referenced by G4VSolid::GetCubicVolume(), G4BooleanSolid::GetCubicVolume(), and G4VCSGfaceted::GetCubicVolume().

◆ EstimateSurfaceArea()

G4double G4VSolid::EstimateSurfaceArea ( G4int  nStat,
G4double  ell 
) const
inherited

Definition at line 265 of file G4VSolid.cc.

266{
267 static const G4double s2 = 1./std::sqrt(2.);
268 static const G4double s3 = 1./std::sqrt(3.);
269 static const G4ThreeVector directions[64] =
270 {
271 G4ThreeVector( 0, 0, 0), G4ThreeVector( -1, 0, 0), // ( , , ) ( -, , )
272 G4ThreeVector( 1, 0, 0), G4ThreeVector( -1, 0, 0), // ( +, , ) (-+, , )
273 G4ThreeVector( 0, -1, 0), G4ThreeVector(-s2,-s2, 0), // ( , -, ) ( -, -, )
274 G4ThreeVector( s2, -s2, 0), G4ThreeVector( 0, -1, 0), // ( +, -, ) (-+, -, )
275
276 G4ThreeVector( 0, 1, 0), G4ThreeVector( -s2, s2, 0), // ( , +, ) ( -, +, )
277 G4ThreeVector( s2, s2, 0), G4ThreeVector( 0, 1, 0), // ( +, +, ) (-+, +, )
278 G4ThreeVector( 0, -1, 0), G4ThreeVector( -1, 0, 0), // ( ,-+, ) ( -,-+, )
279 G4ThreeVector( 1, 0, 0), G4ThreeVector( -1, 0, 0), // ( +,-+, ) (-+,-+, )
280
281 G4ThreeVector( 0, 0, -1), G4ThreeVector(-s2, 0,-s2), // ( , , -) ( -, , -)
282 G4ThreeVector( s2, 0,-s2), G4ThreeVector( 0, 0, -1), // ( +, , -) (-+, , -)
283 G4ThreeVector( 0,-s2,-s2), G4ThreeVector(-s3,-s3,-s3), // ( , -, -) ( -, -, -)
284 G4ThreeVector( s3,-s3,-s3), G4ThreeVector( 0,-s2,-s2), // ( +, -, -) (-+, -, -)
285
286 G4ThreeVector( 0, s2,-s2), G4ThreeVector(-s3, s3,-s3), // ( , +, -) ( -, +, -)
287 G4ThreeVector( s3, s3,-s3), G4ThreeVector( 0, s2,-s2), // ( +, +, -) (-+, +, -)
288 G4ThreeVector( 0, 0, -1), G4ThreeVector(-s2, 0,-s2), // ( ,-+, -) ( -,-+, -)
289 G4ThreeVector( s2, 0,-s2), G4ThreeVector( 0, 0, -1), // ( +,-+, -) (-+,-+, -)
290
291 G4ThreeVector( 0, 0, 1), G4ThreeVector(-s2, 0, s2), // ( , , +) ( -, , +)
292 G4ThreeVector( s2, 0, s2), G4ThreeVector( 0, 0, 1), // ( +, , +) (-+, , +)
293 G4ThreeVector( 0,-s2, s2), G4ThreeVector(-s3,-s3, s3), // ( , -, +) ( -, -, +)
294 G4ThreeVector( s3,-s3, s3), G4ThreeVector( 0,-s2, s2), // ( +, -, +) (-+, -, +)
295
296 G4ThreeVector( 0, s2, s2), G4ThreeVector(-s3, s3, s3), // ( , +, +) ( -, +, +)
297 G4ThreeVector( s3, s3, s3), G4ThreeVector( 0, s2, s2), // ( +, +, +) (-+, +, +)
298 G4ThreeVector( 0, 0, 1), G4ThreeVector(-s2, 0, s2), // ( ,-+, +) ( -,-+, +)
299 G4ThreeVector( s2, 0, s2), G4ThreeVector( 0, 0, 1), // ( +,-+, +) (-+,-+, +)
300
301 G4ThreeVector( 0, 0, -1), G4ThreeVector( -1, 0, 0), // ( , ,-+) ( -, ,-+)
302 G4ThreeVector( 1, 0, 0), G4ThreeVector( -1, 0, 0), // ( +, ,-+) (-+, ,-+)
303 G4ThreeVector( 0, -1, 0), G4ThreeVector(-s2,-s2, 0), // ( , -,-+) ( -, -,-+)
304 G4ThreeVector( s2, -s2, 0), G4ThreeVector( 0, -1, 0), // ( +, -,-+) (-+, -,-+)
305
306 G4ThreeVector( 0, 1, 0), G4ThreeVector( -s2, s2, 0), // ( , +,-+) ( -, +,-+)
307 G4ThreeVector( s2, s2, 0), G4ThreeVector( 0, 1, 0), // ( +, +,-+) (-+, +,-+)
308 G4ThreeVector( 0, -1, 0), G4ThreeVector( -1, 0, 0), // ( ,-+,-+) ( -,-+,-+)
309 G4ThreeVector( 1, 0, 0), G4ThreeVector( -1, 0, 0), // ( +,-+,-+) (-+,-+,-+)
310 };
311
312 G4ThreeVector bmin, bmax;
313 BoundingLimits(bmin, bmax);
314
315 G4double dX = bmax.x() - bmin.x();
316 G4double dY = bmax.y() - bmin.y();
317 G4double dZ = bmax.z() - bmin.z();
318
319 // Define statistics and shell thickness
320 //
321 G4int npoints = (nstat < 1000) ? 1000 : nstat;
322 G4double coeff = 0.5 / std::cbrt(G4double(npoints));
323 G4double eps = (ell > 0) ? ell : coeff * std::min(std::min(dX, dY), dZ);
324 G4double del = 1.8 * eps; // shold be more than sqrt(3.)
325
326 G4double minX = bmin.x() - eps;
327 G4double minY = bmin.y() - eps;
328 G4double minZ = bmin.z() - eps;
329
330 G4double dd = 2. * eps;
331 dX += dd;
332 dY += dd;
333 dZ += dd;
334
335 // Calculate surface area
336 //
337 G4int icount = 0;
338 for(auto i = 0; i < npoints; ++i)
339 {
340 G4double px = minX + dX*G4QuickRand();
341 G4double py = minY + dY*G4QuickRand();
342 G4double pz = minZ + dZ*G4QuickRand();
343 G4ThreeVector p = G4ThreeVector(px, py, pz);
344 EInside in = Inside(p);
345 G4double dist = 0;
346 if (in == kInside)
347 {
348 if (DistanceToOut(p) >= eps) continue;
349 G4int icase = 0;
350 if (Inside(G4ThreeVector(px-del, py, pz)) != kInside) icase += 1;
351 if (Inside(G4ThreeVector(px+del, py, pz)) != kInside) icase += 2;
352 if (Inside(G4ThreeVector(px, py-del, pz)) != kInside) icase += 4;
353 if (Inside(G4ThreeVector(px, py+del, pz)) != kInside) icase += 8;
354 if (Inside(G4ThreeVector(px, py, pz-del)) != kInside) icase += 16;
355 if (Inside(G4ThreeVector(px, py, pz+del)) != kInside) icase += 32;
356 if (icase == 0) continue;
357 G4ThreeVector v = directions[icase];
358 dist = DistanceToOut(p, v);
359 G4ThreeVector n = SurfaceNormal(p + v*dist);
360 dist *= v.dot(n);
361 }
362 else if (in == kOutside)
363 {
364 if (DistanceToIn(p) >= eps) continue;
365 G4int icase = 0;
366 if (Inside(G4ThreeVector(px-del, py, pz)) != kOutside) icase += 1;
367 if (Inside(G4ThreeVector(px+del, py, pz)) != kOutside) icase += 2;
368 if (Inside(G4ThreeVector(px, py-del, pz)) != kOutside) icase += 4;
369 if (Inside(G4ThreeVector(px, py+del, pz)) != kOutside) icase += 8;
370 if (Inside(G4ThreeVector(px, py, pz-del)) != kOutside) icase += 16;
371 if (Inside(G4ThreeVector(px, py, pz+del)) != kOutside) icase += 32;
372 if (icase == 0) continue;
373 G4ThreeVector v = directions[icase];
374 dist = DistanceToIn(p, v);
375 if (dist == kInfinity) continue;
376 G4ThreeVector n = SurfaceNormal(p + v*dist);
377 dist *= -(v.dot(n));
378 }
379 if (dist < eps) ++icount;
380 }
381 return dX*dY*dZ*icount/npoints/dd;
382}
static const G4double eps
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
Definition: G4VSolid.cc:665
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
@ kInside
Definition: geomdefs.hh:70
T min(const T t1, const T t2)
brief Return the smallest of the two arguments

References G4VSolid::BoundingLimits(), G4VSolid::DistanceToIn(), G4VSolid::DistanceToOut(), CLHEP::Hep3Vector::dot(), eps, G4QuickRand(), G4VSolid::Inside(), kInfinity, kInside, kOutside, G4INCL::Math::min(), CLHEP::detail::n, G4VSolid::SurfaceNormal(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by G4VSolid::GetSurfaceArea(), G4MultiUnion::GetSurfaceArea(), and G4VCSGfaceted::GetSurfaceArea().

◆ GetConstituentSolid() [1/2]

G4VSolid * G4VSolid::GetConstituentSolid ( G4int  no)
virtualinherited

Reimplemented in G4BooleanSolid.

Definition at line 170 of file G4VSolid.cc.

171{ return nullptr; }

◆ GetConstituentSolid() [2/2]

const G4VSolid * G4VSolid::GetConstituentSolid ( G4int  no) const
virtualinherited

Reimplemented in G4BooleanSolid.

Definition at line 167 of file G4VSolid.cc.

168{ return nullptr; }

Referenced by G4BooleanSolid::StackPolyhedron().

◆ GetCubicVolume()

G4double G4GenericTrap::GetCubicVolume ( )
virtual

Reimplemented from G4VSolid.

Definition at line 1423 of file G4GenericTrap.cc.

1424{
1425 if (fCubicVolume == 0.0)
1426 {
1427 if(fIsTwisted)
1428 {
1430 }
1431 else
1432 {
1433 // Set vertices
1434 G4ThreeVector v0(fVertices[0].x(),fVertices[0].y(),-fDz);
1435 G4ThreeVector v1(fVertices[1].x(),fVertices[1].y(),-fDz);
1436 G4ThreeVector v2(fVertices[2].x(),fVertices[2].y(),-fDz);
1437 G4ThreeVector v3(fVertices[3].x(),fVertices[3].y(),-fDz);
1438 G4ThreeVector v4(fVertices[4].x(),fVertices[4].y(), fDz);
1439 G4ThreeVector v5(fVertices[5].x(),fVertices[5].y(), fDz);
1440 G4ThreeVector v6(fVertices[6].x(),fVertices[6].y(), fDz);
1441 G4ThreeVector v7(fVertices[7].x(),fVertices[7].y(), fDz);
1442
1443 // Find Cubic Volume
1444 fCubicVolume = GetFaceCubicVolume(v0,v1,v2,v3) // -fDz plane
1445 + GetFaceCubicVolume(v1,v0,v4,v5) // Lat plane
1446 + GetFaceCubicVolume(v2,v1,v5,v6) // Lat plane
1447 + GetFaceCubicVolume(v3,v2,v6,v7) // Lat plane
1448 + GetFaceCubicVolume(v0,v3,v7,v4) // Lat plane
1449 + GetFaceCubicVolume(v7,v6,v5,v4); // +fDz plane
1450 }
1451 }
1452 return fCubicVolume;
1453}
G4double GetFaceCubicVolume(const G4ThreeVector &p0, const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3) const
virtual G4double GetCubicVolume()
Definition: G4VSolid.cc:188

References fCubicVolume, fDz, fIsTwisted, fVertices, G4VSolid::GetCubicVolume(), and GetFaceCubicVolume().

◆ GetDisplacedSolidPtr() [1/2]

G4DisplacedSolid * G4VSolid::GetDisplacedSolidPtr ( )
virtualinherited

Reimplemented in G4DisplacedSolid.

Definition at line 176 of file G4VSolid.cc.

177{ return nullptr; }

◆ GetDisplacedSolidPtr() [2/2]

const G4DisplacedSolid * G4VSolid::GetDisplacedSolidPtr ( ) const
virtualinherited

Reimplemented in G4DisplacedSolid.

Definition at line 173 of file G4VSolid.cc.

174{ return nullptr; }

◆ GetEntityType()

G4GeometryType G4GenericTrap::GetEntityType ( ) const
virtual

Implements G4VSolid.

Definition at line 1259 of file G4GenericTrap.cc.

1260{
1261 return G4String("G4GenericTrap");
1262}

Referenced by StreamInfo().

◆ GetExtent()

G4VisExtent G4GenericTrap::GetExtent ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 2021 of file G4GenericTrap.cc.

2022{
2023 // Computes bounding vectors for the shape
2024
2025#ifdef G4TESS_TEST
2026 if ( fTessellatedSolid != nullptr )
2027 {
2028 return fTessellatedSolid->GetExtent();
2029 }
2030#endif
2031
2032 G4ThreeVector minVec = GetMinimumBBox();
2033 G4ThreeVector maxVec = GetMaximumBBox();
2034 return G4VisExtent (minVec.x(), maxVec.x(),
2035 minVec.y(), maxVec.y(),
2036 minVec.z(), maxVec.z());
2037}
virtual G4VisExtent GetExtent() const

References fTessellatedSolid, G4TessellatedSolid::GetExtent(), GetMaximumBBox(), GetMinimumBBox(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

◆ GetFaceCubicVolume()

G4double G4GenericTrap::GetFaceCubicVolume ( const G4ThreeVector p0,
const G4ThreeVector p1,
const G4ThreeVector p2,
const G4ThreeVector p3 
) const
private

Definition at line 1500 of file G4GenericTrap.cc.

1504{
1505 // Returns contribution of the facet to the volume of the solid.
1506 // Orientation of the facet is important, normal should point to outside.
1507 return (((p2-p0).cross(p3-p1)).dot(p0)) / 6.;
1508}

Referenced by GetCubicVolume().

◆ GetFaceSurfaceArea()

G4double G4GenericTrap::GetFaceSurfaceArea ( const G4ThreeVector p0,
const G4ThreeVector p1,
const G4ThreeVector p2,
const G4ThreeVector p3 
) const
private

Definition at line 1457 of file G4GenericTrap.cc.

1461{
1462 // Returns area of the facet
1463 return 0.5*((p2-p0).cross(p3-p1)).mag();
1464}

Referenced by GetPointOnSurface(), and GetSurfaceArea().

◆ GetMaximumBBox()

G4ThreeVector G4GenericTrap::GetMaximumBBox ( ) const
inlineprivate

◆ GetMinimumBBox()

G4ThreeVector G4GenericTrap::GetMinimumBBox ( ) const
inlineprivate

◆ GetName()

G4String G4VSolid::GetName ( ) const
inlineinherited

Referenced by G4GMocrenFileSceneHandler::AddDetector(), G4HepRepFileSceneHandler::AddHepRepInstance(), G4GMocrenFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddSolid(), G4GMocrenFileSceneHandler::AddSolid(), G4VtkSceneHandler::AddSolid(), G4GDMLWriteSolids::AddSolid(), G4NavigationLogger::AlongComputeStepLog(), G4GDMLWriteSolids::BooleanWrite(), G4ReflectedSolid::BoundingLimits(), G4DisplacedSolid::BoundingLimits(), G4IntersectionSolid::BoundingLimits(), G4ScaledSolid::BoundingLimits(), G4SubtractionSolid::BoundingLimits(), G4UnionSolid::BoundingLimits(), G4Box::BoundingLimits(), G4Cons::BoundingLimits(), G4CutTubs::BoundingLimits(), G4Orb::BoundingLimits(), G4Para::BoundingLimits(), G4Sphere::BoundingLimits(), G4Torus::BoundingLimits(), G4Trap::BoundingLimits(), G4Trd::BoundingLimits(), G4Tubs::BoundingLimits(), G4EllipticalCone::BoundingLimits(), G4ExtrudedSolid::BoundingLimits(), G4GenericPolycone::BoundingLimits(), BoundingLimits(), G4Hype::BoundingLimits(), G4Paraboloid::BoundingLimits(), G4Polycone::BoundingLimits(), G4Polyhedra::BoundingLimits(), G4TessellatedSolid::BoundingLimits(), G4TwistedTubs::BoundingLimits(), G4GDMLWriteSolids::BoxWrite(), G4ExtrudedSolid::CalculateExtent(), G4GenericPolycone::CalculateExtent(), G4Polycone::CalculateExtent(), G4Polyhedra::CalculateExtent(), G4NavigationLogger::CheckDaughterEntryPoint(), G4VDivisionParameterisation::CheckNDivAndWidth(), G4VDivisionParameterisation::CheckOffset(), CheckOrder(), G4Para::CheckParameters(), G4Trap::CheckParameters(), G4Trd::CheckParameters(), G4Ellipsoid::CheckParameters(), G4EllipticalTube::CheckParameters(), G4ParameterisationPolyconeRho::CheckParametersValidity(), G4ParameterisationPolyconeZ::CheckParametersValidity(), G4ParameterisationPolyhedraRho::CheckParametersValidity(), G4ParameterisationPolyhedraPhi::CheckParametersValidity(), G4ParameterisationPolyhedraZ::CheckParametersValidity(), G4PhantomParameterisation::CheckVoxelsFillContainer(), ComputeIsTwisted(), G4VoxelNavigation::ComputeSafety(), G4VoxelSafety::ComputeSafety(), G4NavigationLogger::ComputeSafetyLog(), G4ParameterisedNavigation::ComputeStep(), G4ReplicaNavigation::ComputeStep(), G4GDMLWriteSolids::ConeWrite(), G4Polyhedra::Create(), G4GenericPolycone::Create(), G4Polycone::Create(), G4PhysicalVolumeModel::CreateCurrentAttValues(), G4ReflectedSolid::CreatePolyhedron(), G4ReflectionFactory::CreateReflectedLV(), CreateTessellatedSolid(), G4GDMLWriteSolids::CutTubeWrite(), G4SolidStore::DeRegister(), G4PhysicalVolumeModel::DescribeSolid(), G4SubtractionSolid::DistanceToIn(), G4Paraboloid::DistanceToIn(), G4TessellatedSolid::DistanceToIn(), G4Box::DistanceToOut(), G4Orb::DistanceToOut(), G4Para::DistanceToOut(), G4Trap::DistanceToOut(), G4Trd::DistanceToOut(), G4EllipticalCone::DistanceToOut(), G4TessellatedSolid::DistanceToOut(), G4Ellipsoid::DistanceToOut(), G4EllipticalTube::DistanceToOut(), G4tgbGeometryDumper::DumpMultiUnionVolume(), G4tgbGeometryDumper::DumpScaledVolume(), G4tgbGeometryDumper::DumpSolid(), G4GDMLWriteSolids::ElconeWrite(), G4GDMLWriteSolids::EllipsoidWrite(), G4GDMLWriteSolids::EltubeWrite(), G4PVDivision::ErrorInAxis(), G4ReplicatedSlice::ErrorInAxis(), export_G4VSolid(), G4Box::G4Box(), G4Cons::G4Cons(), G4CutTubs::G4CutTubs(), G4EllipticalCone::G4EllipticalCone(), G4Hype::G4Hype(), G4Para::G4Para(), G4Paraboloid::G4Paraboloid(), G4Polycone::G4Polycone(), G4Polyhedra::G4Polyhedra(), G4Sphere::G4Sphere(), G4Tet::G4Tet(), G4Trap::G4Trap(), G4Tubs::G4Tubs(), G4VParameterisationCons::G4VParameterisationCons(), G4VParameterisationPara::G4VParameterisationPara(), G4VParameterisationPolycone::G4VParameterisationPolycone(), G4VParameterisationPolyhedra::G4VParameterisationPolyhedra(), G4VParameterisationTrd::G4VParameterisationTrd(), G4VTwistedFaceted::G4VTwistedFaceted(), G4GDMLWriteSolids::GenericPolyconeWrite(), G4GDMLWriteSolids::GenTrapWrite(), G4Navigator::GetGlobalExitNormal(), G4Navigator::GetLocalExitNormal(), G4ITNavigator1::GetLocalExitNormal(), G4ITNavigator2::GetLocalExitNormal(), G4BooleanSolid::GetPointOnSurface(), G4PhantomParameterisation::GetReplicaNo(), G4GDMLWriteSolids::HypeWrite(), G4TessellatedSolid::InsideNoVoxels(), G4TessellatedSolid::InsideVoxels(), G4ITNavigator1::LocateGlobalPointAndSetup(), G4ITNavigator2::LocateGlobalPointAndSetup(), G4Navigator::LocateGlobalPointAndSetup(), MakeDownFacet(), G4Trap::MakePlanes(), MakeUpFacet(), G4GDMLWriteSolids::MultiUnionWrite(), G4GDMLWriteSolids::OrbWrite(), G4GDMLWriteSolids::ParaboloidWrite(), G4GDMLWriteParamvol::ParametersWrite(), G4GDMLWriteSolids::ParaWrite(), G4GDMLWriteSolids::PolyconeWrite(), G4GDMLWriteSolids::PolyhedraWrite(), G4NavigationLogger::PostComputeStepLog(), G4NavigationLogger::PreComputeStepLog(), G4NavigationLogger::PrintDaughterLog(), G4PseudoScene::ProcessVolume(), G4SolidStore::Register(), G4tgbVolumeMgr::RegisterMe(), G4NavigationLogger::ReportOutsideMother(), G4ASCIITreeSceneHandler::RequestPrimitives(), G4VSceneHandler::RequestPrimitives(), G4GenericPolycone::Reset(), G4Polyhedra::Reset(), G4VoxelSafety::SafetyForVoxelNode(), G4GDMLWriteSolids::ScaledWrite(), G4Torus::SetAllParameters(), G4Tet::SetBoundingLimits(), G4Polycone::SetOriginalParameters(), G4Polyhedra::SetOriginalParameters(), G4TessellatedSolid::SetSolidClosed(), G4Tet::SetVertices(), G4Box::SetXHalfLength(), G4Box::SetYHalfLength(), G4Box::SetZHalfLength(), G4GDMLWriteSolids::SphereWrite(), G4BooleanSolid::StackPolyhedron(), G4ReflectedSolid::StreamInfo(), G4BooleanSolid::StreamInfo(), G4DisplacedSolid::StreamInfo(), G4MultiUnion::StreamInfo(), G4ScaledSolid::StreamInfo(), G4Box::StreamInfo(), G4Cons::StreamInfo(), G4CSGSolid::StreamInfo(), G4CutTubs::StreamInfo(), G4Orb::StreamInfo(), G4Para::StreamInfo(), G4Sphere::StreamInfo(), G4Torus::StreamInfo(), G4Trap::StreamInfo(), G4Trd::StreamInfo(), G4Tubs::StreamInfo(), G4Ellipsoid::StreamInfo(), G4EllipticalCone::StreamInfo(), G4EllipticalTube::StreamInfo(), G4ExtrudedSolid::StreamInfo(), G4GenericPolycone::StreamInfo(), StreamInfo(), G4Hype::StreamInfo(), G4Paraboloid::StreamInfo(), G4Polycone::StreamInfo(), G4Polyhedra::StreamInfo(), G4TessellatedSolid::StreamInfo(), G4Tet::StreamInfo(), G4TwistedBox::StreamInfo(), G4TwistedTrap::StreamInfo(), G4TwistedTrd::StreamInfo(), G4TwistedTubs::StreamInfo(), G4VCSGfaceted::StreamInfo(), G4VTwistedFaceted::StreamInfo(), G4GDMLRead::StripNames(), SubstractSolids(), G4UnionSolid::SurfaceNormal(), G4Box::SurfaceNormal(), G4Para::SurfaceNormal(), G4Trap::SurfaceNormal(), G4Trd::SurfaceNormal(), G4Ellipsoid::SurfaceNormal(), G4EllipticalCone::SurfaceNormal(), G4EllipticalTube::SurfaceNormal(), G4ExtrudedSolid::SurfaceNormal(), G4Tet::SurfaceNormal(), G4GDMLWriteSolids::TessellatedWrite(), G4GDMLWriteSolids::TetWrite(), G4GDMLWriteSolids::TorusWrite(), G4GDMLWriteSolids::TrapWrite(), G4GDMLWriteStructure::TraverseVolumeTree(), G4GDMLWriteSolids::TrdWrite(), G4GDMLWriteSolids::TubeWrite(), G4GDMLWriteSolids::TwistedboxWrite(), G4GDMLWriteSolids::TwistedtrapWrite(), G4GDMLWriteSolids::TwistedtrdWrite(), G4GDMLWriteSolids::TwistedtubsWrite(), G4PhysicalVolumeModel::VisitGeometryAndGetVisReps(), and G4GDMLWriteSolids::XtruWrite().

◆ GetNofVertices()

G4int G4GenericTrap::GetNofVertices ( ) const
inline

◆ GetPointOnSurface()

G4ThreeVector G4GenericTrap::GetPointOnSurface ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1296 of file G4GenericTrap.cc.

1297{
1298
1299#ifdef G4TESS_TEST
1300 if ( fTessellatedSolid )
1301 {
1303 }
1304#endif
1305
1306 G4ThreeVector point;
1307 G4TwoVector u,v,w;
1308 G4double rand,area,chose,cf,lambda0,lambda1,alfa,beta,zp;
1309 G4int ipl,j;
1310
1311 std::vector<G4ThreeVector> vertices;
1312 for (auto i=0; i<4; ++i)
1313 {
1314 vertices.push_back(G4ThreeVector(fVertices[i].x(),fVertices[i].y(),-fDz));
1315 }
1316 for (auto i=4; i<8; ++i)
1317 {
1318 vertices.push_back(G4ThreeVector(fVertices[i].x(),fVertices[i].y(),fDz));
1319 }
1320
1321 // Surface Area of Planes(only estimation for twisted)
1322 //
1323 G4double Surface0=GetFaceSurfaceArea(vertices[0],vertices[1],
1324 vertices[2],vertices[3]);//-fDz plane
1325 G4double Surface1=GetFaceSurfaceArea(vertices[0],vertices[1],
1326 vertices[5],vertices[4]);// Lat plane
1327 G4double Surface2=GetFaceSurfaceArea(vertices[3],vertices[0],
1328 vertices[4],vertices[7]);// Lat plane
1329 G4double Surface3=GetFaceSurfaceArea(vertices[2],vertices[3],
1330 vertices[7],vertices[6]);// Lat plane
1331 G4double Surface4=GetFaceSurfaceArea(vertices[2],vertices[1],
1332 vertices[5],vertices[6]);// Lat plane
1333 G4double Surface5=GetFaceSurfaceArea(vertices[4],vertices[5],
1334 vertices[6],vertices[7]);// fDz plane
1335 rand = G4UniformRand();
1336 area = Surface0+Surface1+Surface2+Surface3+Surface4+Surface5;
1337 chose = rand*area;
1338
1339 if ( ( chose < Surface0)
1340 || ( chose > (Surface0+Surface1+Surface2+Surface3+Surface4)) )
1341 { // fDz or -fDz Plane
1342 ipl = G4int(G4UniformRand()*4);
1343 j = (ipl+1)%4;
1344 if(chose < Surface0)
1345 {
1346 zp = -fDz;
1347 u = fVertices[ipl]; v = fVertices[j];
1348 w = fVertices[(ipl+3)%4];
1349 }
1350 else
1351 {
1352 zp = fDz;
1353 u = fVertices[ipl+4]; v = fVertices[j+4];
1354 w = fVertices[(ipl+3)%4+4];
1355 }
1356 alfa = G4UniformRand();
1357 beta = G4UniformRand();
1358 lambda1=alfa*beta;
1359 lambda0=alfa-lambda1;
1360 v = v-u;
1361 w = w-u;
1362 v = u+lambda0*v+lambda1*w;
1363 }
1364 else // Lateral Plane Twisted or Not
1365 {
1366 if (chose < Surface0+Surface1) { ipl=0; }
1367 else if (chose < Surface0+Surface1+Surface2) { ipl=1; }
1368 else if (chose < Surface0+Surface1+Surface2+Surface3) { ipl=2; }
1369 else { ipl=3; }
1370 j = (ipl+1)%4;
1371 zp = -fDz+G4UniformRand()*2*fDz;
1372 cf = 0.5*(fDz-zp)/fDz;
1373 u = fVertices[ipl+4]+cf*( fVertices[ipl]-fVertices[ipl+4]);
1374 v = fVertices[j+4]+cf*(fVertices[j]-fVertices[j+4]);
1375 v = u+(v-u)*G4UniformRand();
1376 }
1377 point=G4ThreeVector(v.x(),v.y(),zp);
1378
1379 return point;
1380}
#define G4UniformRand()
Definition: Randomize.hh:52
G4double GetFaceSurfaceArea(const G4ThreeVector &p0, const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3) const
virtual G4ThreeVector GetPointOnSurface() const

References anonymous_namespace{G4PionRadiativeDecayChannel.cc}::beta, fDz, fTessellatedSolid, fVertices, G4UniformRand, GetFaceSurfaceArea(), G4TessellatedSolid::GetPointOnSurface(), CLHEP::Hep2Vector::x(), and CLHEP::Hep2Vector::y().

◆ GetPolyhedron()

G4Polyhedron * G4GenericTrap::GetPolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1980 of file G4GenericTrap.cc.

1981{
1982
1983#ifdef G4TESS_TEST
1984 if ( fTessellatedSolid )
1985 {
1987 }
1988#endif
1989
1990 if ( (fpPolyhedron == nullptr)
1994 {
1996 delete fpPolyhedron;
1998 fRebuildPolyhedron = false;
1999 l.unlock();
2000 }
2001 return fpPolyhedron;
2002}
G4Polyhedron * CreatePolyhedron() const
G4bool fRebuildPolyhedron
G4Polyhedron * fpPolyhedron
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
virtual G4Polyhedron * GetPolyhedron() const
static G4int GetNumberOfRotationSteps()

References CreatePolyhedron(), fpPolyhedron, fRebuildPolyhedron, fTessellatedSolid, HepPolyhedron::GetNumberOfRotationSteps(), G4Polyhedron::GetNumberOfRotationStepsAtTimeOfCreation(), G4TessellatedSolid::GetPolyhedron(), anonymous_namespace{G4GenericTrap.cc}::polyhedronMutex, and G4TemplateAutoLock< _Mutex_t >::unlock().

◆ GetSurfaceArea()

G4double G4GenericTrap::GetSurfaceArea ( )
virtual

Reimplemented from G4VSolid.

Definition at line 1384 of file G4GenericTrap.cc.

1385{
1386 // Set vertices
1387 G4ThreeVector v0(fVertices[0].x(),fVertices[0].y(),-fDz);
1388 G4ThreeVector v1(fVertices[1].x(),fVertices[1].y(),-fDz);
1389 G4ThreeVector v2(fVertices[2].x(),fVertices[2].y(),-fDz);
1390 G4ThreeVector v3(fVertices[3].x(),fVertices[3].y(),-fDz);
1391 G4ThreeVector v4(fVertices[4].x(),fVertices[4].y(), fDz);
1392 G4ThreeVector v5(fVertices[5].x(),fVertices[5].y(), fDz);
1393 G4ThreeVector v6(fVertices[6].x(),fVertices[6].y(), fDz);
1394 G4ThreeVector v7(fVertices[7].x(),fVertices[7].y(), fDz);
1395
1396 // Find Surface Area
1397 if (fSurfaceArea == 0.0)
1398 {
1399 if(fIsTwisted)
1400 {
1401 fSurfaceArea = GetFaceSurfaceArea(v0,v1,v2,v3) // -fDz plane
1402 + GetTwistedFaceSurfaceArea(v1,v0,v4,v5) // Lat plane
1403 + GetTwistedFaceSurfaceArea(v2,v1,v5,v6) // Lat plane
1404 + GetTwistedFaceSurfaceArea(v3,v2,v6,v7) // Lat plane
1405 + GetTwistedFaceSurfaceArea(v0,v3,v7,v4) // Lat plane
1406 + GetFaceSurfaceArea(v7,v6,v5,v4); // +fDz plane
1407 }
1408 else
1409 {
1410 fSurfaceArea = GetFaceSurfaceArea(v0,v1,v2,v3) // -fDz plane
1411 + GetFaceSurfaceArea(v1,v0,v4,v5) // Lat plane
1412 + GetFaceSurfaceArea(v2,v1,v5,v6) // Lat plane
1413 + GetFaceSurfaceArea(v3,v2,v6,v7) // Lat plane
1414 + GetFaceSurfaceArea(v0,v3,v7,v4) // Lat plane
1415 + GetFaceSurfaceArea(v7,v6,v5,v4); // +fDz plane
1416 }
1417 }
1418 return fSurfaceArea;
1419}
G4double GetTwistedFaceSurfaceArea(const G4ThreeVector &p0, const G4ThreeVector &p1, const G4ThreeVector &p2, const G4ThreeVector &p3) const

References fDz, fIsTwisted, fSurfaceArea, fVertices, GetFaceSurfaceArea(), and GetTwistedFaceSurfaceArea().

◆ GetTolerance()

G4double G4VSolid::GetTolerance ( ) const
inlineinherited

◆ GetTwistAngle()

G4double G4GenericTrap::GetTwistAngle ( G4int  index) const
inline

◆ GetTwistedFaceSurfaceArea()

G4double G4GenericTrap::GetTwistedFaceSurfaceArea ( const G4ThreeVector p0,
const G4ThreeVector p1,
const G4ThreeVector p2,
const G4ThreeVector p3 
) const
private

Definition at line 1469 of file G4GenericTrap.cc.

1473{
1474 G4int nstep = 100;
1475 G4ThreeVector dels1 = (p1 - p0)/nstep;
1476 G4ThreeVector dels2 = (p2 - p3)/nstep;
1477 G4double area = 0;
1478 for (G4int is = 0; is < nstep; ++is)
1479 {
1480 G4ThreeVector s0 = p0 + dels1*is;
1481 G4ThreeVector s1 = s0 + dels1;
1482 G4ThreeVector s3 = p3 + dels2*is;
1483 G4ThreeVector s2 = s3 + dels2;
1484 G4ThreeVector delt1 = (s3 - s0)/nstep;
1485 G4ThreeVector delt2 = (s2 - s1)/nstep;
1486 for (G4int it = 0; it < nstep; ++it)
1487 {
1488 G4ThreeVector t0 = s0 + delt1*it;
1489 G4ThreeVector t1 = t0 + delt1;
1490 G4ThreeVector t3 = s1 + delt2*it;
1491 G4ThreeVector t2 = t3 + delt2;
1492 area += 0.5*((t2-t0).cross(t3-t1)).mag();
1493 }
1494 }
1495 return area;
1496}

References G4InuclParticleNames::s0.

Referenced by GetSurfaceArea().

◆ GetVertex()

G4TwoVector G4GenericTrap::GetVertex ( G4int  index) const
inline

Referenced by CalculateExtent().

◆ GetVertices()

const std::vector< G4TwoVector > & G4GenericTrap::GetVertices ( ) const
inline

◆ GetVisSubdivisions()

G4int G4GenericTrap::GetVisSubdivisions ( ) const
inline

Referenced by CreatePolyhedron().

◆ GetZHalfLength()

G4double G4GenericTrap::GetZHalfLength ( ) const
inline

◆ Inside()

EInside G4GenericTrap::Inside ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 318 of file G4GenericTrap.cc.

319{
320 // Test if point is inside this shape
321
322#ifdef G4TESS_TEST
323 if ( fTessellatedSolid )
324 {
325 return fTessellatedSolid->Inside(p);
326 }
327#endif
328
329 EInside innew=kOutside;
330 std::vector<G4TwoVector> xy;
331
332 if (std::fabs(p.z()) <= fDz+halfCarTolerance) // First check Z range
333 {
334 // Compute intersection between Z plane containing point and the shape
335 //
336 G4double cf = 0.5*(fDz-p.z())/fDz;
337 for (auto i=0; i<4; ++i)
338 {
339 xy.push_back(fVertices[i+4]+cf*( fVertices[i]-fVertices[i+4]));
340 }
341
342 innew=InsidePolygone(p,xy);
343
344 if( (innew==kInside) || (innew==kSurface) )
345 {
346 if(std::fabs(p.z()) > fDz-halfCarTolerance) { innew=kSurface; }
347 }
348 }
349 return innew;
350}
virtual EInside Inside(const G4ThreeVector &p) const

References fDz, fTessellatedSolid, fVertices, halfCarTolerance, G4TessellatedSolid::Inside(), InsidePolygone(), kInside, kOutside, kSurface, and CLHEP::Hep3Vector::z().

Referenced by DistanceToIn(), DistToPlane(), and DistToTriangle().

◆ InsidePolygone()

EInside G4GenericTrap::InsidePolygone ( const G4ThreeVector p,
const std::vector< G4TwoVector > &  poly 
) const
private

Definition at line 216 of file G4GenericTrap.cc.

218{
219 EInside in = kInside;
220 G4double cross, len2;
221 G4int count=0;
222
223 for (G4int i=0; i<4; ++i)
224 {
225 G4int j = (i+1) % 4;
226
227 cross = (p.x()-poly[i].x())*(poly[j].y()-poly[i].y())-
228 (p.y()-poly[i].y())*(poly[j].x()-poly[i].x());
229
230 len2=(poly[i]-poly[j]).mag2();
231 if (len2 > kCarTolerance)
232 {
233 if(cross*cross<=len2*halfCarTolerance*halfCarTolerance) // Surface check
234 {
236
237 // Check if p lies between the two extremes of the segment
238 //
239 G4int iMax;
240 G4int iMin;
241
242 if (poly[j].x() > poly[i].x())
243 {
244 iMax = j;
245 iMin = i;
246 }
247 else {
248 iMax = i;
249 iMin = j;
250 }
251 if ( p.x() > poly[iMax].x()+halfCarTolerance
252 || p.x() < poly[iMin].x()-halfCarTolerance )
253 {
254 return kOutside;
255 }
256
257 if (poly[j].y() > poly[i].y())
258 {
259 iMax = j;
260 iMin = i;
261 }
262 else
263 {
264 iMax = i;
265 iMin = j;
266 }
267 if ( p.y() > poly[iMax].y()+halfCarTolerance
268 || p.y() < poly[iMin].y()-halfCarTolerance )
269 {
270 return kOutside;
271 }
272
273 if ( poly[iMax].x() != poly[iMin].x() )
274 {
275 test = (p.x()-poly[iMin].x())/(poly[iMax].x()-poly[iMin].x())
276 * (poly[iMax].y()-poly[iMin].y())+poly[iMin].y();
277 }
278 else
279 {
280 test = p.y();
281 }
282
283 // Check if point is Inside Segment
284 //
285 if( (test>=(poly[iMin].y()-halfCarTolerance))
286 && (test<=(poly[iMax].y()+halfCarTolerance)) )
287 {
288 return kSurface;
289 }
290 else
291 {
292 return kOutside;
293 }
294 }
295 else if (cross<0.) { return kOutside; }
296 }
297 else
298 {
299 ++count;
300 }
301 }
302
303 // All collapsed vertices, Tet like
304 //
305 if(count==4)
306 {
307 if ( (std::fabs(p.x()-poly[0].x())
308 +std::fabs(p.y()-poly[0].y())) > halfCarTolerance )
309 {
310 in = kOutside;
311 }
312 }
313 return in;
314}
def test()
Definition: mcscore.py:117
Definition: test.py:1

References halfCarTolerance, G4VSolid::kCarTolerance, kInside, kOutside, kSurface, mcscore::test(), CLHEP::Hep3Vector::x(), and CLHEP::Hep3Vector::y().

Referenced by DistanceToOut(), and Inside().

◆ IsSegCrossing()

G4bool G4GenericTrap::IsSegCrossing ( const G4TwoVector a,
const G4TwoVector b,
const G4TwoVector c,
const G4TwoVector d 
) const
private

Definition at line 1656 of file G4GenericTrap.cc.

1658{
1659 // Check if segments [A,B] and [C,D] are crossing
1660
1661 G4bool stand1 = false;
1662 G4bool stand2 = false;
1663 G4double dx1,dx2,xm=0.,ym=0.,a1=0.,a2=0.,b1=0.,b2=0.;
1664 dx1=(b-a).x();
1665 dx2=(d-c).x();
1666
1667 if( std::fabs(dx1) < fgkTolerance ) { stand1 = true; }
1668 if( std::fabs(dx2) < fgkTolerance ) { stand2 = true; }
1669 if (!stand1)
1670 {
1671 a1 = (b.x()*a.y()-a.x()*b.y())/dx1;
1672 b1 = (b-a).y()/dx1;
1673 }
1674 if (!stand2)
1675 {
1676 a2 = (d.x()*c.y()-c.x()*d.y())/dx2;
1677 b2 = (d-c).y()/dx2;
1678 }
1679 if (stand1 && stand2)
1680 {
1681 // Segments parallel and vertical
1682 //
1683 if (std::fabs(a.x()-c.x())<fgkTolerance)
1684 {
1685 // Check if segments are overlapping
1686 //
1687 if ( ((c.y()-a.y())*(c.y()-b.y())<-fgkTolerance)
1688 || ((d.y()-a.y())*(d.y()-b.y())<-fgkTolerance)
1689 || ((a.y()-c.y())*(a.y()-d.y())<-fgkTolerance)
1690 || ((b.y()-c.y())*(b.y()-d.y())<-fgkTolerance) ) { return true; }
1691
1692 return false;
1693 }
1694 // Different x values
1695 //
1696 return false;
1697 }
1698
1699 if (stand1) // First segment vertical
1700 {
1701 xm = a.x();
1702 ym = a2+b2*xm;
1703 }
1704 else
1705 {
1706 if (stand2) // Second segment vertical
1707 {
1708 xm = c.x();
1709 ym = a1+b1*xm;
1710 }
1711 else // Normal crossing
1712 {
1713 if (std::fabs(b1-b2) < fgkTolerance)
1714 {
1715 // Parallel segments, are they aligned
1716 //
1717 if (std::fabs(c.y()-(a1+b1*c.x())) > fgkTolerance) { return false; }
1718
1719 // Aligned segments, are they overlapping
1720 //
1721 if ( ((c.x()-a.x())*(c.x()-b.x())<-fgkTolerance)
1722 || ((d.x()-a.x())*(d.x()-b.x())<-fgkTolerance)
1723 || ((a.x()-c.x())*(a.x()-d.x())<-fgkTolerance)
1724 || ((b.x()-c.x())*(b.x()-d.x())<-fgkTolerance) ) { return true; }
1725
1726 return false;
1727 }
1728 xm = (a1-a2)/(b2-b1);
1729 ym = (a1*b2-a2*b1)/(b2-b1);
1730 }
1731 }
1732
1733 // Check if crossing point is both between A,B and C,D
1734 //
1735 G4double check = (xm-a.x())*(xm-b.x())+(ym-a.y())*(ym-b.y());
1736 if (check > -fgkTolerance) { return false; }
1737 check = (xm-c.x())*(xm-d.x())+(ym-c.y())*(ym-d.y());
1738 if (check > -fgkTolerance) { return false; }
1739
1740 return true;
1741}

References fgkTolerance, CLHEP::Hep2Vector::x(), and CLHEP::Hep2Vector::y().

Referenced by CheckOrder().

◆ IsSegCrossingZ()

G4bool G4GenericTrap::IsSegCrossingZ ( const G4TwoVector a,
const G4TwoVector b,
const G4TwoVector c,
const G4TwoVector d 
) const
private

Definition at line 1746 of file G4GenericTrap.cc.

1748{
1749 // Check if segments [A,B] and [C,D] are crossing when
1750 // A and C are on -dZ and B and D are on +dZ
1751
1752 // Calculate the Intersection point between two lines in 3D
1753 //
1754 G4ThreeVector temp1,temp2;
1755 G4ThreeVector v1,v2,p1,p2,p3,p4,dv;
1756 G4double q,det;
1757 p1=G4ThreeVector(a.x(),a.y(),-fDz);
1758 p2=G4ThreeVector(c.x(),c.y(),-fDz);
1759 p3=G4ThreeVector(b.x(),b.y(),fDz);
1760 p4=G4ThreeVector(d.x(),d.y(),fDz);
1761 v1=p3-p1;
1762 v2=p4-p2;
1763 dv=p2-p1;
1764
1765 // In case of Collapsed Vertices No crossing
1766 //
1767 if( (std::fabs(dv.x()) < kCarTolerance )&&
1768 (std::fabs(dv.y()) < kCarTolerance ) ) { return false; }
1769
1770 if( (std::fabs((p4-p3).x()) < kCarTolerance )&&
1771 (std::fabs((p4-p3).y()) < kCarTolerance ) ) { return false; }
1772
1773 // First estimate if Intersection is possible( if det is 0)
1774 //
1775 det = dv.x()*v1.y()*v2.z()+dv.y()*v1.z()*v2.x()
1776 - dv.x()*v1.z()*v2.y()-dv.y()*v1.x()*v2.z();
1777
1778 if (std::fabs(det)<kCarTolerance) //Intersection
1779 {
1780 temp1 = v1.cross(v2);
1781 temp2 = (p2-p1).cross(v2);
1782 if (temp1.dot(temp2) < 0) { return false; } // intersection negative
1783 q = temp1.mag();
1784
1785 if ( q < kCarTolerance ) { return false; } // parallel lines
1786 q = ((dv).cross(v2)).mag()/q;
1787
1788 if(q < 1.-kCarTolerance) { return true; }
1789 }
1790 return false;
1791}
Hep3Vector cross(const Hep3Vector &) const
double mag() const

References CLHEP::Hep3Vector::cross(), CLHEP::Hep3Vector::dot(), fDz, G4VSolid::kCarTolerance, CLHEP::Hep3Vector::mag(), CLHEP::Hep3Vector::x(), CLHEP::Hep2Vector::x(), CLHEP::Hep3Vector::y(), CLHEP::Hep2Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by CheckOrder().

◆ IsTwisted()

G4bool G4GenericTrap::IsTwisted ( ) const
inline

◆ MakeDownFacet()

G4VFacet * G4GenericTrap::MakeDownFacet ( const std::vector< G4ThreeVector > &  fromVertices,
G4int  ind1,
G4int  ind2,
G4int  ind3 
) const
private

Definition at line 1796 of file G4GenericTrap.cc.

1798{
1799 // Create a triangular facet from the polygon points given by indices
1800 // forming the down side ( the normal goes in -z)
1801 // Do not create facet if 2 vertices are the same
1802
1803 if ( (fromVertices[ind1] == fromVertices[ind2]) ||
1804 (fromVertices[ind2] == fromVertices[ind3]) ||
1805 (fromVertices[ind1] == fromVertices[ind3]) ) { return 0; }
1806
1807 std::vector<G4ThreeVector> vertices;
1808 vertices.push_back(fromVertices[ind1]);
1809 vertices.push_back(fromVertices[ind2]);
1810 vertices.push_back(fromVertices[ind3]);
1811
1812 // first vertex most left
1813 //
1814 G4ThreeVector cross=(vertices[1]-vertices[0]).cross(vertices[2]-vertices[1]);
1815
1816 if ( cross.z() > 0.0 )
1817 {
1818 // Should not happen, as vertices should have been reordered at this stage
1819
1820 std::ostringstream message;
1821 message << "Vertices in wrong order - " << GetName();
1822 G4Exception("G4GenericTrap::MakeDownFacet", "GeomSolids0002",
1823 FatalException, message);
1824 }
1825
1826 return new G4TriangularFacet(vertices[0], vertices[1], vertices[2], ABSOLUTE);
1827}
@ ABSOLUTE
Definition: G4VFacet.hh:48

References ABSOLUTE, FatalException, G4Exception(), G4VSolid::GetName(), and CLHEP::Hep3Vector::z().

Referenced by CreateTessellatedSolid().

◆ MakeSideFacet()

G4VFacet * G4GenericTrap::MakeSideFacet ( const G4ThreeVector downVertex0,
const G4ThreeVector downVertex1,
const G4ThreeVector upVertex1,
const G4ThreeVector upVertex0 
) const
private

Definition at line 1869 of file G4GenericTrap.cc.

1873{
1874 // Creates a triangular facet from the polygon points given by indices
1875 // forming the upper side ( z>0 )
1876
1877 if ( (downVertex0 == downVertex1) && (upVertex0 == upVertex1) )
1878 {
1879 return nullptr;
1880 }
1881
1882 if ( downVertex0 == downVertex1 )
1883 {
1884 return new G4TriangularFacet(downVertex0, upVertex1, upVertex0, ABSOLUTE);
1885 }
1886
1887 if ( upVertex0 == upVertex1 )
1888 {
1889 return new G4TriangularFacet(downVertex0, downVertex1, upVertex0, ABSOLUTE);
1890 }
1891
1892 return new G4QuadrangularFacet(downVertex0, downVertex1,
1893 upVertex1, upVertex0, ABSOLUTE);
1894}

References ABSOLUTE.

Referenced by CreateTessellatedSolid().

◆ MakeUpFacet()

G4VFacet * G4GenericTrap::MakeUpFacet ( const std::vector< G4ThreeVector > &  fromVertices,
G4int  ind1,
G4int  ind2,
G4int  ind3 
) const
private

Definition at line 1832 of file G4GenericTrap.cc.

1834{
1835 // Create a triangular facet from the polygon points given by indices
1836 // forming the upper side ( z>0 )
1837
1838 // Do not create facet if 2 vertices are the same
1839 //
1840 if ( (fromVertices[ind1] == fromVertices[ind2]) ||
1841 (fromVertices[ind2] == fromVertices[ind3]) ||
1842 (fromVertices[ind1] == fromVertices[ind3]) ) { return nullptr; }
1843
1844 std::vector<G4ThreeVector> vertices;
1845 vertices.push_back(fromVertices[ind1]);
1846 vertices.push_back(fromVertices[ind2]);
1847 vertices.push_back(fromVertices[ind3]);
1848
1849 // First vertex most left
1850 //
1851 G4ThreeVector cross=(vertices[1]-vertices[0]).cross(vertices[2]-vertices[1]);
1852
1853 if ( cross.z() < 0.0 )
1854 {
1855 // Should not happen, as vertices should have been reordered at this stage
1856
1857 std::ostringstream message;
1858 message << "Vertices in wrong order - " << GetName();
1859 G4Exception("G4GenericTrap::MakeUpFacet", "GeomSolids0002",
1860 FatalException, message);
1861 }
1862
1863 return new G4TriangularFacet(vertices[0], vertices[1], vertices[2], ABSOLUTE);
1864}

References ABSOLUTE, FatalException, G4Exception(), G4VSolid::GetName(), and CLHEP::Hep3Vector::z().

Referenced by CreateTessellatedSolid().

◆ NormalToPlane()

G4ThreeVector G4GenericTrap::NormalToPlane ( const G4ThreeVector p,
const G4int  ipl 
) const
private

Definition at line 489 of file G4GenericTrap.cc.

491{
492 // Return normal to given lateral plane ipl
493
494#ifdef G4TESS_TEST
495 if ( fTessellatedSolid )
496 {
498 }
499#endif
500
501 G4ThreeVector lnorm, norm(0.,0.,0.), p0,p1,p2;
502
503 G4double distz = fDz-p.z();
504 G4int i=ipl; // current plane index
505
506 G4TwoVector u,v;
507 G4ThreeVector r1,r2,r3,r4;
508 G4double cf = 0.5*(fDz-p.z())/fDz;
509 G4int j=(i+1)%4;
510
511 u=fVertices[i+4]+cf*(fVertices[i]-fVertices[i+4]);
512 v=fVertices[j+4]+cf*(fVertices[j]-fVertices[j+4]);
513
514 // Compute cross product
515 //
516 p0=G4ThreeVector(u.x(),u.y(),p.z());
517
518 if (std::fabs(distz)<halfCarTolerance)
519 {
520 p1=G4ThreeVector(fVertices[i].x(),fVertices[i].y(),-fDz);
521 distz=-1;
522 }
523 else
524 {
525 p1=G4ThreeVector(fVertices[i+4].x(),fVertices[i+4].y(),fDz);
526 }
527 p2=G4ThreeVector(v.x(),v.y(),p.z());
528
529 // Collapsed vertices
530 //
531 if ( (p2-p0).mag2() < kCarTolerance )
532 {
533 if ( std::fabs(p.z()+fDz) > halfCarTolerance )
534 {
535 p2=G4ThreeVector(fVertices[j].x(),fVertices[j].y(),-fDz);
536 }
537 else
538 {
539 p2=G4ThreeVector(fVertices[j+4].x(),fVertices[j+4].y(),fDz);
540 }
541 }
542 lnorm=-(p1-p0).cross(p2-p0);
543 if (distz>-halfCarTolerance) { lnorm=-lnorm.unit(); }
544 else { lnorm=lnorm.unit(); }
545
546 // Adjust Normal for Twisted Surface
547 //
548 if( (fIsTwisted) && (GetTwistAngle(ipl)!=0) )
549 {
550 G4double normP=(p2-p0).mag();
551 if(normP)
552 {
553 G4double proj=(p-p0).dot(p2-p0)/normP;
554 if (proj<0) { proj=0; }
555 if (proj>normP) { proj=normP; }
556
557 r1=G4ThreeVector(fVertices[i+4].x(),fVertices[i+4].y(),fDz);
558 r2=G4ThreeVector(fVertices[j+4].x(),fVertices[j+4].y(),fDz);
559 r3=G4ThreeVector(fVertices[i].x(),fVertices[i].y(),-fDz);
560 r4=G4ThreeVector(fVertices[j].x(),fVertices[j].y(),-fDz);
561 r1=r1+proj*(r2-r1)/normP;
562 r3=r3+proj*(r4-r3)/normP;
563 r2=r1-r3;
564 r4=r2.cross(p2-p0);r4=r4.unit();
565 lnorm=r4;
566 }
567 } // End if fIsTwisted
568
569 return lnorm;
570}
Hep3Vector unit() const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const

References CLHEP::Hep3Vector::cross(), fDz, fIsTwisted, fTessellatedSolid, fVertices, GetTwistAngle(), halfCarTolerance, G4VSolid::kCarTolerance, G4TessellatedSolid::SurfaceNormal(), CLHEP::Hep3Vector::unit(), CLHEP::Hep2Vector::x(), CLHEP::Hep2Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by DistanceToOut(), DistToPlane(), DistToTriangle(), and SafetyToFace().

◆ operator=()

G4GenericTrap & G4GenericTrap::operator= ( const G4GenericTrap rhs)

Definition at line 183 of file G4GenericTrap.cc.

184{
185 // Check assignment to self
186 //
187 if (this == &rhs) { return *this; }
188
189 // Copy base class data
190 //
192
193 // Copy data
194 //
196 fDz = rhs.fDz; fVertices = rhs.fVertices;
197 fIsTwisted = rhs.fIsTwisted; fTessellatedSolid = nullptr;
201
202 for (auto i=0; i<4; ++i) { fTwist[i] = rhs.fTwist[i]; }
203#ifdef G4TESS_TEST
204 if (rhs.fTessellatedSolid && !fIsTwisted )
206#endif
207 fRebuildPolyhedron = false;
208 delete fpPolyhedron; fpPolyhedron = nullptr;
209
210 return *this;
211}
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:107

References CreateTessellatedSolid(), fCubicVolume, fDz, fIsTwisted, fMaxBBoxVector, fMinBBoxVector, fpPolyhedron, fRebuildPolyhedron, fSurfaceArea, fTessellatedSolid, fTwist, fVertices, fVisSubdivisions, halfCarTolerance, and G4VSolid::operator=().

◆ operator==()

G4bool G4VSolid::operator== ( const G4VSolid s) const
inlineinherited

◆ ReorderVertices()

void G4GenericTrap::ReorderVertices ( std::vector< G4ThreeVector > &  vertices) const
private

Definition at line 1641 of file G4GenericTrap.cc.

1642{
1643 // Reorder the vector of vertices
1644
1645 std::vector<G4ThreeVector> oldVertices(vertices);
1646
1647 for ( size_t i=0; i<oldVertices.size(); ++i )
1648 {
1649 vertices[i] = oldVertices[oldVertices.size()-1-i];
1650 }
1651}

Referenced by CreateTessellatedSolid().

◆ SafetyToFace()

G4double G4GenericTrap::SafetyToFace ( const G4ThreeVector p,
const G4int  iseg 
) const
private

Definition at line 830 of file G4GenericTrap.cc.

831{
832 // Estimate distance to lateral plane defined by segment iseg in range [0,3]
833 // Might be negative: plane seen only from inside
834
835 G4ThreeVector p1,norm;
836 G4double safe;
837
838 p1=G4ThreeVector(fVertices[iseg].x(),fVertices[iseg].y(),-fDz);
839
840 norm=NormalToPlane(p,iseg);
841 safe = (p-p1).dot(norm); // Can be negative
842
843 return safe;
844}

References fDz, fVertices, and NormalToPlane().

Referenced by DistanceToIn(), and DistanceToOut().

◆ SetName()

void G4VSolid::SetName ( const G4String name)
inherited

◆ SetTwistAngle()

void G4GenericTrap::SetTwistAngle ( G4int  index,
G4double  twist 
)
inlineprivate

Referenced by ComputeIsTwisted().

◆ SetVisSubdivisions()

void G4GenericTrap::SetVisSubdivisions ( G4int  subdiv)
inline

◆ StreamInfo()

std::ostream & G4GenericTrap::StreamInfo ( std::ostream &  os) const
virtual

Implements G4VSolid.

Definition at line 1273 of file G4GenericTrap.cc.

1274{
1275 G4int oldprc = os.precision(16);
1276 os << "-----------------------------------------------------------\n"
1277 << " *** Dump for solid - " << GetName() << " *** \n"
1278 << " =================================================== \n"
1279 << " Solid geometry type: " << GetEntityType() << G4endl
1280 << " half length Z: " << fDz/mm << " mm \n"
1281 << " list of vertices:\n";
1282
1283 for ( G4int i=0; i<fgkNofVertices; ++i )
1284 {
1285 os << std::setw(5) << "#" << i
1286 << " vx = " << fVertices[i].x()/mm << " mm"
1287 << " vy = " << fVertices[i].y()/mm << " mm" << G4endl;
1288 }
1289 os.precision(oldprc);
1290
1291 return os;
1292}
G4GeometryType GetEntityType() const

References fDz, fgkNofVertices, fVertices, G4endl, GetEntityType(), G4VSolid::GetName(), and mm.

◆ SurfaceNormal()

G4ThreeVector G4GenericTrap::SurfaceNormal ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Definition at line 354 of file G4GenericTrap.cc.

355{
356 // Calculate side nearest to p, and return normal
357 // If two sides are equidistant, sum of the Normal is returned
358
359#ifdef G4TESS_TEST
360 if ( fTessellatedSolid )
361 {
363 }
364#endif
365
366 G4ThreeVector lnorm, sumnorm(0.,0.,0.), apprnorm(0.,0.,1.),
367 p0, p1, p2, r1, r2, r3, r4;
368 G4int noSurfaces = 0;
369 G4double distxy,distz;
370 G4bool zPlusSide=false;
371
372 distz = fDz-std::fabs(p.z());
373 if (distz < halfCarTolerance)
374 {
375 if(p.z()>0)
376 {
377 zPlusSide=true;
378 sumnorm=G4ThreeVector(0,0,1);
379 }
380 else
381 {
382 sumnorm=G4ThreeVector(0,0,-1);
383 }
384 ++noSurfaces;
385 }
386
387 // Check lateral planes
388 //
389 std:: vector<G4TwoVector> vertices;
390 G4double cf = 0.5*(fDz-p.z())/fDz;
391 for (auto i=0; i<4; ++i)
392 {
393 vertices.push_back(fVertices[i+4]+cf*(fVertices[i]-fVertices[i+4]));
394 }
395
396 // Compute distance for lateral planes
397 //
398 for (G4int q=0; q<4; ++q)
399 {
400 p0=G4ThreeVector(vertices[q].x(),vertices[q].y(),p.z());
401 if(zPlusSide)
402 {
403 p1=G4ThreeVector(fVertices[q].x(),fVertices[q].y(),-fDz);
404 }
405 else
406 {
407 p1=G4ThreeVector(fVertices[q+4].x(),fVertices[q+4].y(),fDz);
408 }
409 p2=G4ThreeVector(vertices[(q+1)%4].x(),vertices[(q+1)%4].y(),p.z());
410
411 // Collapsed vertices
412 //
413 if ( (p2-p0).mag2() < kCarTolerance )
414 {
415 if ( std::fabs(p.z()+fDz) > kCarTolerance )
416 {
417 p2=G4ThreeVector(fVertices[(q+1)%4].x(),fVertices[(q+1)%4].y(),-fDz);
418 }
419 else
420 {
421 p2=G4ThreeVector(fVertices[(q+1)%4+4].x(),fVertices[(q+1)%4+4].y(),fDz);
422 }
423 }
424 lnorm = (p1-p0).cross(p2-p0);
425 lnorm = lnorm.unit();
426 if(zPlusSide) { lnorm=-lnorm; }
427
428 // Adjust Normal for Twisted Surface
429 //
430 if ( (fIsTwisted) && (GetTwistAngle(q)!=0) )
431 {
432 G4double normP=(p2-p0).mag();
433 if(normP)
434 {
435 G4double proj=(p-p0).dot(p2-p0)/normP;
436 if(proj<0) { proj=0; }
437 if(proj>normP) { proj=normP; }
438 G4int j=(q+1)%4;
439 r1=G4ThreeVector(fVertices[q+4].x(),fVertices[q+4].y(),fDz);
440 r2=G4ThreeVector(fVertices[j+4].x(),fVertices[j+4].y(),fDz);
441 r3=G4ThreeVector(fVertices[q].x(),fVertices[q].y(),-fDz);
442 r4=G4ThreeVector(fVertices[j].x(),fVertices[j].y(),-fDz);
443 r1=r1+proj*(r2-r1)/normP;
444 r3=r3+proj*(r4-r3)/normP;
445 r2=r1-r3;
446 r4=r2.cross(p2-p0); r4=r4.unit();
447 lnorm=r4;
448 }
449 } // End if fIsTwisted
450
451 distxy=std::fabs((p0-p).dot(lnorm));
452 if ( distxy<halfCarTolerance )
453 {
454 ++noSurfaces;
455
456 // Negative sign for Normal is taken for Outside Normal
457 //
458 sumnorm=sumnorm+lnorm;
459 }
460
461 // For ApproxSurfaceNormal
462 //
463 if (distxy<distz)
464 {
465 distz=distxy;
466 apprnorm=lnorm;
467 }
468 } // End for loop
469
470 // Calculate final Normal, add Normal in the Corners and Touching Sides
471 //
472 if ( noSurfaces == 0 )
473 {
474#ifdef G4SPECSDEBUG
475 G4Exception("G4GenericTrap::SurfaceNormal(p)", "GeomSolids1002",
476 JustWarning, "Point p is not on surface !?" );
477#endif
478 sumnorm=apprnorm;
479 // Add Approximative Surface Normal Calculation?
480 }
481 else if ( noSurfaces == 1 ) { ; }
482 else { sumnorm = sumnorm.unit(); }
483
484 return sumnorm ;
485}

References CLHEP::Hep3Vector::cross(), fDz, fIsTwisted, fTessellatedSolid, fVertices, G4Exception(), GetTwistAngle(), halfCarTolerance, JustWarning, G4VSolid::kCarTolerance, G4TessellatedSolid::SurfaceNormal(), CLHEP::Hep3Vector::unit(), and CLHEP::Hep3Vector::z().

Field Documentation

◆ fCubicVolume

G4double G4GenericTrap::fCubicVolume = 0.0
private

Definition at line 225 of file G4GenericTrap.hh.

Referenced by GetCubicVolume(), and operator=().

◆ fDz

G4double G4GenericTrap::fDz
private

◆ fgkNofVertices

const G4int G4GenericTrap::fgkNofVertices = 8
staticprivate

◆ fgkTolerance

const G4double G4GenericTrap::fgkTolerance = 1E-3
staticprivate

Definition at line 206 of file G4GenericTrap.hh.

Referenced by CheckOrder(), ComputeIsTwisted(), and IsSegCrossing().

◆ fIsTwisted

G4bool G4GenericTrap::fIsTwisted = false
private

◆ fMaxBBoxVector

G4ThreeVector G4GenericTrap::fMaxBBoxVector
private

Definition at line 218 of file G4GenericTrap.hh.

Referenced by ComputeBBox(), and operator=().

◆ fMinBBoxVector

G4ThreeVector G4GenericTrap::fMinBBoxVector
private

Definition at line 217 of file G4GenericTrap.hh.

Referenced by ComputeBBox(), and operator=().

◆ fpPolyhedron

G4Polyhedron* G4GenericTrap::fpPolyhedron = nullptr
mutableprotected

Definition at line 199 of file G4GenericTrap.hh.

Referenced by GetPolyhedron(), and operator=().

◆ fRebuildPolyhedron

G4bool G4GenericTrap::fRebuildPolyhedron = false
mutableprotected

Definition at line 198 of file G4GenericTrap.hh.

Referenced by GetPolyhedron(), and operator=().

◆ fshapeName

G4String G4VSolid::fshapeName
privateinherited

Definition at line 312 of file G4VSolid.hh.

Referenced by G4VSolid::operator=(), and G4VSolid::SetName().

◆ fSurfaceArea

G4double G4GenericTrap::fSurfaceArea = 0.0
private

Definition at line 224 of file G4GenericTrap.hh.

Referenced by GetSurfaceArea(), and operator=().

◆ fTessellatedSolid

G4TessellatedSolid* G4GenericTrap::fTessellatedSolid = nullptr
private

◆ fTwist

G4double G4GenericTrap::fTwist[4]
private

Definition at line 215 of file G4GenericTrap.hh.

Referenced by G4GenericTrap(), and operator=().

◆ fVertices

std::vector<G4TwoVector> G4GenericTrap::fVertices
private

◆ fVisSubdivisions

G4int G4GenericTrap::fVisSubdivisions = 0
private

Definition at line 219 of file G4GenericTrap.hh.

Referenced by operator=().

◆ halfCarTolerance

G4double G4GenericTrap::halfCarTolerance
private

◆ kCarTolerance

G4double G4VSolid::kCarTolerance
protectedinherited

Definition at line 299 of file G4VSolid.hh.

Referenced by G4TessellatedSolid::AddFacet(), G4Polycone::CalculateExtent(), G4Polyhedra::CalculateExtent(), G4Tet::CheckDegeneracy(), G4Para::CheckParameters(), G4Trd::CheckParameters(), G4Ellipsoid::CheckParameters(), G4EllipticalTube::CheckParameters(), ComputeIsTwisted(), G4Polyhedra::Create(), G4GenericPolycone::Create(), G4Polycone::Create(), G4CutTubs::CreatePolyhedron(), G4TessellatedSolid::CreateVertexList(), G4VCSGfaceted::DistanceTo(), G4Sphere::DistanceToIn(), G4Ellipsoid::DistanceToIn(), G4Hype::DistanceToIn(), G4Paraboloid::DistanceToIn(), G4VCSGfaceted::DistanceToIn(), G4TessellatedSolid::DistanceToInCore(), G4Cons::DistanceToOut(), G4CutTubs::DistanceToOut(), G4Sphere::DistanceToOut(), G4Torus::DistanceToOut(), G4Tubs::DistanceToOut(), DistanceToOut(), G4Hype::DistanceToOut(), G4Paraboloid::DistanceToOut(), G4VCSGfaceted::DistanceToOut(), G4TessellatedSolid::DistanceToOutCandidates(), G4TessellatedSolid::DistanceToOutCore(), G4TessellatedSolid::DistanceToOutNoVoxels(), DistToPlane(), DistToTriangle(), G4Box::G4Box(), G4Cons::G4Cons(), G4CutTubs::G4CutTubs(), G4EllipticalCone::G4EllipticalCone(), G4ExtrudedSolid::G4ExtrudedSolid(), G4GenericTrap(), G4Hype::G4Hype(), G4Para::G4Para(), G4Sphere::G4Sphere(), G4Tet::G4Tet(), G4Trap::G4Trap(), G4Tubs::G4Tubs(), G4UnionSolid::G4UnionSolid(), G4VSolid::G4VSolid(), G4VTwistedFaceted::G4VTwistedFaceted(), G4GenericPolycone::GetPointOnSurface(), G4Polycone::GetPointOnSurface(), G4UnionSolid::Init(), G4Orb::Initialize(), G4TessellatedSolid::Initialize(), G4SubtractionSolid::Inside(), G4Hype::Inside(), G4Paraboloid::Inside(), G4VCSGfaceted::Inside(), G4VTwistedFaceted::Inside(), G4TessellatedSolid::InsideNoVoxels(), InsidePolygone(), G4TessellatedSolid::InsideVoxels(), G4CutTubs::IsCrossingCutPlanes(), IsSegCrossingZ(), G4Trap::MakePlane(), NormalToPlane(), G4VSolid::operator=(), G4TessellatedSolid::SafetyFromInside(), G4TessellatedSolid::SafetyFromOutside(), G4Torus::SetAllParameters(), G4Polycone::SetOriginalParameters(), G4Polyhedra::SetOriginalParameters(), G4Box::SetXHalfLength(), G4Box::SetYHalfLength(), G4Box::SetZHalfLength(), G4Torus::SurfaceNormal(), SurfaceNormal(), and G4Paraboloid::SurfaceNormal().


The documentation for this class was generated from the following files: