Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4GeomTools Class Reference

#include <G4GeomTools.hh>

Static Public Member Functions

static G4double TriangleArea (G4double Ax, G4double Ay, G4double Bx, G4double By, G4double Cx, G4double Cy)
 
static G4double TriangleArea (const G4TwoVector &A, const G4TwoVector &B, const G4TwoVector &C)
 
static G4double QuadArea (const G4TwoVector &A, const G4TwoVector &B, const G4TwoVector &C, const G4TwoVector &D)
 
static G4double PolygonArea (const G4TwoVectorList &polygon)
 
static G4bool PointInTriangle (G4double Px, G4double Py, G4double Ax, G4double Ay, G4double Bx, G4double By, G4double Cx, G4double Cy)
 
static G4bool PointInTriangle (const G4TwoVector &P, const G4TwoVector &A, const G4TwoVector &B, const G4TwoVector &C)
 
static G4bool IsConvex (const G4TwoVectorList &polygon)
 
static G4bool TriangulatePolygon (const G4TwoVectorList &polygon, G4TwoVectorList &result)
 
static G4bool TriangulatePolygon (const G4TwoVectorList &polygon, std::vector< G4int > &result)
 
static void RemoveRedundantVertices (G4TwoVectorList &polygon, std::vector< G4int > &iout, G4double tolerance=0)
 
static G4bool DiskExtent (G4double rmin, G4double rmax, G4double startPhi, G4double delPhi, G4TwoVector &pmin, G4TwoVector &pmax)
 
static void DiskExtent (G4double rmin, G4double rmax, G4double sinPhiStart, G4double cosPhiStart, G4double sinPhiEnd, G4double cosPhiEnd, G4TwoVector &pmin, G4TwoVector &pmax)
 
static G4double DistancePointSegment (G4ThreeVector P, G4ThreeVector A, G4ThreeVector B)
 
static G4bool SphereExtent (G4double rmin, G4double rmax, G4double startTheta, G4double delTheta, G4double startPhi, G4double delPhi, G4ThreeVector &pmin, G4ThreeVector &pmax)
 

Detailed Description

Definition at line 53 of file G4GeomTools.hh.

Member Function Documentation

G4bool G4GeomTools::DiskExtent ( G4double  rmin,
G4double  rmax,
G4double  startPhi,
G4double  delPhi,
G4TwoVector pmin,
G4TwoVector pmax 
)
static

Definition at line 378 of file G4GeomTools.cc.

381 {
382  static const G4double kCarTolerance =
384 
385  // check parameters
386  //
387  pmin.set(0,0);
388  pmax.set(0,0);
389  if (rmin < 0) return false;
390  if (rmax <= rmin + kCarTolerance) return false;
391  if (delPhi <= 0 + kCarTolerance) return false;
392 
393  // calculate extent
394  //
395  pmin.set(-rmax,-rmax);
396  pmax.set( rmax, rmax);
397  if (delPhi >= CLHEP::twopi) return true;
398 
399  DiskExtent(rmin,rmax,
400  std::sin(startPhi),std::cos(startPhi),
401  std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
402  pmin,pmax);
403  return true;
404 }
G4double GetSurfaceTolerance() const
void set(double x, double y)
const G4double kCarTolerance
double G4double
Definition: G4Types.hh:76
static constexpr double twopi
Definition: SystemOfUnits.h:55
static G4bool DiskExtent(G4double rmin, G4double rmax, G4double startPhi, G4double delPhi, G4TwoVector &pmin, G4TwoVector &pmax)
Definition: G4GeomTools.cc:378
static G4GeometryTolerance * GetInstance()

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GeomTools::DiskExtent ( G4double  rmin,
G4double  rmax,
G4double  sinPhiStart,
G4double  cosPhiStart,
G4double  sinPhiEnd,
G4double  cosPhiEnd,
G4TwoVector pmin,
G4TwoVector pmax 
)
static

Definition at line 411 of file G4GeomTools.cc.

