Geant4-11
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | Friends
G4PolyhedraSide Class Reference

#include <G4PolyhedraSide.hh>

Inheritance diagram for G4PolyhedraSide:
G4VCSGface

Data Structures

struct  sG4PolyhedraSideEdge
 
struct  sG4PolyhedraSideVec
 

Public Types

typedef struct G4PolyhedraSide::sG4PolyhedraSideEdge G4PolyhedraSideEdge
 
typedef struct G4PolyhedraSide::sG4PolyhedraSideVec G4PolyhedraSideVec
 

Public Member Functions

void CalculateExtent (const EAxis axis, const G4VoxelLimits &voxelLimit, const G4AffineTransform &tranform, G4SolidExtentList &extentList)
 
G4VCSGfaceClone ()
 
G4double Distance (const G4ThreeVector &p, G4bool outgoing)
 
G4double Extent (const G4ThreeVector axis)
 
 G4PolyhedraSide (__void__ &)
 
 G4PolyhedraSide (const G4PolyhedraSide &source)
 
 G4PolyhedraSide (const G4PolyhedraSideRZ *prevRZ, const G4PolyhedraSideRZ *tail, const G4PolyhedraSideRZ *head, const G4PolyhedraSideRZ *nextRZ, G4int numSide, G4double phiStart, G4double phiTotal, G4bool phiIsOpen, G4bool isAllBehind=false)
 
G4int GetInstanceID () const
 
G4ThreeVector GetPointOnFace ()
 
G4ThreeVector GetPointOnPlane (G4ThreeVector p0, G4ThreeVector p1, G4ThreeVector p2, G4ThreeVector p3, G4double *Area)
 
EInside Inside (const G4ThreeVector &p, G4double tolerance, G4double *bestDistance)
 
G4bool Intersect (const G4ThreeVector &p, const G4ThreeVector &v, G4bool outgoing, G4double surfTolerance, G4double &distance, G4double &distFromSurface, G4ThreeVector &normal, G4bool &allBehind)
 
G4ThreeVector Normal (const G4ThreeVector &p, G4double *bestDistance)
 
G4PolyhedraSideoperator= (const G4PolyhedraSide &source)
 
G4double SurfaceArea ()
 
G4double SurfaceTriangle (G4ThreeVector p1, G4ThreeVector p2, G4ThreeVector p3, G4ThreeVector *p4)
 
virtual ~G4PolyhedraSide ()
 

Static Public Member Functions

static const G4PhSideManagerGetSubInstanceManager ()
 

Protected Member Functions

G4int ClosestPhiSegment (G4double phi)
 
void CopyStuff (const G4PolyhedraSide &source)
 
G4double DistanceAway (const G4ThreeVector &p, const G4PolyhedraSideVec &vec, G4double *normDist)
 
G4double DistanceToOneSide (const G4ThreeVector &p, const G4PolyhedraSideVec &vec, G4double *normDist)
 
G4double GetPhi (const G4ThreeVector &p)
 
G4bool IntersectSidePlane (const G4ThreeVector &p, const G4ThreeVector &v, const G4PolyhedraSideVec &vec, G4double normSign, G4double surfTolerance, G4double &distance, G4double &distFromSurface)
 
G4int LineHitsSegments (const G4ThreeVector &p, const G4ThreeVector &v, G4int *i1, G4int *i2)
 
G4int PhiSegment (G4double phi)
 

Protected Attributes

G4bool allBehind = false
 
G4IntersectingConecone = nullptr
 
G4double deltaPhi
 
G4double edgeNorm
 
G4PolyhedraSideEdgeedges = nullptr
 
G4double endPhi
 
G4double lenPhi [2]
 
G4double lenRZ
 
G4int numSide = 0
 
G4bool phiIsOpen = false
 
G4double r [2]
 
G4double startPhi
 
G4PolyhedraSideVecvecs = nullptr
 
G4double z [2]
 

Private Attributes

G4double fSurfaceArea = 0.0
 
G4int instanceID
 
G4double kCarTolerance
 

Static Private Attributes

static G4GEOM_DLL G4PhSideManager subInstanceManager
 

Friends

struct sG4PolyhedraSideVec
 

Detailed Description

Definition at line 88 of file G4PolyhedraSide.hh.

Member Typedef Documentation

◆ G4PolyhedraSideEdge

◆ G4PolyhedraSideVec

Constructor & Destructor Documentation

◆ G4PolyhedraSide() [1/3]

G4PolyhedraSide::G4PolyhedraSide ( const G4PolyhedraSideRZ prevRZ,
const G4PolyhedraSideRZ tail,
const G4PolyhedraSideRZ head,
const G4PolyhedraSideRZ nextRZ,
G4int  numSide,
G4double  phiStart,
G4double  phiTotal,
G4bool  phiIsOpen,
G4bool  isAllBehind = false 
)

Definition at line 66 of file G4PolyhedraSide.cc.

