G4TessellatedGeometryAlgorithms Class Reference

#include <G4TessellatedGeometryAlgorithms.hh>


Static Public Member Functions

static G4bool IntersectLineAndTriangle2D (const G4TwoVector &p, const G4TwoVector &v, const G4TwoVector &p0, const G4TwoVector &e0, const G4TwoVector &e1, G4TwoVector location[2])
static G4int IntersectLineAndLineSegment2D (const G4TwoVector &p0, const G4TwoVector &d0, const G4TwoVector &p1, const G4TwoVector &d1, G4TwoVector location[2])
static G4double cross (const G4TwoVector &v1, const G4TwoVector &v2)


Detailed Description

Definition at line 77 of file G4TessellatedGeometryAlgorithms.hh.


Member Function Documentation

G4double G4TessellatedGeometryAlgorithms::cross ( const G4TwoVector v1,
const G4TwoVector v2 
) [static]

Definition at line 250 of file G4TessellatedGeometryAlgorithms.cc.

Referenced by IntersectLineAndLineSegment2D().

00252 {
00253   return v1.x()*v2.y() - v1.y()*v2.x();
00254 }

G4int G4TessellatedGeometryAlgorithms::IntersectLineAndLineSegment2D ( const G4TwoVector p0,
const G4TwoVector d0,
const G4TwoVector p1,
const G4TwoVector d1,
G4TwoVector  location[2] 
) [static]

Definition at line 176 of file G4TessellatedGeometryAlgorithms.cc.

References cross(), DBL_EPSILON, and G4InuclParticleNames::s0.

Referenced by IntersectLineAndTriangle2D().

00180 {
00181   G4TwoVector e     = p1 - p0;
00182   G4double kross    = cross(d0,d1);
00183   G4double sqrKross = kross * kross;
00184   G4double sqrLen0  = d0.mag2();
00185   G4double sqrLen1  = d1.mag2();
00186   location[0]       = G4TwoVector(0.0,0.0);
00187   location[1]       = G4TwoVector(0.0,0.0);
00188 
00189   if (sqrKross > DBL_EPSILON * DBL_EPSILON * sqrLen0 * sqrLen1)
00190   {
00191     //
00192     // The line and line segment are not parallel. Determine if the intersection
00193     // is in positive s where r=p0 + s*d0, and for 0<=t<=1 where r=p1 + t*d1.
00194     //
00195     G4double ss = cross(e,d1)/kross;
00196     if (ss < 0)         return 0; // Intersection does not occur for positive ss
00197     G4double t = cross(e,d0)/kross;
00198     if (t < 0 || t > 1) return 0; // Intersection does not occur on line-segment
00199     //
00200     // Intersection of lines is a single point on the forward-propagating line
00201     // defined by r=p0 + ss*d0, and the line segment defined by  r=p1 + t*d1.
00202     //
00203     location[0] = p0 + ss*d0;
00204     return 1;
00205   }
00206   //
00207   // Line and line segment are parallel. Determine whether they overlap or not.
00208   //
00209   G4double sqrLenE = e.mag2();
00210   kross            = cross(e,d0);
00211   sqrKross         = kross * kross;
00212   if (sqrKross > DBL_EPSILON * DBL_EPSILON * sqrLen0 * sqrLenE)
00213   {
00214     return 0; //Lines are different.
00215   }
00216   //
00217   // Lines are the same.  Test for overlap.
00218   //
00219   G4double s0   = d0.dot(e)/sqrLen0;
00220   G4double s1   = s0 + d0.dot(d1)/sqrLen0;
00221   G4double smin = 0.0;
00222   G4double smax = 0.0;
00223 
00224   if (s0 < s1) {smin = s0; smax = s1;}
00225   else         {smin = s1; smax = s0;}
00226 
00227   if (smax < 0.0) return 0;
00228   else if (smin < 0.0)
00229   {
00230     location[0] = p0;
00231     location[1] = p0 + smax*d0;
00232     return 2;
00233   }
00234   else
00235   {
00236     location[0] = p0 + smin*d0;
00237     location[1] = p0 + smax*d0;
00238     return 2;
00239   }
00240 }

G4bool G4TessellatedGeometryAlgorithms::IntersectLineAndTriangle2D ( const G4TwoVector p,
const G4TwoVector v,
const G4TwoVector p0,
const G4TwoVector e0,
const G4TwoVector e1,
G4TwoVector  location[2] 
) [static]

Definition at line 68 of file G4TessellatedGeometryAlgorithms.cc.

References IntersectLineAndLineSegment2D().

Referenced by G4TriangularFacet::Intersect().

00072 {
00073   G4TwoVector loc0[2];
00074   G4int e0i = IntersectLineAndLineSegment2D (p,v,p0,e0,loc0);
00075   if (e0i == 2)
00076   {
00077     location[0] = loc0[0];
00078     location[1] = loc0[1];
00079     return true;
00080   }
00081 
00082   G4TwoVector loc1[2];
00083   G4int e1i = IntersectLineAndLineSegment2D (p,v,p0,e1,loc1);
00084   if (e1i == 2)
00085   {
00086     location[0] = loc1[0];
00087     location[1] = loc1[1];
00088     return true;
00089   }
00090 
00091   if ((e0i == 1) && (e1i == 1))
00092   {
00093     if ((loc0[0]-p).mag2() < (loc1[0]-p).mag2())
00094     {
00095       location[0] = loc0[0];
00096       location[1] = loc1[0];
00097     }
00098     else
00099     {
00100       location[0] = loc1[0];
00101       location[1] = loc0[0];
00102     }
00103     return true;
00104   }
00105 
00106   G4TwoVector p1 = p0 + e0;
00107   G4TwoVector DE = e1 - e0;
00108   G4TwoVector loc2[2];
00109   G4int e2i = IntersectLineAndLineSegment2D (p,v,p1,DE,loc2);
00110   if (e2i == 2)
00111   {
00112     location[0] = loc2[0];
00113     location[1] = loc2[1];
00114     return true;
00115   }
00116 
00117   if ((e0i == 0) && (e1i == 0) && (e2i == 0)) return false;
00118 
00119   if ((e0i == 1) && (e2i == 1))
00120   {
00121     if ((loc0[0]-p).mag2() < (loc2[0]-p).mag2())
00122     {
00123       location[0] = loc0[0];
00124       location[1] = loc2[0];
00125     }
00126     else
00127     {
00128       location[0] = loc2[0];
00129       location[1] = loc0[0];
00130     }
00131     return true;
00132   }
00133 
00134   if ((e1i == 1) && (e2i == 1))
00135   {
00136     if ((loc1[0]-p).mag2() < (loc2[0]-p).mag2())
00137     {
00138       location[0] = loc1[0];
00139       location[1] = loc2[0];
00140     }
00141     else
00142     {
00143       location[0] = loc2[0];
00144       location[1] = loc1[0];
00145     }
00146     return true;
00147   }
00148 
00149   return false;
00150 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:28 2013 for Geant4 by  doxygen 1.4.7