415 {
416  static const G4double kCarTolerance =
418 
419  // check if 360 degrees
420  //
421  pmin.set(-rmax,-rmax);
422  pmax.set( rmax, rmax);
423 
424  if (std::abs(sinEnd-sinStart) < kCarTolerance &&
425  std::abs(cosEnd-cosStart) < kCarTolerance) return;
426 
427  // get start and end quadrants
428  //
429  // 1 | 0
430  // ---+---
431  // 3 | 2
432  //
433  G4int icase = (cosEnd < 0) ? 1 : 0;
434  if (sinEnd < 0) icase += 2;
435  if (cosStart < 0) icase += 4;
436  if (sinStart < 0) icase += 8;
437 
438  switch (icase)
439  {
440  // start quadrant 0
441  case 0: // start->end : 0->0
442  if (sinEnd < sinStart) break;
443  pmin.set(rmin*cosEnd,rmin*sinStart);
444  pmax.set(rmax*cosStart,rmax*sinEnd );
445  break;
446  case 1: // start->end : 0->1
447  pmin.set(rmax*cosEnd,std::min(rmin*sinStart,rmin*sinEnd));
448  pmax.set(rmax*cosStart,rmax );
449  break;
450  case 2: // start->end : 0->2
451  pmin.set(-rmax,-rmax);
452  pmax.set(std::max(rmax*cosStart,rmax*cosEnd),rmax);
453  break;
454  case 3: // start->end : 0->3
455  pmin.set(-rmax,rmax*sinEnd);
456  pmax.set(rmax*cosStart,rmax);
457  break;
458  // start quadrant 1
459  case 4: // start->end : 1->0
460  pmin.set(-rmax,-rmax);
461  pmax.set(rmax,std::max(rmax*sinStart,rmax*sinEnd));
462  break;
463  case 5: // start->end : 1->1
464  if (sinEnd > sinStart) break;
465  pmin.set(rmax*cosEnd,rmin*sinEnd );
466  pmax.set(rmin*cosStart,rmax*sinStart);
467  break;
468  case 6: // start->end : 1->2
469  pmin.set(-rmax,-rmax);
470  pmax.set(rmax*cosEnd,rmax*sinStart);
471  break;
472  case 7: // start->end : 1->3
473  pmin.set(-rmax,rmax*sinEnd);
474  pmax.set(std::max(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
475  break;
476  // start quadrant 2
477  case 8: // start->end : 2->0
478  pmin.set(std::min(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
479  pmax.set(rmax,rmax*sinEnd);
480  break;
481  case 9: // start->end : 2->1
482  pmin.set(rmax*cosEnd,rmax*sinStart);
483  pmax.set(rmax,rmax);
484  break;
485  case 10: // start->end : 2->2
486  if (sinEnd < sinStart) break;
487  pmin.set(rmin*cosStart,rmax*sinStart);
488  pmax.set(rmax*cosEnd,rmin*sinEnd );
489  break;
490  case 11: // start->end : 2->3
491  pmin.set(-rmax,std::min(rmax*sinStart,rmax*sinEnd));
492  pmax.set(rmax,rmax);
493  break;
494  // start quadrant 3
495  case 12: // start->end : 3->0
496  pmin.set(rmax*cosStart,-rmax);
497  pmax.set(rmax,rmax*sinEnd);
498  break;
499  case 13: // start->end : 3->1
500  pmin.set(std::min(rmax*cosStart,rmax*cosEnd),-rmax);
501  pmax.set(rmax,rmax);
502  break;
503  case 14: // start->end : 3->2
504  pmin.set(rmax*cosStart,-rmax);
505  pmax.set(rmax*cosEnd,std::max(rmin*sinStart,rmin*sinEnd));
506  break;
507  case 15: // start->end : 3->3
508  if (sinEnd > sinStart) break;
509  pmin.set(rmax*cosStart,rmax*sinEnd);
510  pmax.set(rmin*cosEnd,rmin*sinStart);
511  break;
512  }
513  return;
514 }
G4double GetSurfaceTolerance() const
int G4int
Definition: G4Types.hh:78
void set(double x, double y)
const G4double kCarTolerance
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
double G4double
Definition: G4Types.hh:76
static G4GeometryTolerance * GetInstance()

Here is the call graph for this function:

G4double G4GeomTools::DistancePointSegment ( G4ThreeVector  P,
G4ThreeVector  A,
G4ThreeVector  B 
)
static

Definition at line 520 of file G4GeomTools.cc.

523 {
524  G4ThreeVector AP = P - A;
525  G4ThreeVector AB = B - A;
526 
527  G4double u = AP.dot(AB);
528  if (u <= 0) return AP.mag(); // closest point is A
529 
530  G4double len2 = AB.mag2();
531  if (u >= len2) return (B-P).mag(); // closest point is B
532 
533  return ((u/len2)*AB - AP).mag(); // distance to line
534 }
double dot(const Hep3Vector &) const
double A(double temperature)
double mag2() const
double G4double
Definition: G4Types.hh:76
double mag() const

Here is the call graph for this function:

G4bool G4GeomTools::IsConvex ( const G4TwoVectorList polygon)
static

Definition at line 150 of file G4GeomTools.cc.

151 {
152  static const G4double kCarTolerance =
154 
155  G4bool gotNegative = false;
156  G4bool gotPositive = false;
157  G4int n = polygon.size();
158  if (n <= 0) return false;
159  for (G4int icur=0; icur<n; ++icur)
160  {
161  G4int iprev = (icur == 0) ? n-1 : icur-1;
162  G4int inext = (icur == n-1) ? 0 : icur+1;
163  G4TwoVector e1 = polygon[icur] - polygon[iprev];
164  G4TwoVector e2 = polygon[inext] - polygon[icur];
165  G4double cross = e1.x()*e2.y() - e1.y()*e2.x();
166  if (std::abs(cross) < kCarTolerance) return false;
167  if (cross < 0) gotNegative = true;
168  if (cross > 0) gotPositive = true;
169  if (gotNegative && gotPositive) return false;
170  }
171  return true;
172 }
double y() const
double x() const
G4double GetSurfaceTolerance() const
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
const G4double kCarTolerance
double G4double
Definition: G4Types.hh:76
static G4GeometryTolerance * GetInstance()

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4GeomTools::PointInTriangle ( G4double  Px,
G4double  Py,
G4double  Ax,
G4double  Ay,
G4double  Bx,
G4double  By,
G4double  Cx,
G4double  Cy 
)
static

Definition at line 97 of file G4GeomTools.cc.

102 {
103  if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
104  {
105  if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.) return false;
106  if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.) return false;
107  if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.) return false;
108  }
109  else
110  {
111  if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.) return false;
112  if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.) return false;
113  if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.) return false;
114  }
115  return true;
116 }
G4bool G4GeomTools::PointInTriangle ( const G4TwoVector P,
const G4TwoVector A,
const G4TwoVector B,
const G4TwoVector C 
)
static