75{
76
78
80 G4MT_phphix = 0.0; G4MT_phphiy = 0.0; G4MT_phphiz = 0.0;
81 G4MT_phphik = 0.0;
82
83 //
84 // Record values
85 //
86 r[0] = tail->r; z[0] = tail->z;
87 r[1] = head->r; z[1] = head->z;
88
89 G4double phiTotal;
90
91 //
92 // Set phi to our convention
93 //
94 startPhi = thePhiStart;
95 while (startPhi < 0.0) // Loop checking, 13.08.2015, G.Cosmo
96 startPhi += twopi;
97
98 phiIsOpen = thePhiIsOpen;
99 phiTotal = (phiIsOpen) ? thePhiTotal : twopi;
100
101 allBehind = isAllBehind;
102
103 //
104 // Make our intersecting cone
105 //
106 cone = new G4IntersectingCone( r, z );
107
108 //
109 // Construct side plane vector set
110 //
111 numSide = theNumSide;
112 deltaPhi = phiTotal/theNumSide;
113 endPhi = startPhi+phiTotal;
114
116
118
119 //
120 // ...this is where we start
121 //
122 G4double phi = startPhi;
123 G4ThreeVector a1( r[0]*std::cos(phi), r[0]*std::sin(phi), z[0] ),
124 b1( r[1]*std::cos(phi), r[1]*std::sin(phi), z[1] ),
125 c1( prevRZ->r*std::cos(phi), prevRZ->r*std::sin(phi), prevRZ->z ),
126 d1( nextRZ->r*std::cos(phi), nextRZ->r*std::sin(phi), nextRZ->z ),
127 a2, b2, c2, d2;
129
131 do // Loop checking, 13.08.2015, G.Cosmo
132 {
133 //
134 // ...this is where we are going
135 //
136 phi += deltaPhi;
137 a2 = G4ThreeVector( r[0]*std::cos(phi), r[0]*std::sin(phi), z[0] );
138 b2 = G4ThreeVector( r[1]*std::cos(phi), r[1]*std::sin(phi), z[1] );
139 c2 = G4ThreeVector( prevRZ->r*std::cos(phi), prevRZ->r*std::sin(phi), prevRZ->z );
140 d2 = G4ThreeVector( nextRZ->r*std::cos(phi), nextRZ->r*std::sin(phi), nextRZ->z );
141
142 G4ThreeVector tt;
143
144 //
145 // ...build some relevant vectors.
146 // the point is to sacrifice a little memory with precalcs
147 // to gain speed
148 //
149 vec->center = 0.25*( a1 + a2 + b1 + b2 );
150
151 tt = b2 + b1 - a2 - a1;
152 vec->surfRZ = tt.unit();
153 if (vec==vecs) lenRZ = 0.25*tt.mag();
154
155 tt = b2 - b1 + a2 - a1;
156 vec->surfPhi = tt.unit();
157 if (vec==vecs)
158 {
159 lenPhi[0] = 0.25*tt.mag();
160 tt = b2 - b1;
161 lenPhi[1] = (0.5*tt.mag()-lenPhi[0])/lenRZ;
162 }
163
164 tt = vec->surfPhi.cross(vec->surfRZ);
165 vec->normal = tt.unit();
166
167 //
168 // ...edge normals are the average of the normals of
169 // the two faces they connect.
170 //
171 // ...edge normals are necessary if we are to accurately
172 // decide if a point is "inside" a face. For non-convex
173 // shapes, it is absolutely necessary to know information
174 // on adjacent faces to accurate determine this.
175 //
176 // ...we don't need them for the phi edges, since that
177 // information is taken care of internally. The r/z edges,
178 // however, depend on the adjacent G4PolyhedraSide.
179 //
180 G4ThreeVector a12, adj;
181
182 a12 = a2-a1;
183
184 adj = 0.5*(c1+c2-a1-a2);
185 adj = adj.cross(a12);
186 adj = adj.unit() + vec->normal;
187 vec->edgeNorm[0] = adj.unit();
188
189 a12 = b1-b2;
190 adj = 0.5*(d1+d2-b1-b2);
191 adj = adj.cross(a12);
192 adj = adj.unit() + vec->normal;
193 vec->edgeNorm[1] = adj.unit();
194
195 //
196 // ...the corners are crucial. It is important that
197 // they are calculated consistently for adjacent
198 // G4PolyhedraSides, to avoid gaps caused by roundoff.
199 //
200 vec->edges[0] = edge;
201 edge->corner[0] = a1;
202 edge->corner[1] = b1;
203 edge++;
204 vec->edges[1] = edge;
205
206 a1 = a2;
207 b1 = b2;
208 c1 = c2;
209 d1 = d2;
210 } while( ++vec < vecs+numSide );
211
212 //
213 // Clean up hanging edge
214 //
215 if (phiIsOpen)
216 {
217 edge->corner[0] = a2;
218 edge->corner[1] = b2;
219 }
220 else
221 {
222 vecs[numSide-1].edges[1] = edges;
223 }
224
225 //
226 // Go back and fill in remaining fields in edges
227 //
228 vec = vecs;
230 do // Loop checking, 13.08.2015, G.Cosmo
231 {
232 edge = vec->edges[0]; // The edge between prev and vec
233
234 //
235 // Okay: edge normal is average of normals of adjacent faces
236 //
237 G4ThreeVector eNorm = vec->normal + prev->normal;
238 edge->normal = eNorm.unit();
239
240 //
241 // Vertex normal is average of norms of adjacent surfaces (all four)
242 // However, vec->edgeNorm is unit vector in some direction
243 // as the sum of normals of adjacent PolyhedraSide with vec.
244 // The normalization used for this vector should be the same
245 // for vec and prev.
246 //
247 eNorm = vec->edgeNorm[0] + prev->edgeNorm[0];
248 edge->cornNorm[0] = eNorm.unit();
249
250 eNorm = vec->edgeNorm[1] + prev->edgeNorm[1];
251 edge->cornNorm[1] = eNorm.unit();
252 } while( prev=vec, ++vec < vecs + numSide );
253
254 if (phiIsOpen)
255 {
256 // G4double rFact = std::cos(0.5*deltaPhi);
257 //
258 // If phi is open, we need to patch up normals of the
259 // first and last edges and their corresponding
260 // vertices.
261 //
262 // We use vectors that are in the plane of the
263 // face. This should be safe.
264 //
265 vec = vecs;
266
267 G4ThreeVector normvec = vec->edges[0]->corner[0]
268 - vec->edges[0]->corner[1];
269 normvec = normvec.cross(vec->normal);
270 if (normvec.dot(vec->surfPhi) > 0) normvec = -normvec;
271
272 vec->edges[0]->normal = normvec.unit();
273
274 vec->edges[0]->cornNorm[0] = (vec->edges[0]->corner[0]
275 - vec->center).unit();
276 vec->edges[0]->cornNorm[1] = (vec->edges[0]->corner[1]
277 - vec->center).unit();
278
279 //
280 // Repeat for ending phi
281 //
282 vec = vecs + numSide - 1;
283
284 normvec = vec->edges[1]->corner[0] - vec->edges[1]->corner[1];
285 normvec = normvec.cross(vec->normal);
286 if (normvec.dot(vec->surfPhi) < 0) normvec = -normvec;
287
288 vec->edges[1]->normal = normvec.unit();
289
290 vec->edges[1]->cornNorm[0] = (vec->edges[1]->corner[0]
291 - vec->center).unit();
292 vec->edges[1]->cornNorm[1] = (vec->edges[1]->corner[1]
293 - vec->center).unit();
294 }
295
296 //
297 // edgeNorm is the factor one multiplies the distance along vector phi
298 // on the surface of one of our sides in order to calculate the distance
299 // from the edge. (see routine DistanceAway)
300 //
301 edgeNorm = 1.0/std::sqrt( 1.0 + lenPhi[1]*lenPhi[1] );
302}
static const G4double d1
static const G4double d2
#define G4MT_phphix
#define G4MT_phphiz
#define G4MT_phphiy
#define G4MT_phphik
static constexpr double twopi
Definition: G4SIunits.hh:56
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
Hep3Vector unit() const
Hep3Vector cross(const Hep3Vector &) const
double dot(const Hep3Vector &) const
double mag() const
G4int CreateSubInstance()
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
G4PolyhedraSideVec * vecs
G4PolyhedraSideEdge * edges
struct G4PolyhedraSide::sG4PolyhedraSideVec G4PolyhedraSideVec
G4double lenPhi[2]
struct G4PolyhedraSide::sG4PolyhedraSideEdge G4PolyhedraSideEdge
static G4GEOM_DLL G4PhSideManager subInstanceManager
G4IntersectingCone * cone

