Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PolyPhiFace.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4PolyPhiFace
27//
28// Class description:
29//
30// Definition of a face that bounds a polycone or polyhedra when
31// it has a phi opening:
32//
33// G4PolyPhiFace( const G4ReduciblePolygon* rz,
34// G4double phi,
35// G4double deltaPhi,
36// G4double phiOther )
37//
38// Specifically: a face that lies on a plane that passes through
39// the z axis. It has boundaries that are straight lines of arbitrary
40// length and direction, but with corners aways on the same side of
41// the z axis.
42
43// Author: David C. Williams (UCSC), 1998
44// --------------------------------------------------------------------
45#ifndef G4POLYPHIFACE_HH
46#define G4POLYPHIFACE_HH 1
47
48#include "G4VCSGface.hh"
49#include "G4TwoVector.hh"
50
52
54{
55 G4double x, y, r, z; // position
57 zNorm; // r/z normal
58 G4ThreeVector norm3D; // 3D normal
59
60 // Needed for Triangulation Algorithm
61 //
64};
65
67{
68 G4PolyPhiFaceEdge() = default;
69 G4PolyPhiFaceVertex *v0{nullptr}, *v1{nullptr}; // Corners
70 G4double tr{.0}, tz{0.}, // Unit vector along edge
71 length{0.}; // Length of edge
72 G4ThreeVector norm3D; // 3D edge normal vector
73};
74
75/**
76 * @brief G4PolyPhiFace is a face that bounds a polycone or polyhedra when
77 * it has a phi opening. Specifically, it is a face that lies on a plane that
78 * passes through the Z axis, having boundaries that are straight lines of
79 * arbitrary length and direction, but with corners aways on the same side of
80 * the Z axis.
81 */
82
84{
85
86 public:
87
88 /**
89 * Constructor where points r,z should be supplied in clockwise order
90 * in r,z.
91 * For example:
92 * [1]---------[2] ^ R
93 * | | |
94 * | | +--> z
95 * [0]---------[3]
96 * @param[in] rz Pointer to previous r,Z section.
97 * @param[in] phi Initial Phi starting angle.
98 * @param[in] deltaPhi Total Phi angle.
99 * @param[in] phiOther Phi angle of next section.
100 */
102 G4double phi, G4double deltaPhi, G4double phiOther );
103
104 /**
105 * Destructor. Removes edges and corners.
106 */
107 ~G4PolyPhiFace() override;
108
109 /**
110 * Copy constructor and assignment operator.
111 */
112 G4PolyPhiFace( const G4PolyPhiFace& source );
113 G4PolyPhiFace& operator=( const G4PolyPhiFace& source );
114
115 /**
116 * Determines the distance along a line to the face.
117 * @param[in] p Position.
118 * @param[in] v Direction (assumed to be a unit vector).
119 * @param[in] outgoing Flag true, to consider only inside surfaces;
120 * false, to consider only outside surfaces.
121 * @param[in] surfTolerance Minimum distance from the surface.
122 * @param[out] distance Distance to intersection.
123 * @param[out] distFromSurface Distance from surface (along surface normal),
124 * < 0 if the point is in front of the surface.
125 * @param[out] normal Normal of surface at intersection point.
126 * @param[out] allBehind Flag, true, if entire surface is behind normal.
127 * @returns true if there is an intersection, false otherwise.
128 */
129 G4bool Intersect( const G4ThreeVector& p, const G4ThreeVector& v,
130 G4bool outgoing, G4double surfTolerance,
131 G4double& distance, G4double& distFromSurface,
132 G4ThreeVector& normal, G4bool& allBehind ) override;
133
134 /**
135 * Determines the distance of a point from either the inside or outside
136 * surfaces of the face.
137 * @param[in] p Position.
138 * @param[in] outgoing Flag, true, to consider only inside surfaces
139 * or false, to consider only outside surfaces.
140 * @returns The distance to the closest surface satisfying requirements
141 * or kInfinity if no such surface exists.
142 */
143 G4double Distance( const G4ThreeVector& p, G4bool outgoing ) override;
144
145 /**
146 * Determines whether a point is inside, outside, or on the surface of
147 * the face.
148 * @param[in] p Position.
149 * @param[in] tolerance Tolerance defining the bounds of the "kSurface",
150 * nominally equal to kCarTolerance/2.
151 * @param[out] bestDistance Distance to the closest surface (in or out).
152 * @returns kInside if the point is closest to the inside surface;
153 * kOutside if the point is closest to the outside surface;
154 * kSurface if the point is withing tolerance of the surface.
155 */
156 EInside Inside( const G4ThreeVector& p, G4double tolerance,
157 G4double* bestDistance ) override;
158
159 /**
160 * Returns the normal of surface closest to the point.
161 * @param[in] p Position.
162 * @param[out] bestDistance Distance to the closest surface (in or out).
163 * @returns The normal of the surface nearest the point.
164 */
166 G4double* bestDistance ) override;
167
168 /**
169 * Returns the face extent along the axis.
170 * @param[in] axis Unit vector defining the direction.
171 * @returns The largest point along the given axis of the face's extent.
172 */
173 G4double Extent( const G4ThreeVector axis ) override;
174
175 /**
176 * Calculates the extent of the face for the voxel navigator.
177 * @param[in] axis The axis in which to check the shapes 3D extent against.
178 * @param[in] voxelLimit Limits along x, y, and/or z axes.
179 * @param[in] tranform A coordinate transformation on which to apply to
180 * the shape before testing.
181 * @param[out] extentList The list of (voxel) extents along the axis.
182 */
183 void CalculateExtent( const EAxis axis,
184 const G4VoxelLimits &voxelLimit,
185 const G4AffineTransform& tranform,
186 G4SolidExtentList& extentList ) override;
187
188 /**
189 * Method invoked by the copy constructor or the assignment operator.
190 * Its purpose is to return a pointer to a duplicate copy of the face.
191 */
192 inline G4VCSGface* Clone() override;
193
194 /**
195 * Returning an estimation of the face surface area, in internal units.
196 */
197 G4double SurfaceArea() override;
198
199 /**
200 * Fake default constructor for usage restricted to direct object
201 * persistency for clients requiring preallocation of memory for
202 * persistifiable objects.
203 */
204 G4PolyPhiFace(__void__&);
205
206 /**
207 * Throws an exception if something is found inconsistent with the solid.
208 * For debugging purposes only.
209 */
210 void Diagnose( G4VSolid* solid );
211
212 private:
213
214 /**
215 * Calculates the surface area of a triangle.
216 * At the same time a random point in the triangle is given.
217 */
218 G4double SurfaceTriangle( const G4ThreeVector& p1, const G4ThreeVector& p2,
219 const G4ThreeVector& p3, G4ThreeVector* p4);
220
221 /**
222 * Auxiliary method for GetPointOnSurface().
223 */
224 G4ThreeVector GetPointOnFace() override;
225
226 /**
227 * Decides if the point in r,z is inside the edges of a face,
228 * **but** do so consistently with other faces.
229 */
230 G4bool InsideEdgesExact( G4double r, G4double z, G4double normSign,
231 const G4ThreeVector& p, const G4ThreeVector& v );
232
233 /**
234 * Methods to decide if the point in r,z is inside the edges of a face.
235 */
236 G4bool InsideEdges( G4double r, G4double z );
237 G4bool InsideEdges( G4double r, G4double z, G4double* distRZ2,
238 G4PolyPhiFaceVertex** base3Dnorm = nullptr,
239 G4ThreeVector** head3Dnorm = nullptr );
240
241 /**
242 * Decides precisely whether a trajectory passes to the left, right,
243 * or exactly passes through the Z position of a vertex point in face.
244 */
245 inline G4double ExactZOrder( G4double z,
246 G4double qx, G4double qy, G4double qz,
247 const G4ThreeVector& v,
248 G4double normSign,
249 const G4PolyPhiFaceVertex* vert ) const;
250
251 /**
252 * Copies parameters from other object; used in copy constructor and
253 * assignment operator.
254 */
255 void CopyStuff( const G4PolyPhiFace& source );
256
257 // Functions used for Triangulation in Case of generic Polygone.
258 // The triangulation is used for GetPointOnFace()
259
260 /**
261 * Calculates of 2*Area of Triangle with Sign.
262 */
263 G4double Area2( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c);
264
265 /**
266 * Boolean functions for sign of Surface.
267 */
268 G4bool Left( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c );
269 G4bool LeftOn( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c );
270 G4bool Collinear( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c );
271
272 /**
273 * Boolean function for finding proper intersection of two
274 * line segments (a,b) and (c,d).
275 */
276 G4bool IntersectProp( const G4TwoVector& a, const G4TwoVector& b,
277 const G4TwoVector& c, const G4TwoVector& d );
278
279 /**
280 * Boolean function for determining if point c is between a and b
281 * where the three points (a,b,c) are on the same line.
282 */
283 G4bool Between( const G4TwoVector& a, const G4TwoVector& b, const G4TwoVector& c );
284
285 /**
286 * Boolean function for finding proper intersection or not
287 * of two line segments (a,b) and (c,d).
288 */
289 G4bool Intersect( const G4TwoVector& a, const G4TwoVector& b,
290 const G4TwoVector& c, const G4TwoVector& d );
291
292 /**
293 * Boolean Diagonalie help to determine if diagonal s
294 * of segment (a,b) is convex or reflex.
295 */
297
298 /**
299 * Boolean function for determining if b is inside the cone (a0,a,a1)
300 * where a is the center of the cone.
301 */
303
304 /**
305 * Boolean function for determining if Diagonal is possible
306 * inside Polycone or PolyHedra.
307 */
309
310 /**
311 * Initialisation for Triangulisation by ear tips.
312 * For details see "Computational Geometry in C" by Joseph O'Rourke.
313 */
314 void EarInit();
315
316 /**
317 * Triangularisation by ear tips for Polycone or Polyhedra.
318 * For details see "Computational Geometry in C" by Joseph O'Rourke.
319 * NOTE: a copy of the shape is made and this copy is reordered in
320 * order to have a list of triangles. This list is used by the
321 * method GetPointOnFace().
322 */
323 void Triangulate();
324
325 private:
326
327 G4int numEdges = 0; // Number of edges
328 G4PolyPhiFaceEdge* edges = nullptr; // The edges of the face
329 G4PolyPhiFaceVertex* corners = nullptr; // And the corners
330 G4ThreeVector normal; // Normal unit vector
331 G4ThreeVector radial; // Unit vector along radial direction
332 G4ThreeVector surface; // Point on surface
333 G4ThreeVector surface_point; // Auxiliary point on surface used for
334 // method GetPointOnFace()
335 G4double rMin, rMax, // Extent in r
336 zMin, zMax; // Extent in z
337 G4bool allBehind = false; // True if the polycone/polyhedra
338 // is behind the place of this face
339 G4double kCarTolerance; // Surface thickness
340 G4double fSurfaceArea = 0.0; // Surface Area of PolyPhiFace
341
342 /** Auxiliary pointer to 'corners' used for triangulation.
343 Copy structure, changing the structure of 'corners' (ear removal). */
344 G4PolyPhiFaceVertex* triangles = nullptr;
345};
346
347#include "G4PolyPhiFace.icc"
348
349#endif
CLHEP::Hep3Vector G4ThreeVector
CLHEP::Hep2Vector G4TwoVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4AffineTransform is a class for geometric affine transformations. It supports efficient arbitrary ro...
G4double Distance(const G4ThreeVector &p, G4bool outgoing) override
EInside Inside(const G4ThreeVector &p, G4double tolerance, G4double *bestDistance) override
void Diagnose(G4VSolid *solid)
void CalculateExtent(const EAxis axis, const G4VoxelLimits &voxelLimit, const G4AffineTransform &tranform, G4SolidExtentList &extentList) override
G4PolyPhiFace & operator=(const G4PolyPhiFace &source)
G4VCSGface * Clone() override
G4double Extent(const G4ThreeVector axis) override
G4ThreeVector Normal(const G4ThreeVector &p, G4double *bestDistance) override
G4bool Intersect(const G4ThreeVector &p, const G4ThreeVector &v, G4bool outgoing, G4double surfTolerance, G4double &distance, G4double &distFromSurface, G4ThreeVector &normal, G4bool &allBehind) override
~G4PolyPhiFace() override
G4double SurfaceArea() override
G4PolyPhiFace(const G4ReduciblePolygon *rz, G4double phi, G4double deltaPhi, G4double phiOther)
G4ReduciblePolygon is a utility class used to specify, test, reduce, and/or otherwise manipulate a 2D...
G4SolidExtentList is utility class designed for calculating the extent of a CSG-like solid for a voxe...
virtual G4ThreeVector GetPointOnFace()=0
G4VCSGface()=default
G4VSolid is an abstract base class for solids, physical shapes that can be tracked through....
Definition G4VSolid.hh:80
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67
const axis_t axis_to_type< N >::axis
Definition pugixml.cc:9668
G4PolyPhiFaceVertex * v1
G4PolyPhiFaceEdge()=default
G4ThreeVector norm3D
G4PolyPhiFaceVertex * v0
G4ThreeVector norm3D
G4PolyPhiFaceVertex * next
G4PolyPhiFaceVertex * prev