Definition at line 122 of file G4GeomTools.cc.

126 {
127  G4double Ax = A.x(), Ay = A.y();
128  G4double Bx = B.x(), By = B.y();
129  G4double Cx = C.x(), Cy = C.y();
130  G4double Px = P.x(), Py = P.y();
131  if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
132  {
133  if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.) return false;
134  if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.) return false;
135  if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.) return false;
136  }
137  else
138  {
139  if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.) return false;
140  if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.) return false;
141  if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.) return false;
142  }
143  return true;
144 }
double y() const
double x() const
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4double G4GeomTools::PolygonArea ( const G4TwoVectorList polygon)
static

Definition at line 82 of file G4GeomTools.cc.

83 {
84  G4double area = 0.0;
85  G4int n = p.size();
86  for(G4int i=0,k=n-1; i<n; k=i,++i)
87  {
88  area += p[k].x()*p[i].y() - p[i].x()*p[k].y();
89  }
90  return area*0.5;
91 }
const char * p
Definition: xmltok.h:285
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76

Here is the caller graph for this function:

G4double G4GeomTools::QuadArea ( const G4TwoVector A,
const G4TwoVector B,
const G4TwoVector C,
const G4TwoVector D 
)
static

Definition at line 70 of file G4GeomTools.cc.

74 {
75  return ((C.x()-A.x())*(D.y()-B.y()) - (C.y()-A.y())*(D.x()-B.x()))*0.5;
76 }
double y() const
double x() const

Here is the call graph for this function:

void G4GeomTools::RemoveRedundantVertices ( G4TwoVectorList polygon,
std::vector< G4int > &  iout,
G4double  tolerance = 0 
)
static

Definition at line 293 of file G4GeomTools.cc.