References allBehind, G4PolyhedraSide::sG4PolyhedraSideVec::center, cone, G4PolyhedraSide::sG4PolyhedraSideEdge::corner, G4PolyhedraSide::sG4PolyhedraSideEdge::cornNorm, G4GeomSplitter< T >::CreateSubInstance(), CLHEP::Hep3Vector::cross(), d1, d2, deltaPhi, CLHEP::Hep3Vector::dot(), G4PolyhedraSide::sG4PolyhedraSideVec::edgeNorm, edgeNorm, G4PolyhedraSide::sG4PolyhedraSideVec::edges, edges, endPhi, G4MT_phphik, G4MT_phphix, G4MT_phphiy, G4MT_phphiz, G4GeometryTolerance::GetInstance(), G4GeometryTolerance::GetSurfaceTolerance(), instanceID, kCarTolerance, lenPhi, lenRZ, CLHEP::Hep3Vector::mag(), G4PolyhedraSide::sG4PolyhedraSideEdge::normal, G4PolyhedraSide::sG4PolyhedraSideVec::normal, numSide, phiIsOpen, G4PolyhedraSideRZ::r, r, startPhi, subInstanceManager, G4PolyhedraSide::sG4PolyhedraSideVec::surfPhi, G4PolyhedraSide::sG4PolyhedraSideVec::surfRZ, twopi, CLHEP::Hep3Vector::unit(), vecs, G4PolyhedraSideRZ::z, and z.

Referenced by Clone().

◆ ~G4PolyhedraSide()

G4PolyhedraSide::~G4PolyhedraSide ( )
virtual

Definition at line 319 of file G4PolyhedraSide.cc.

320{
321 delete cone;
322 delete [] vecs;
323 delete [] edges;
324}

References cone, edges, and vecs.

◆ G4PolyhedraSide() [2/3]

G4PolyhedraSide::G4PolyhedraSide ( const G4PolyhedraSide source)

Definition at line 328 of file G4PolyhedraSide.cc.

329 : G4VCSGface()
330{
332
333 CopyStuff( source );
334}
void CopyStuff(const G4PolyhedraSide &source)

References CopyStuff(), G4GeomSplitter< T >::CreateSubInstance(), instanceID, and subInstanceManager.

◆ G4PolyhedraSide() [3/3]

G4PolyhedraSide::G4PolyhedraSide ( __void__ &  )

Definition at line 307 of file G4PolyhedraSide.cc.

308 : startPhi(0.), deltaPhi(0.), endPhi(0.),
309 lenRZ(0.), edgeNorm(0.), kCarTolerance(0.), instanceID(0)
310{
311 r[0] = r[1] = 0.;
312 z[0] = z[1] = 0.;
313 lenPhi[0] = lenPhi[1] = 0.;
314}

References lenPhi, r, and z.

Member Function Documentation

◆ CalculateExtent()

void G4PolyhedraSide::CalculateExtent ( const EAxis  axis,
const G4VoxelLimits voxelLimit,
const G4AffineTransform tranform,
G4SolidExtentList extentList 
)
virtual

Implements G4VCSGface.

Definition at line 704 of file G4PolyhedraSide.cc.

708{
709 //
710 // Loop over all sides
711 //
713 do // Loop checking, 13.08.2015, G.Cosmo
714 {
715 //
716 // Fill our polygon with the four corners of
717 // this side, after the specified transformation
718 //
719 G4ClippablePolygon polygon;
720
722 TransformPoint(vec->edges[0]->corner[0]));
724 TransformPoint(vec->edges[0]->corner[1]));
726 TransformPoint(vec->edges[1]->corner[1]));
728 TransformPoint(vec->edges[1]->corner[0]));
729
730 //
731 // Get extent
732 //
733 if (polygon.PartialClip( voxelLimit, axis ))
734 {
735 //
736 // Get dot product of normal along target axis
737 //
738 polygon.SetNormal( transform.TransformAxis(vec->normal) );
739
740 extentList.AddSurface( polygon );
741 }
742 } while( ++vec < vecs+numSide );
743
744 return;
745}
virtual G4bool PartialClip(const G4VoxelLimits &voxelLimit, const EAxis IgnoreMe)
virtual void AddVertexInOrder(const G4ThreeVector vertex)
void SetNormal(const G4ThreeVector &newNormal)
void AddSurface(const G4ClippablePolygon &surface)
G4bool transform(G4String &input, const G4String &type)

References G4SolidExtentList::AddSurface(), G4ClippablePolygon::AddVertexInOrder(), G4PolyhedraSide::sG4PolyhedraSideEdge::corner, G4PolyhedraSide::sG4PolyhedraSideVec::edges, G4PolyhedraSide::sG4PolyhedraSideVec::normal, numSide, G4ClippablePolygon::PartialClip(), G4ClippablePolygon::SetNormal(), G4coutFormatters::anonymous_namespace{G4coutFormatters.cc}::transform(), and vecs.

◆ Clone()

G4VCSGface * G4PolyhedraSide::Clone ( )
inlinevirtual

Implements G4VCSGface.

Definition at line 124 of file G4PolyhedraSide.hh.

124{ return new G4PolyhedraSide( *this ); }
G4PolyhedraSide(const G4PolyhedraSideRZ *prevRZ, const G4PolyhedraSideRZ *tail, const G4PolyhedraSideRZ *head, const G4PolyhedraSideRZ *nextRZ, G4int numSide, G4double phiStart, G4double phiTotal, G4bool phiIsOpen, G4bool isAllBehind=false)

References G4PolyhedraSide().

◆ ClosestPhiSegment()

G4int G4PolyhedraSide::ClosestPhiSegment ( G4double  phi)
protected

Definition at line 910 of file G4PolyhedraSide.cc.

911{
912 G4int iPhi = PhiSegment( phi0 );
913 if (iPhi >= 0) return iPhi;
914
915 //
916 // Boogers! The points falls inside the phi segment.
917 // Look for the closest point: the start, or end
918 //
919 G4double phi = phi0;
920
921 while( phi < startPhi ) // Loop checking, 13.08.2015, G.Cosmo
922 phi += twopi;
923 G4double d1 = phi-endPhi;
924
925 while( phi > startPhi ) // Loop checking, 13.08.2015, G.Cosmo
926 phi -= twopi;
927 G4double d2 = startPhi-phi;
928
929 return (d2 < d1) ? 0 : numSide-1;
930}
int G4int
Definition: G4Types.hh:85
G4int PhiSegment(G4double phi)

References d1, d2, endPhi, numSide, PhiSegment(), startPhi, and twopi.

Referenced by Distance(), Inside(), and Normal().

◆ CopyStuff()

void G4PolyhedraSide::CopyStuff ( const G4PolyhedraSide source)
protected

Definition at line 355 of file G4PolyhedraSide.cc.

356{
357 //
358 // The simple stuff
359 //
360 numSide = source.numSide;
361 r[0] = source.r[0];
362 r[1] = source.r[1];
363 z[0] = source.z[0];
364 z[1] = source.z[1];
365 startPhi = source.startPhi;
366 deltaPhi = source.deltaPhi;
367 endPhi = source.endPhi;
368 phiIsOpen = source.phiIsOpen;
369 allBehind = source.allBehind;
370
371 lenRZ = source.lenRZ;
372 lenPhi[0] = source.lenPhi[0];
373 lenPhi[1] = source.lenPhi[1];
374 edgeNorm = source.edgeNorm;
375
376 kCarTolerance = source.kCarTolerance;
377 fSurfaceArea = source.fSurfaceArea;
378
379 cone = new G4IntersectingCone( *source.cone );
380
381 //
382 // Duplicate edges
383 //
384 G4int numEdges = phiIsOpen ? numSide+1 : numSide;
385 edges = new G4PolyhedraSideEdge[numEdges];
386
388 *sourceEdge = source.edges;
389 do // Loop checking, 13.08.2015, G.Cosmo
390 {
391 *edge = *sourceEdge;
392 } while( ++sourceEdge, ++edge < edges + numEdges);
393
394 //
395 // Duplicate vecs
396 //
398
400 *sourceVec = source.vecs;
401 do // Loop checking, 13.08.2015, G.Cosmo
402 {
403 *vec = *sourceVec;
404 vec->edges[0] = edges + (sourceVec->edges[0] - source.edges);
405 vec->edges[1] = edges + (sourceVec->edges[1] - source.edges);
406 } while( ++sourceVec, ++vec < vecs + numSide );
407}

