Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4GeomTools.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 //
27 // $Id: $
28 //
29 //
30 // --------------------------------------------------------------------
31 // class G4GeomTools
32 //
33 // Class description:
34 //
35 // A collection of utilities which can be helpfull for a wide range
36 // of geometry-related tasks
37 
38 // History:
39 //
40 // 10.10.2016 E.Tcherniaev: Initial version.
41 // --------------------------------------------------------------------
42 
43 #ifndef G4GEOMTOOLS_HH
44 #define G4GEOMTOOLS_HH
45 
46 #include <vector>
47 #include "G4TwoVector.hh"
48 #include "G4ThreeVector.hh"
49 
50 typedef std::vector<G4TwoVector> G4TwoVectorList;
51 typedef std::vector<G4ThreeVector> G4ThreeVectorList;
52 
54 {
55  public:
56 
57  // ==================================================================
58  // 2D Utilities
59  // ------------------------------------------------------------------
60 
61  static G4double TriangleArea(G4double Ax, G4double Ay,
62  G4double Bx, G4double By,
63  G4double Cx, G4double Cy);
64 
65  static G4double TriangleArea(const G4TwoVector& A,
66  const G4TwoVector& B,
67  const G4TwoVector& C);
68  // Calcuate area of 2D triangle, return value is positive if
69  // vertices of the triangle are given in anticlockwise order,
70  // otherwise it is negative
71 
72  static G4double QuadArea(const G4TwoVector& A,
73  const G4TwoVector& B,
74  const G4TwoVector& C,
75  const G4TwoVector& D);
76  // Calcuate area of 2D quadrilateral, return value is positive if
77  // vertices of the quadrilateral are given in anticlockwise order,
78  // otherwise it is negative
79 
80  static G4double PolygonArea(const G4TwoVectorList& polygon);
81  // Calcuate area of 2D polygon, return value is positive if
82  // vertices of the polygon are defined in anticlockwise order,
83  // otherwise it is negative
84 
86  G4double Ax, G4double Ay,
87  G4double Bx, G4double By,
88  G4double Cx, G4double Cy);
89  // Decide if point (Px,Py) is inside triangle (Ax,Ay)(Bx,By)(Cx,Cy)
90 
91  static G4bool PointInTriangle(const G4TwoVector& P,
92  const G4TwoVector& A,
93  const G4TwoVector& B,
94  const G4TwoVector& C);
95  // Decide if point P is inside triangle ABC
96 
97  /*
98  static G4bool PointInPolygon(const G4TwoVector& P
99  const G4TwoVectorList& Polygon);
100  // Decide if point P is inside Polygon
101  */
102 
103  static G4bool IsConvex(const G4TwoVectorList& polygon);
104  // Decide if 2D polygon is convex, i.e. all internal angles are
105  // less than pi
106 
107  static G4bool TriangulatePolygon(const G4TwoVectorList& polygon,
109 
110  static G4bool TriangulatePolygon(const G4TwoVectorList& polygon,
111  std::vector<G4int>& result);
112  // Simple implementation of "ear clipping" algorithm for
113  // triangulation of a simple contour/polygon, it places results
114  // in a std::vector as triplets of vertices. If triangulation
115  // is sucsessfull then the function returns true, otherwise false
116 
117  static void RemoveRedundantVertices(G4TwoVectorList& polygon,
118  std::vector<G4int>& iout,
119  G4double tolerance = 0);
120  // Remove collinear and coincident points from 2D polygon.
121  // Indices of removed points are available in iout.
122 
123  static G4bool DiskExtent(G4double rmin, G4double rmax,
124  G4double startPhi, G4double delPhi,
125  G4TwoVector& pmin, G4TwoVector& pmax);
126  // Calculate bounding square of a disk sector,
127  // it returns false if input parameters do not meet the following:
128  // rmin >= 0
129  // rmax > rmin + kCarTolerance
130  // delPhi > 0 + kCarTolerance
131 
132  static void DiskExtent(G4double rmin, G4double rmax,
133  G4double sinPhiStart, G4double cosPhiStart,
134  G4double sinPhiEnd, G4double cosPhiEnd,
135  G4TwoVector& pmin, G4TwoVector& pmax);
136  // Calculate bounding square of a disk sector,
137  // faster version without check of parameters
138 
139  // ==================================================================
140  // 3D Utilities
141  // ------------------------------------------------------------------
142 
143  /*
144  static G4ThreeVector TriangleAreaNormal(const G4ThreeVector& A,
145  const G4ThreeVector& B,
146  const G4ThreeVector& C);
147  // Calcuate normal to the plane of of 3D triangle ABC with
148  // length equal to its area
149 
150  static G4ThreeVector QuadAreaNormal(const G4ThreeVector& A,
151  const G4ThreeVector& B,
152  const G4ThreeVector& C,
153  const G4ThreeVector& D);
154  // Calcuate normal to the plane of 3D quadrilateral ABCD with
155  // length equal to its area
156 
157  static G4ThreeVector PolygonAreaNormal(const G4ThreeVectorList& polygon);
158  // Calcuate normal to the plane of 3D polygon with
159  // length equal to its area
160 
161  static G4bool IsPlanar(const G4ThreeVector& A,
162  const G4ThreeVector& B,
163  const G4ThreeVector& C,
164  const G4ThreeVector& D);
165  // Decide if 3D quadrilateral ABCD is planar
166 
167  static G4bool IsPlanar(const G4ThreeVectorList& polygon);
168  // Decide if 3D polygon is planar
169  */
170 
172  G4ThreeVector A,
173  G4ThreeVector B);
174  // Calculate distance between point P and line segment AB in 3D
175 
176  static G4bool SphereExtent(G4double rmin, G4double rmax,
177  G4double startTheta, G4double delTheta,
178  G4double startPhi, G4double delPhi,
179  G4ThreeVector& pmin, G4ThreeVector& pmax);
180  // Calculate bounding box of a spherical sector,
181  // it returns false if input parameters do not meet the following:
182  // rmin >= 0
183  // rmax > rmin + kCarTolerance
184  // startTheta >= 0 && <= pi;
185  // delTheta > 0 + kCarTolerance
186  // delPhi > 0 + kCarTolerance
187 
188  private:
189 
190  static G4bool CheckSnip(const G4TwoVectorList& contour,
191  G4int a, G4int b, G4int c,
192  G4int n, const G4int* V);
193  // Helper function for TriangulatePolygon()
194 };
195 
196 #endif // G4GEOMTOOLS_HH
G4double G4ParticleHPJENDLHEData::G4double result
static G4double QuadArea(const G4TwoVector &A, const G4TwoVector &B, const G4TwoVector &C, const G4TwoVector &D)
Definition: G4GeomTools.cc:70
std::vector< G4TwoVector > G4TwoVectorList
Definition: G4GeomTools.hh:50
static G4bool PointInTriangle(G4double Px, G4double Py, G4double Ax, G4double Ay, G4double Bx, G4double By, G4double Cx, G4double Cy)
Definition: G4GeomTools.cc:97
static G4double PolygonArea(const G4TwoVectorList &polygon)
Definition: G4GeomTools.cc:82
static G4double DistancePointSegment(G4ThreeVector P, G4ThreeVector A, G4ThreeVector B)
Definition: G4GeomTools.cc:520
double C(double temp)
double B(double temperature)
static G4bool SphereExtent(G4double rmin, G4double rmax, G4double startTheta, G4double delTheta, G4double startPhi, G4double delPhi, G4ThreeVector &pmin, G4ThreeVector &pmax)
Definition: G4GeomTools.cc:542
int G4int
Definition: G4Types.hh:78
static double P[]
double A(double temperature)
bool G4bool
Definition: G4Types.hh:79
static G4bool TriangulatePolygon(const G4TwoVectorList &polygon, G4TwoVectorList &result)
Definition: G4GeomTools.cc:178
std::vector< G4ThreeVector > G4ThreeVectorList
double D(double temp)
static G4bool IsConvex(const G4TwoVectorList &polygon)
Definition: G4GeomTools.cc:150
static G4double TriangleArea(G4double Ax, G4double Ay, G4double Bx, G4double By, G4double Cx, G4double Cy)
Definition: G4GeomTools.cc:47
double G4double
Definition: G4Types.hh:76
static G4bool DiskExtent(G4double rmin, G4double rmax, G4double startPhi, G4double delPhi, G4TwoVector &pmin, G4TwoVector &pmax)
Definition: G4GeomTools.cc:378
static void RemoveRedundantVertices(G4TwoVectorList &polygon, std::vector< G4int > &iout, G4double tolerance=0)
Definition: G4GeomTools.cc:293