296 {
297  iout.resize(0);
298  // set tolerance squared
299  G4double delta = tolerance*tolerance;
300  // set special value to mark vertices for removal
301  G4double removeIt = kInfinity;
302 
303  G4int nv = polygon.size();
304 
305  // Main loop: check every three consecutive points, if the points
306  // are collinear then mark middle point for removal
307  //
308  G4int icur = 0, iprev = 0, inext = 0, nout = 0;
309  for (G4int i=0; i<nv; ++i)
310  {
311  icur = i; // index of current point
312 
313  for (G4int k=1; k<nv+1; ++k) // set index of previous point
314  {
315  iprev = icur - k;
316  if (iprev < 0) iprev += nv;
317  if (polygon[iprev].x() != removeIt) break;
318  }
319 
320  for (G4int k=1; k<nv+1; ++k) // set index of next point
321  {
322  inext = icur + k;
323  if (inext >= nv) inext -= nv;
324  if (polygon[inext].x() != removeIt) break;
325  }
326 
327  if (iprev == inext) break; // degenerate polygon, stop
328 
329  // Calculate parameters of triangle (iprev->icur->inext),
330  // if triangle is too small or too narrow then mark current
331  // point for removal
332  G4TwoVector e1 = polygon[iprev] - polygon[icur];
333  G4TwoVector e2 = polygon[inext] - polygon[icur];
334 
335  // Check length of edges, then check height of the triangle
336  G4double leng1 = e1.mag2();
337  G4double leng2 = e2.mag2();
338  G4double leng3 = (e2-e1).mag2();
339  if (leng1 <= delta || leng2 <= delta || leng3 <= delta)
340  {
341  polygon[icur].setX(removeIt); nout++;
342  }
343  else
344  {
345  G4double lmax = std::max(std::max(leng1,leng2),leng3);
346  G4double area = std::abs(e1.x()*e2.y()-e1.y()*e2.x())*0.5;
347  if (area/std::sqrt(lmax) <= std::abs(tolerance))
348  {
349  polygon[icur].setX(removeIt); nout++;
350  }
351  }
352  }
353 
354  // Remove marked points
355  //
356  icur = 0;
357  if (nv - nout < 3) // degenerate polygon, remove all points
358  {
359  for (G4int i=0; i<nv; ++i) iout.push_back(i);
360  polygon.resize(0);
361  nv = 0;
362  }
363  for (G4int i=0; i<nv; ++i) // move points, if required
364  {
365  if (polygon[i].x() != removeIt)
366  polygon[icur++] = polygon[i];
367  else
368  iout.push_back(i);
369  }
370  if (icur < nv) polygon.resize(icur);
371  return;
372 }
double y() const
double x() const
static const G4double kInfinity
Definition: geomdefs.hh:42
int G4int
Definition: G4Types.hh:78
double mag2() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4GeomTools::SphereExtent ( G4double  rmin,
G4double  rmax,
G4double  startTheta,
G4double  delTheta,
G4double  startPhi,
G4double  delPhi,
G4ThreeVector pmin,
G4ThreeVector pmax 
)
static

Definition at line 542 of file G4GeomTools.cc.

546 {
547  static const G4double kCarTolerance =
549 
550  // check parameters
551  //
552  pmin.set(0,0,0);
553  pmax.set(0,0,0);
554  if (rmin < 0) return false;
555  if (rmax <= rmin + kCarTolerance) return false;
556  if (delTheta <= 0 + kCarTolerance) return false;
557  if (delPhi <= 0 + kCarTolerance) return false;
558 
559  G4double stheta = startTheta;
560  G4double dtheta = delTheta;
561  if (stheta < 0 && stheta > CLHEP::pi) return false;
562  if (stheta + dtheta > CLHEP::pi) dtheta = CLHEP::pi - stheta;
563  if (dtheta <= 0 + kCarTolerance) return false;
564 
565  // calculate extent
566  //
567  pmin.set(-rmax,-rmax,-rmax);
568  pmax.set( rmax, rmax, rmax);
569  if (dtheta >= CLHEP::pi && delPhi >= CLHEP::twopi) return true;
570 
571  G4double etheta = stheta + dtheta;
572  G4double sinStart = std::sin(stheta);
573  G4double cosStart = std::cos(stheta);
574  G4double sinEnd = std::sin(etheta);
575  G4double cosEnd = std::cos(etheta);
576 
577  G4double rhomin = rmin*std::min(sinStart,sinEnd);
578  G4double rhomax = rmax;
579  if (stheta > CLHEP::halfpi) rhomax = rmax*sinStart;
580  if (etheta < CLHEP::halfpi) rhomax = rmax*sinEnd;
581 
582  G4TwoVector xymin,xymax;
583  DiskExtent(rhomin,rhomax,
584  std::sin(startPhi),std::cos(startPhi),
585  std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
586  xymin,xymax);
587 
588  G4double zmin = std::min(rmin*cosEnd,rmax*cosEnd);
589  G4double zmax = std::max(rmin*cosStart,rmax*cosStart);
590  pmin.set(xymin.x(),xymin.y(),zmin);
591  pmax.set(xymax.x(),xymax.y(),zmax);
592  return true;
593 }
void set(double x, double y, double z)
double y() const
double x() const
G4double GetSurfaceTolerance() const
const G4double kCarTolerance
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
static constexpr double halfpi
Definition: SystemOfUnits.h:56
double G4double
Definition: G4Types.hh:76
static constexpr double twopi
Definition: SystemOfUnits.h:55
static constexpr double pi
Definition: SystemOfUnits.h:54
static G4bool DiskExtent(G4double rmin, G4double rmax, G4double startPhi, G4double delPhi, G4TwoVector &pmin, G4TwoVector &pmax)
Definition: G4GeomTools.cc:378
static G4GeometryTolerance * GetInstance()