References allBehind, cone, deltaPhi, edgeNorm, G4PolyhedraSide::sG4PolyhedraSideVec::edges, edges, endPhi, fSurfaceArea, kCarTolerance, lenPhi, lenRZ, numSide, phiIsOpen, r, startPhi, vecs, and z.

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

◆ Distance()

G4double G4PolyhedraSide::Distance ( const G4ThreeVector p,
G4bool  outgoing 
)
virtual

Implements G4VCSGface.

Definition at line 569 of file G4PolyhedraSide.cc.

570{
571 G4double normSign = outgoing ? -1 : +1;
572
573 //
574 // Try the closest phi segment first
575 //
576 G4int iPhi = ClosestPhiSegment( GetPhi(p) );
577
578 G4ThreeVector pdotc = p - vecs[iPhi].center;
579 G4double normDist = pdotc.dot(vecs[iPhi].normal);
580
581 if (normSign*normDist > -0.5*kCarTolerance)
582 {
583 return DistanceAway( p, vecs[iPhi], &normDist );
584 }
585
586 //
587 // Now we have an interesting problem... do we try to find the
588 // closest facing side??
589 //
590 // Considered carefully, the answer is no. We know that if we
591 // are asking for the distance out, we are supposed to be inside,
592 // and vice versa.
593 //
594
595 return kInfinity;
596}
G4double GetPhi(const G4ThreeVector &p)
G4int ClosestPhiSegment(G4double phi)
G4double DistanceAway(const G4ThreeVector &p, const G4PolyhedraSideVec &vec, G4double *normDist)
static const G4double kInfinity
Definition: geomdefs.hh:41
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:79

References G4PolyhedraSide::sG4PolyhedraSideVec::center, ClosestPhiSegment(), DistanceAway(), CLHEP::Hep3Vector::dot(), GetPhi(), kCarTolerance, kInfinity, CLHEP::normal(), and vecs.

◆ DistanceAway()

G4double G4PolyhedraSide::DistanceAway ( const G4ThreeVector p,
const G4PolyhedraSideVec vec,
G4double normDist 
)
protected

Definition at line 1024 of file G4PolyhedraSide.cc.

1027{
1028 G4double distOut2;
1029 G4ThreeVector pct = p - vec.center;
1030 G4double distFaceNorm = *normDist;
1031
1032 //
1033 // Okay, are we inside bounds?
1034 //
1035 G4double pcDotRZ = pct.dot(vec.surfRZ);
1036 G4double pcDotPhi = pct.dot(vec.surfPhi);
1037
1038 //
1039 // Go through all permutations.
1040 // Phi
1041 // | | ^
1042 // B | H | E |
1043 // ------[1]------------[3]----- |
1044 // |XXXXXXXXXXXXXX| +----> RZ
1045 // C |XXXXXXXXXXXXXX| F
1046 // |XXXXXXXXXXXXXX|
1047 // ------[0]------------[2]----
1048 // A | G | D
1049 // | |
1050 //
1051 // It's real messy, but at least it's quick
1052 //
1053
1054 if (pcDotRZ < -lenRZ)
1055 {
1056 G4double lenPhiZ = lenPhi[0] - lenRZ*lenPhi[1];
1057 G4double distOutZ = pcDotRZ+lenRZ;
1058 //
1059 // Below in RZ
1060 //
1061 if (pcDotPhi < -lenPhiZ)
1062 {
1063 //
1064 // ...and below in phi. Find distance to point (A)
1065 //
1066 G4double distOutPhi = pcDotPhi+lenPhiZ;
1067 distOut2 = distOutPhi*distOutPhi + distOutZ*distOutZ;
1068 G4ThreeVector pa = p - vec.edges[0]->corner[0];
1069 *normDist = pa.dot(vec.edges[0]->cornNorm[0]);
1070 }
1071 else if (pcDotPhi > lenPhiZ)
1072 {
1073 //
1074 // ...and above in phi. Find distance to point (B)
1075 //
1076 G4double distOutPhi = pcDotPhi-lenPhiZ;
1077 distOut2 = distOutPhi*distOutPhi + distOutZ*distOutZ;
1078 G4ThreeVector pb = p - vec.edges[1]->corner[0];
1079 *normDist = pb.dot(vec.edges[1]->cornNorm[0]);
1080 }
1081 else
1082 {
1083 //
1084 // ...and inside in phi. Find distance to line (C)
1085 //
1086 G4ThreeVector pa = p - vec.edges[0]->corner[0];
1087 distOut2 = distOutZ*distOutZ;
1088 *normDist = pa.dot(vec.edgeNorm[0]);
1089 }
1090 }
1091 else if (pcDotRZ > lenRZ)
1092 {
1093 G4double lenPhiZ = lenPhi[0] + lenRZ*lenPhi[1];
1094 G4double distOutZ = pcDotRZ-lenRZ;
1095 //
1096 // Above in RZ
1097 //
1098 if (pcDotPhi < -lenPhiZ)
1099 {
1100 //
1101 // ...and below in phi. Find distance to point (D)
1102 //
1103 G4double distOutPhi = pcDotPhi+lenPhiZ;
1104 distOut2 = distOutPhi*distOutPhi + distOutZ*distOutZ;
1105 G4ThreeVector pd = p - vec.edges[0]->corner[1];
1106 *normDist = pd.dot(vec.edges[0]->cornNorm[1]);
1107 }
1108 else if (pcDotPhi > lenPhiZ)
1109 {
1110 //
1111 // ...and above in phi. Find distance to point (E)
1112 //
1113 G4double distOutPhi = pcDotPhi-lenPhiZ;
1114 distOut2 = distOutPhi*distOutPhi + distOutZ*distOutZ;
1115 G4ThreeVector pe = p - vec.edges[1]->corner[1];
1116 *normDist = pe.dot(vec.edges[1]->cornNorm[1]);
1117 }
1118 else
1119 {
1120 //
1121 // ...and inside in phi. Find distance to line (F)
1122 //
1123 distOut2 = distOutZ*distOutZ;
1124 G4ThreeVector pd = p - vec.edges[0]->corner[1];
1125 *normDist = pd.dot(vec.edgeNorm[1]);
1126 }
1127 }
1128 else
1129 {
1130 G4double lenPhiZ = lenPhi[0] + pcDotRZ*lenPhi[1];
1131 //
1132 // We are inside RZ bounds
1133 //
1134 if (pcDotPhi < -lenPhiZ)
1135 {
1136 //
1137 // ...and below in phi. Find distance to line (G)
1138 //
1139 G4double distOut = edgeNorm*(pcDotPhi+lenPhiZ);
1140 distOut2 = distOut*distOut;
1141 G4ThreeVector pd = p - vec.edges[0]->corner[1];
1142 *normDist = pd.dot(vec.edges[0]->normal);
1143 }
1144 else if (pcDotPhi > lenPhiZ)
1145 {
1146 //
1147 // ...and above in phi. Find distance to line (H)
1148 //
1149 G4double distOut = edgeNorm*(pcDotPhi-lenPhiZ);
1150 distOut2 = distOut*distOut;
1151 G4ThreeVector pe = p - vec.edges[1]->corner[1];
1152 *normDist = pe.dot(vec.edges[1]->normal);
1153 }
1154 else
1155 {
1156 //
1157 // Inside bounds! No penalty.
1158 //
1159 return std::fabs(distFaceNorm);
1160 }
1161 }
1162 return std::sqrt( distFaceNorm*distFaceNorm + distOut2 );
1163}

References G4PolyhedraSide::sG4PolyhedraSideVec::center, G4PolyhedraSide::sG4PolyhedraSideEdge::corner, G4PolyhedraSide::sG4PolyhedraSideEdge::cornNorm, CLHEP::Hep3Vector::dot(), G4PolyhedraSide::sG4PolyhedraSideVec::edgeNorm, edgeNorm, G4PolyhedraSide::sG4PolyhedraSideVec::edges, lenPhi, lenRZ, G4PolyhedraSide::sG4PolyhedraSideEdge::normal, G4PolyhedraSide::sG4PolyhedraSideVec::surfPhi, and G4PolyhedraSide::sG4PolyhedraSideVec::surfRZ.

Referenced by Distance(), and DistanceToOneSide().

◆ DistanceToOneSide()

G4double G4PolyhedraSide::DistanceToOneSide ( const G4ThreeVector p,
const G4PolyhedraSideVec vec,
G4double normDist 
)
protected

Definition at line 1002 of file G4PolyhedraSide.cc.

1005{
1006 G4ThreeVector pct = p - vec.center;
1007
1008 //
1009 // Get normal distance
1010 //
1011 *normDist = vec.normal.dot(pct);
1012
1013 //
1014 // Add edge penalty
1015 //
1016 return DistanceAway( p, vec, normDist );
1017}

References G4PolyhedraSide::sG4PolyhedraSideVec::center, DistanceAway(), CLHEP::Hep3Vector::dot(), and G4PolyhedraSide::sG4PolyhedraSideVec::normal.

Referenced by Inside(), and Normal().

◆ Extent()

G4double G4PolyhedraSide::Extent ( const G4ThreeVector  axis)
virtual

Implements G4VCSGface.

Definition at line 646 of file G4PolyhedraSide.cc.

647{
648 if (axis.perp2() < DBL_MIN)
649 {
650 //
651 // Special case
652 //
653 return axis.z() < 0 ? -cone->ZLo() : cone->ZHi();
654 }
655
656 G4int iPhi, i1, i2;
657 G4double best;
658 G4ThreeVector* list[4];
659
660 //
661 // Which phi segment, if any, does the axis belong to
662 //
663 iPhi = PhiSegment( GetPhi(axis) );
664
665 if (iPhi < 0)
666 {
667 //
668 // No phi segment? Check front edge of first side and
669 // last edge of second side
670 //
671 i1 = 0; i2 = numSide-1;
672 }
673 else
674 {
675 //
676 // Check all corners of matching phi side
677 //
678 i1 = iPhi; i2 = iPhi;
679 }
680
681 list[0] = vecs[i1].edges[0]->corner;
682 list[1] = vecs[i1].edges[0]->corner+1;
683 list[2] = vecs[i2].edges[1]->corner;
684 list[3] = vecs[i2].edges[1]->corner+1;
685
686 //
687 // Who's biggest?
688 //
689 best = -kInfinity;
690 G4ThreeVector** vec = list;
691 do // Loop checking, 13.08.2015, G.Cosmo
692 {
693 G4double answer = (*vec)->dot(axis);
694 if (answer > best) best = answer;
695 } while( ++vec < list+4 );
696
697 return best;
698}
double z() const
double perp2() const
G4double ZHi() const
G4double ZLo() const
#define DBL_MIN
Definition: templates.hh:54

References cone, G4PolyhedraSide::sG4PolyhedraSideEdge::corner, DBL_MIN, CLHEP::Hep3Vector::dot(), G4PolyhedraSide::sG4PolyhedraSideVec::edges, GetPhi(), kInfinity, numSide, CLHEP::Hep3Vector::perp2(), PhiSegment(), vecs, CLHEP::Hep3Vector::z(), G4IntersectingCone::ZHi(), and G4IntersectingCone::ZLo().

◆ GetInstanceID()

G4int G4PolyhedraSide::GetInstanceID ( ) const
inline

Definition at line 147 of file G4PolyhedraSide.hh.

147{ return instanceID; }

References instanceID.

◆ GetPhi()

G4double G4PolyhedraSide::GetPhi ( const G4ThreeVector p)
protected

Definition at line 976 of file G4PolyhedraSide.cc.

977{
978 G4double val=0.;
980
981 if (vphi != p)
982 {
983 val = p.phi();
984 G4MT_phphix = p.x(); G4MT_phphiy = p.y(); G4MT_phphiz = p.z();
985 G4MT_phphik = val;
986 }
987 else
988 {
989 val = G4MT_phphik;
990 }
991 return val;
992}
double phi() const
double x() const
double y() const

References G4MT_phphik, G4MT_phphix, G4MT_phphiy, G4MT_phphiz, CLHEP::Hep3Vector::phi(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

Referenced by Distance(), Extent(), Inside(), and Normal().

◆ GetPointOnFace()

G4ThreeVector G4PolyhedraSide::GetPointOnFace ( )
virtual

Implements G4VCSGface.

Definition at line 1242 of file G4PolyhedraSide.cc.

1243{
1244 // Define the variables
1245 //
1246 std::vector<G4double>areas;
1247 std::vector<G4ThreeVector>points;
1248 G4double area=0.;
1249 G4double result1;
1250 G4ThreeVector point1;
1251 G4ThreeVector v1,v2,v3,v4;
1252 G4PolyhedraSideVec* vec = vecs;
1253
1254 // Do a loop on all SideEdge
1255 //
1256 do // Loop checking, 13.08.2015, G.Cosmo
1257 {
1258 // Define 4points for a Plane or Triangle
1259 //
1260 v1=vec->edges[0]->corner[0];
1261 v2=vec->edges[0]->corner[1];
1262 v3=vec->edges[1]->corner[1];
1263 v4=vec->edges[1]->corner[0];
1264 point1=GetPointOnPlane(v1,v2,v3,v4,&result1);
1265 points.push_back(point1);
1266 areas.push_back(result1);
1267 area+=result1;
1268 } while( ++vec < vecs+numSide );
1269
1270 // Choose randomly one of the surfaces and point on it
1271 //
1272 G4double chose = area*G4UniformRand();
1273 G4double Achose1=0., Achose2=0.;
1274 G4int i=0;
1275 do // Loop checking, 13.08.2015, G.Cosmo
1276 {
1277 Achose2+=areas[i];
1278 if(chose>=Achose1 && chose<Achose2)
1279 {
1280 point1=points[i] ; break;
1281 }
1282 ++i; Achose1=Achose2;
1283 } while( i<numSide );
1284
1285 return point1;
1286}
#define G4UniformRand()
Definition: Randomize.hh:52
G4ThreeVector GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, G4ThreeVector p2, G4ThreeVector p3, G4double *Area)