Here is the call graph for this function:

G4double G4GeomTools::TriangleArea ( G4double  Ax,
G4double  Ay,
G4double  Bx,
G4double  By,
G4double  Cx,
G4double  Cy 
)
static

Definition at line 47 of file G4GeomTools.cc.

50 {
51  return ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax))*0.5;
52 }
G4double G4GeomTools::TriangleArea ( const G4TwoVector A,
const G4TwoVector B,
const G4TwoVector C 
)
static

Definition at line 58 of file G4GeomTools.cc.

61 {
62  G4double Ax = A.x(), Ay = A.y();
63  return ((B.x()-Ax)*(C.y()-Ay) - (B.y()-Ay)*(C.x()-Ax))*0.5;
64 }
double y() const
double x() const
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4bool G4GeomTools::TriangulatePolygon ( const G4TwoVectorList polygon,
G4TwoVectorList result 
)
static

Definition at line 178 of file G4GeomTools.cc.

180 {
181  result.resize(0);
182  std::vector<G4int> triangles;
183  G4bool reply = TriangulatePolygon(polygon,triangles);
184 
185  G4int n = triangles.size();
186  for (G4int i=0; i<n; ++i) result.push_back(polygon[triangles[i]]);
187  return reply;
188 }
G4double G4ParticleHPJENDLHEData::G4double result
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
static G4bool TriangulatePolygon(const G4TwoVectorList &polygon, G4TwoVectorList &result)
Definition: G4GeomTools.cc:178

Here is the caller graph for this function:

G4bool G4GeomTools::TriangulatePolygon ( const G4TwoVectorList polygon,
std::vector< G4int > &  result 
)
static

Definition at line 194 of file G4GeomTools.cc.

196 {
197  result.resize(0);
198 
199  // allocate and initialize list of Vertices in polygon
200  //
201  G4int n = polygon.size();
202  if (n < 3) return false;
203 
204  // we want a counter-clockwise polygon in V
205  //
206  G4double area = G4GeomTools::PolygonArea(polygon);
207  G4int* V = new G4int[n];
208  if (area > 0.)
209  for (G4int i=0; i<n; ++i) V[i] = i;
210  else
211  for (G4int i=0; i<n; ++i) V[i] = (n-1)-i;
212 
213  // Triangulation: remove nv-2 Vertices, creating 1 triangle every time
214  //
215  G4int nv = n;
216  G4int count = 2*nv; // error detection counter
217  for(G4int b=nv-1; nv>2; )
218  {
219  // ERROR: if we loop, it is probably a non-simple polygon
220  if ((count--) <= 0)
221  {
222  delete[] V;
223  if (area < 0.) std::reverse(result.begin(),result.end());
224  return false;
225  }
226 
227  // three consecutive vertices in current polygon, <a,b,c>
228  G4int a = (b < nv) ? b : 0; // previous
229  b = (a+1 < nv) ? a+1 : 0; // current
230  G4int c = (b+1 < nv) ? b+1 : 0; // next
231 
232  if (CheckSnip(polygon, a,b,c, nv,V))
233  {
234  // output Triangle
235  result.push_back(V[a]);
236  result.push_back(V[b]);
237  result.push_back(V[c]);
238 
239  // remove vertex b from remaining polygon
240  nv--;
241  for(G4int i=b; i<nv; ++i) V[i] = V[i+1];
242 
243  count = 2*nv; // resest error detection counter
244  }
245  }
246  delete[] V;
247  if (area < 0.) std::reverse(result.begin(),result.end());
248  return true;
249 }
G4double G4ParticleHPJENDLHEData::G4double result
static G4double PolygonArea(const G4TwoVectorList &polygon)
Definition: G4GeomTools.cc:82
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:


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