References G4PolyhedraSide::sG4PolyhedraSideEdge::corner, G4PolyhedraSide::sG4PolyhedraSideVec::edges, G4UniformRand, GetPointOnPlane(), numSide, and vecs.

◆ GetPointOnPlane()

G4ThreeVector G4PolyhedraSide::GetPointOnPlane ( G4ThreeVector  p0,
G4ThreeVector  p1,
G4ThreeVector  p2,
G4ThreeVector  p3,
G4double Area 
)

Definition at line 1189 of file G4PolyhedraSide.cc.

1192{
1193 G4double chose,aOne,aTwo;
1194 G4ThreeVector point1,point2;
1195 aOne = SurfaceTriangle(p0,p1,p2,&point1);
1196 aTwo = SurfaceTriangle(p2,p3,p0,&point2);
1197 *Area= aOne+aTwo;
1198
1199 chose = G4UniformRand()*(aOne+aTwo);
1200 if( (chose>=0.) && (chose < aOne) )
1201 {
1202 return (point1);
1203 }
1204 return (point2);
1205}
G4double SurfaceTriangle(G4ThreeVector p1, G4ThreeVector p2, G4ThreeVector p3, G4ThreeVector *p4)

References G4UniformRand, and SurfaceTriangle().

Referenced by GetPointOnFace(), and SurfaceArea().

◆ GetSubInstanceManager()

const G4PhSideManager & G4PolyhedraSide::GetSubInstanceManager ( )
static

Definition at line 56 of file G4PolyhedraSide.cc.

57{
58 return subInstanceManager;
59}

References subInstanceManager.

Referenced by G4SolidsWorkspace::G4SolidsWorkspace().

◆ Inside()

EInside G4PolyhedraSide::Inside ( const G4ThreeVector p,
G4double  tolerance,
G4double bestDistance 
)
virtual

Implements G4VCSGface.

Definition at line 600 of file G4PolyhedraSide.cc.

603{
604 //
605 // Which phi segment is closest to this point?
606 //
607 G4int iPhi = ClosestPhiSegment( GetPhi(p) );
608
609 G4double norm;
610
611 //
612 // Get distance to this segment
613 //
614 *bestDistance = DistanceToOneSide( p, vecs[iPhi], &norm );
615
616 //
617 // Use distance along normal to decide return value
618 //
619 if ( (std::fabs(norm) > tolerance) || (*bestDistance > 2.0*tolerance) )
620 return (norm < 0) ? kInside : kOutside;
621 else
622 return kSurface;
623}
G4double DistanceToOneSide(const G4ThreeVector &p, const G4PolyhedraSideVec &vec, G4double *normDist)
@ kInside
Definition: geomdefs.hh:70
@ kOutside
Definition: geomdefs.hh:68
@ kSurface
Definition: geomdefs.hh:69

References ClosestPhiSegment(), DistanceToOneSide(), GetPhi(), kInside, kOutside, kSurface, and vecs.

◆ Intersect()

G4bool G4PolyhedraSide::Intersect ( const G4ThreeVector p,
const G4ThreeVector v,
G4bool  outgoing,
G4double  surfTolerance,
G4double distance,
G4double distFromSurface,
G4ThreeVector normal,
G4bool allBehind 
)
virtual

Implements G4VCSGface.

Definition at line 449 of file G4PolyhedraSide.cc.

457{
458 G4double normSign = outgoing ? +1 : -1;
459
460 //
461 // ------------------TO BE IMPLEMENTED---------------------
462 // Testing the intersection of individual phi faces is
463 // pretty straight forward. The simple thing therefore is to
464 // form a loop and check them all in sequence.
465 //
466 // But, I worry about one day someone making
467 // a polygon with a thousands sides. A linear search
468 // would not be ideal in such a case.
469 //
470 // So, it would be nice to be able to quickly decide
471 // which face would be intersected. One can make a very
472 // good guess by using the intersection with a cone.
473 // However, this is only reliable in 99% of the cases.
474 //
475 // My solution: make a decent guess as to the one or
476 // two potential faces might get intersected, and then
477 // test them. If we have the wrong face, use the test
478 // to make a better guess.
479 //
480 // Since we might have two guesses, form a queue of
481 // potential intersecting faces. Keep an array of
482 // already tested faces to avoid doing one more than
483 // once.
484 //
485 // Result: at worst, an iterative search. On average,
486 // a little more than two tests would be required.
487 //
488 G4ThreeVector q = p + v;
489
490 G4int face = 0;
492 do // Loop checking, 13.08.2015, G.Cosmo
493 {
494 //
495 // Correct normal?
496 //
497 G4double dotProd = normSign*v.dot(vec->normal);
498 if (dotProd <= 0) continue;
499
500 //
501 // Is this face in front of the point along the trajectory?
502 //
503 G4ThreeVector delta = p - vec->center;
504 distFromSurface = -normSign*delta.dot(vec->normal);
505
506 if (distFromSurface < -surfTolerance) continue;
507
508 //
509 // phi
510 // c -------- d ^
511 // | | |
512 // a -------- b +---> r/z
513 //
514 //
515 // Do we remain on this particular segment?
516 //
517 G4ThreeVector qc = q - vec->edges[1]->corner[0];
518 G4ThreeVector qd = q - vec->edges[1]->corner[1];
519
520 if (normSign*qc.cross(qd).dot(v) < 0) continue;
521
522 G4ThreeVector qa = q - vec->edges[0]->corner[0];
523 G4ThreeVector qb = q - vec->edges[0]->corner[1];
524
525 if (normSign*qa.cross(qb).dot(v) > 0) continue;
526
527 //
528 // We found the one and only segment we might be intersecting.
529 // Do we remain within r/z bounds?
530 //
531
532 if (r[0] > 1/kInfinity && normSign*qa.cross(qc).dot(v) < 0) return false;
533 if (r[1] > 1/kInfinity && normSign*qb.cross(qd).dot(v) > 0) return false;
534
535 //
536 // We allow the face to be slightly behind the trajectory
537 // (surface tolerance) only if the point p is within
538 // the vicinity of the face
539 //
540 if (distFromSurface < 0)
541 {
542 G4ThreeVector ps = p - vec->center;
543
544 G4double rz = ps.dot(vec->surfRZ);
545 if (std::fabs(rz) > lenRZ+surfTolerance) return false;
546
547 G4double pp = ps.dot(vec->surfPhi);
548 if (std::fabs(pp) > lenPhi[0]+lenPhi[1]*rz+surfTolerance) return false;
549 }
550
551
552 //
553 // Intersection found. Return answer.
554 //
555 distance = distFromSurface/dotProd;
556 normal = vec->normal;
557 isAllBehind = allBehind;
558 return true;
559 } while( ++vec, ++face < numSide );
560
561 //
562 // Oh well. Better luck next time.
563 //
564 return false;
565}
static constexpr double ps
Definition: G4SIunits.hh:157

References allBehind, G4PolyhedraSide::sG4PolyhedraSideVec::center, G4PolyhedraSide::sG4PolyhedraSideEdge::corner, CLHEP::Hep3Vector::cross(), CLHEP::Hep3Vector::dot(), G4PolyhedraSide::sG4PolyhedraSideVec::edges, kInfinity, lenPhi, lenRZ, CLHEP::normal(), G4PolyhedraSide::sG4PolyhedraSideVec::normal, numSide, G4InuclParticleNames::pp, ps, r, G4PolyhedraSide::sG4PolyhedraSideVec::surfPhi, G4PolyhedraSide::sG4PolyhedraSideVec::surfRZ, and vecs.

◆ IntersectSidePlane()

G4bool G4PolyhedraSide::IntersectSidePlane ( const G4ThreeVector p,
const G4ThreeVector v,
const G4PolyhedraSideVec vec,
G4double  normSign,
G4double  surfTolerance,
G4double distance,
G4double distFromSurface 
)
protected

Definition at line 773 of file G4PolyhedraSide.cc.

780{
781 //
782 // Correct normal? Here we have straight sides, and can safely ignore
783 // intersections where the dot product with the normal is zero.
784 //
785 G4double dotProd = normSign*v.dot(vec.normal);
786
787 if (dotProd <= 0) return false;
788
789 //
790 // Calculate distance to surface. If the side is too far
791 // behind the point, we must reject it.
792 //
793 G4ThreeVector delta = p - vec.center;
794 distFromSurface = -normSign*delta.dot(vec.normal);
795
796 if (distFromSurface < -surfTolerance) return false;
797
798 //
799 // Calculate precise distance to intersection with the side
800 // (along the trajectory, not normal to the surface)
801 //
802 distance = distFromSurface/dotProd;
803
804 //
805 // Do we fall off the r/z extent of the segment?
806 //
807 // Calculate this very, very carefully! Why?
808 // 1. If a RZ end is at R=0, you can't miss!
809 // 2. If you just fall off in RZ, the answer must
810 // be consistent with adjacent G4PolyhedraSide faces.
811 // (2) implies that only variables used by other G4PolyhedraSide
812 // faces may be used, which includes only: p, v, and the edge corners.
813 // It also means that one side is a ">" or "<", which the other
814 // must be ">=" or "<=". Fortunately, this isn't a new problem.
815 // The solution below I borrowed from Joseph O'Rourke,
816 // "Computational Geometry in C (Second Edition)"
817 // See: http://cs.smith.edu/~orourke/
818 //
819 G4ThreeVector ic = p + distance*v - vec.center;
820 G4double atRZ = vec.surfRZ.dot(ic);
821
822 if (atRZ < 0)
823 {
824 if (r[0]==0) return true; // Can't miss!
825
826 if (atRZ < -lenRZ*1.2) return false; // Forget it! Missed by a mile.
827
828 G4ThreeVector q = p + v;
829 G4ThreeVector qa = q - vec.edges[0]->corner[0],
830 qb = q - vec.edges[1]->corner[0];
831 G4ThreeVector qacb = qa.cross(qb);
832 if (normSign*qacb.dot(v) < 0) return false;
833
834 if (distFromSurface < 0)
835 {
836 if (atRZ < -lenRZ-surfTolerance) return false;
837 }
838 }
839 else if (atRZ > 0)
840 {
841 if (r[1]==0) return true; // Can't miss!
842
843 if (atRZ > lenRZ*1.2) return false; // Missed by a mile
844
845 G4ThreeVector q = p + v;
846 G4ThreeVector qa = q - vec.edges[0]->corner[1],
847 qb = q - vec.edges[1]->corner[1];
848 G4ThreeVector qacb = qa.cross(qb);
849 if (normSign*qacb.dot(v) >= 0) return false;
850
851 if (distFromSurface < 0)
852 {
853 if (atRZ > lenRZ+surfTolerance) return false;
854 }
855 }
856
857 return true;
858}

References G4PolyhedraSide::sG4PolyhedraSideVec::center, G4PolyhedraSide::sG4PolyhedraSideEdge::corner, CLHEP::Hep3Vector::cross(), CLHEP::Hep3Vector::dot(), G4PolyhedraSide::sG4PolyhedraSideVec::edges, lenRZ, G4PolyhedraSide::sG4PolyhedraSideVec::normal, r, and G4PolyhedraSide::sG4PolyhedraSideVec::surfRZ.

◆ LineHitsSegments()

G4int G4PolyhedraSide::LineHitsSegments ( const G4ThreeVector p,
const G4ThreeVector v,
G4int i1,
G4int i2 
)
protected

Definition at line 866 of file G4PolyhedraSide.cc.

869{
870 G4double s1, s2;
871 //
872 // First, decide if and where the line intersects the cone
873 //
874 G4int n = cone->LineHitsCone( p, v, &s1, &s2 );
875
876 if (n==0) return 0;
877
878 //
879 // Try first intersection.
880 //
881 *i1 = PhiSegment( std::atan2( p.y() + s1*v.y(), p.x() + s1*v.x() ) );
882 if (n==1)
883 {
884 return (*i1 < 0) ? 0 : 1;
885 }
886
887 //
888 // Try second intersection
889 //
890 *i2 = PhiSegment( std::atan2( p.y() + s2*v.y(), p.x() + s2*v.x() ) );
891 if (*i1 == *i2) return 0;
892
893 if (*i1 < 0)
894 {
895 if (*i2 < 0) return 0;
896 *i1 = *i2;
897 return 1;
898 }
899
900 if (*i2 < 0) return 1;
901
902 return 2;
903}
G4int LineHitsCone(const G4ThreeVector &p, const G4ThreeVector &v, G4double *s1, G4double *s2)

References cone, G4IntersectingCone::LineHitsCone(), CLHEP::detail::n, PhiSegment(), CLHEP::Hep3Vector::x(), and CLHEP::Hep3Vector::y().

◆ Normal()

G4ThreeVector G4PolyhedraSide::Normal ( const G4ThreeVector p,
G4double bestDistance 
)
virtual

Implements G4VCSGface.

Definition at line 627 of file G4PolyhedraSide.cc.

629{
630 //
631 // Which phi segment is closest to this point?
632 //
633 G4int iPhi = ClosestPhiSegment( GetPhi(p) );
634
635 //
636 // Get distance to this segment
637 //
638 G4double norm;
639 *bestDistance = DistanceToOneSide( p, vecs[iPhi], &norm );
640
641 return vecs[iPhi].normal;
642}

References ClosestPhiSegment(), DistanceToOneSide(), GetPhi(), G4PolyhedraSide::sG4PolyhedraSideVec::normal, and vecs.

◆ operator=()

G4PolyhedraSide & G4PolyhedraSide::operator= ( const G4PolyhedraSide source)

Definition at line 340 of file G4PolyhedraSide.cc.

341{
342 if (this == &source) return *this;
343
344 delete cone;
345 delete [] vecs;
346 delete [] edges;
347
348 CopyStuff( source );
349
350 return *this;
351}

References cone, CopyStuff(), edges, and vecs.

◆ PhiSegment()

G4int G4PolyhedraSide::PhiSegment ( G4double  phi)
protected

Definition at line 938 of file G4PolyhedraSide.cc.

939{
940 //
941 // How far are we from phiStart? Come up with a positive answer
942 // that is less than 2*PI
943 //
944 G4double phi = phi0 - startPhi;
945 while( phi < 0 ) // Loop checking, 13.08.2015, G.Cosmo
946 phi += twopi;
947 while( phi > twopi ) // Loop checking, 13.08.2015, G.Cosmo
948 phi -= twopi;
949
950 //
951 // Divide
952 //
953 G4int answer = (G4int)(phi/deltaPhi);
954
955 if (answer >= numSide)
956 {
957 if (phiIsOpen)
958 {
959 return -1; // Looks like we missed
960 }
961 else
962 {
963 answer = numSide-1; // Probably just roundoff
964 }
965 }
966
967 return answer;
968}

References deltaPhi, numSide, phiIsOpen, startPhi, and twopi.

Referenced by ClosestPhiSegment(), Extent(), and LineHitsSegments().

◆ SurfaceArea()

G4double G4PolyhedraSide::SurfaceArea ( )
virtual

Implements G4VCSGface.

Definition at line 1209 of file G4PolyhedraSide.cc.

1210{
1211 if( fSurfaceArea==0. )
1212 {
1213 // Define the variables
1214 //
1215 G4double area,areas;
1216 G4ThreeVector point1;
1217 G4ThreeVector v1,v2,v3,v4;
1218 G4PolyhedraSideVec* vec = vecs;
1219 areas=0.;
1220
1221 // Do a loop on all SideEdge
1222 //
1223 do // Loop checking, 13.08.2015, G.Cosmo
1224 {
1225 // Define 4points for a Plane or Triangle
1226 //
1227 v1=vec->edges[0]->corner[0];
1228 v2=vec->edges[0]->corner[1];
1229 v3=vec->edges[1]->corner[1];
1230 v4=vec->edges[1]->corner[0];
1231 point1=GetPointOnPlane(v1,v2,v3,v4,&area);
1232 areas+=area;
1233 } while( ++vec < vecs + numSide);
1234
1235 fSurfaceArea=areas;
1236 }
1237 return fSurfaceArea;
1238}

References G4PolyhedraSide::sG4PolyhedraSideEdge::corner, G4PolyhedraSide::sG4PolyhedraSideVec::edges, fSurfaceArea, GetPointOnPlane(), numSide, and vecs.

◆ SurfaceTriangle()

G4double G4PolyhedraSide::SurfaceTriangle ( G4ThreeVector  p1,
G4ThreeVector  p2,
G4ThreeVector  p3,
G4ThreeVector p4 
)

Definition at line 1168 of file G4PolyhedraSide.cc.

1172{
1173 G4ThreeVector v, w;
1174
1175 v = p3 - p1;
1176 w = p1 - p2;
1177 G4double lambda1 = G4UniformRand();
1178 G4double lambda2 = lambda1*G4UniformRand();
1179
1180 *p4=p2 + lambda1*w + lambda2*v;
1181 return 0.5*(v.cross(w)).mag();
1182}

References CLHEP::Hep3Vector::cross(), and G4UniformRand.

Referenced by GetPointOnPlane().

Friends And Related Function Documentation

◆ sG4PolyhedraSideVec

friend struct sG4PolyhedraSideVec
friend

Definition at line 157 of file G4PolyhedraSide.hh.

Field Documentation

◆ allBehind

G4bool G4PolyhedraSide::allBehind = false
protected

Definition at line 214 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), G4PolyhedraSide(), and Intersect().

◆ cone

G4IntersectingCone* G4PolyhedraSide::cone = nullptr
protected

◆ deltaPhi

G4double G4PolyhedraSide::deltaPhi
protected

Definition at line 211 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), G4PolyhedraSide(), and PhiSegment().

◆ edgeNorm

G4double G4PolyhedraSide::edgeNorm
protected

Definition at line 222 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), DistanceAway(), and G4PolyhedraSide().

◆ edges

G4PolyhedraSideEdge* G4PolyhedraSide::edges = nullptr
protected

Definition at line 219 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), G4PolyhedraSide(), operator=(), and ~G4PolyhedraSide().

◆ endPhi

G4double G4PolyhedraSide::endPhi
protected

Definition at line 212 of file G4PolyhedraSide.hh.

Referenced by ClosestPhiSegment(), CopyStuff(), and G4PolyhedraSide().

◆ fSurfaceArea

G4double G4PolyhedraSide::fSurfaceArea = 0.0
private

Definition at line 227 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), and SurfaceArea().

◆ instanceID

G4int G4PolyhedraSide::instanceID
private

Definition at line 229 of file G4PolyhedraSide.hh.

Referenced by G4PolyhedraSide(), and GetInstanceID().

◆ kCarTolerance

G4double G4PolyhedraSide::kCarTolerance
private

Definition at line 226 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), Distance(), and G4PolyhedraSide().

◆ lenPhi

G4double G4PolyhedraSide::lenPhi[2]
protected

Definition at line 221 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), DistanceAway(), G4PolyhedraSide(), and Intersect().

◆ lenRZ

G4double G4PolyhedraSide::lenRZ
protected

◆ numSide

G4int G4PolyhedraSide::numSide = 0
protected

◆ phiIsOpen

G4bool G4PolyhedraSide::phiIsOpen = false
protected

Definition at line 213 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), G4PolyhedraSide(), and PhiSegment().

◆ r

G4double G4PolyhedraSide::r[2]
protected

Definition at line 209 of file G4PolyhedraSide.hh.

Referenced by CopyStuff(), G4PolyhedraSide(), Intersect(), and IntersectSidePlane().

◆ startPhi

G4double G4PolyhedraSide::startPhi
protected

Definition at line 210 of file G4PolyhedraSide.hh.

Referenced by ClosestPhiSegment(), CopyStuff(), G4PolyhedraSide(), and PhiSegment().

◆ subInstanceManager

G4PhSideManager G4PolyhedraSide::subInstanceManager
staticprivate

Definition at line 231 of file G4PolyhedraSide.hh.

Referenced by G4PolyhedraSide(), and GetSubInstanceManager().

◆ vecs

G4PolyhedraSideVec* G4PolyhedraSide::vecs = nullptr
protected

◆ z

G4double G4PolyhedraSide::z[2]
protected

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