Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.

252 {
253  return v1.x()*v2.y() - v1.y()*v2.x();
254 }
double y() const
double x() const

Here is the call graph for this function:

Here is the caller graph for this function:

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.

180 {
181  G4TwoVector e = p1 - p0;
182  G4double kross = cross(d0,d1);
183  G4double sqrKross = kross * kross;
184  G4double sqrLen0 = d0.mag2();
185  G4double sqrLen1 = d1.mag2();
186  location[0] = G4TwoVector(0.0,0.0);
187  location[1] = G4TwoVector(0.0,0.0);
188 
189  if (sqrKross > DBL_EPSILON * DBL_EPSILON * sqrLen0 * sqrLen1)
190  {
191  //
192  // The line and line segment are not parallel. Determine if the intersection
193  // is in positive s where r=p0 + s*d0, and for 0<=t<=1 where r=p1 + t*d1.
194  //
195  G4double ss = cross(e,d1)/kross;
196  if (ss < 0) return 0; // Intersection does not occur for positive ss
197  G4double t = cross(e,d0)/kross;
198  if (t < 0 || t > 1) return 0; // Intersection does not occur on line-segment
199  //
200  // Intersection of lines is a single point on the forward-propagating line
201  // defined by r=p0 + ss*d0, and the line segment defined by r=p1 + t*d1.
202  //
203  location[0] = p0 + ss*d0;
204  return 1;
205  }
206  //
207  // Line and line segment are parallel. Determine whether they overlap or not.
208  //
209  G4double sqrLenE = e.mag2();
210  kross = cross(e,d0);
211  sqrKross = kross * kross;
212  if (sqrKross > DBL_EPSILON * DBL_EPSILON * sqrLen0 * sqrLenE)
213  {
214  return 0; //Lines are different.
215  }
216  //
217  // Lines are the same. Test for overlap.
218  //
219  G4double s0 = d0.dot(e)/sqrLen0;
220  G4double s1 = s0 + d0.dot(d1)/sqrLen0;
221  G4double smin = 0.0;
222  G4double smax = 0.0;
223 
224  if (s0 < s1) {smin = s0; smax = s1;}
225  else {smin = s1; smax = s0;}
226 
227  if (smax < 0.0) return 0;
228  else if (smin < 0.0)
229  {
230  location[0] = p0;
231  location[1] = p0 + smax*d0;
232  return 2;
233  }
234  else
235  {
236  location[0] = p0 + smin*d0;
237  location[1] = p0 + smax*d0;
238  return 2;
239  }
240 }
static G4double cross(const G4TwoVector &v1, const G4TwoVector &v2)
const G4int smax
double mag2() const
#define DBL_EPSILON
Definition: templates.hh:87
CLHEP::Hep2Vector G4TwoVector
Definition: G4TwoVector.hh:42
double G4double
Definition: G4Types.hh:76
double dot(const Hep2Vector &p) const

Here is the call graph for this function:

Here is the caller graph for this function:

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.

72 {
73  G4TwoVector loc0[2];
74  G4int e0i = IntersectLineAndLineSegment2D (p,v,p0,e0,loc0);
75  if (e0i == 2)
76  {
77  location[0] = loc0[0];
78  location[1] = loc0[1];
79  return true;
80  }
81 
82  G4TwoVector loc1[2];
83  G4int e1i = IntersectLineAndLineSegment2D (p,v,p0,e1,loc1);
84  if (e1i == 2)
85  {
86  location[0] = loc1[0];
87  location[1] = loc1[1];
88  return true;
89  }
90 
91  if ((e0i == 1) && (e1i == 1))
92  {
93  if ((loc0[0]-p).mag2() < (loc1[0]-p).mag2())
94  {
95  location[0] = loc0[0];
96  location[1] = loc1[0];
97  }
98  else
99  {
100  location[0] = loc1[0];
101  location[1] = loc0[0];
102  }
103  return true;
104  }
105 
106  G4TwoVector p1 = p0 + e0;
107  G4TwoVector DE = e1 - e0;
108  G4TwoVector loc2[2];
109  G4int e2i = IntersectLineAndLineSegment2D (p,v,p1,DE,loc2);
110  if (e2i == 2)
111  {
112  location[0] = loc2[0];
113  location[1] = loc2[1];
114  return true;
115  }
116 
117  if ((e0i == 0) && (e1i == 0) && (e2i == 0)) return false;
118 
119  if ((e0i == 1) && (e2i == 1))
120  {
121  if ((loc0[0]-p).mag2() < (loc2[0]-p).mag2())
122  {
123  location[0] = loc0[0];
124  location[1] = loc2[0];
125  }
126  else
127  {
128  location[0] = loc2[0];
129  location[1] = loc0[0];
130  }
131  return true;
132  }
133 
134  if ((e1i == 1) && (e2i == 1))
135  {
136  if ((loc1[0]-p).mag2() < (loc2[0]-p).mag2())
137  {
138  location[0] = loc1[0];
139  location[1] = loc2[0];
140  }
141  else
142  {
143  location[0] = loc2[0];
144  location[1] = loc1[0];
145  }
146  return true;
147  }
148 
149  return false;
150 }
int G4int
Definition: G4Types.hh:78
static G4int IntersectLineAndLineSegment2D(const G4TwoVector &p0, const G4TwoVector &d0, const G4TwoVector &p1, const G4TwoVector &d1, G4TwoVector location[2])

Here is the call graph for this function:

Here is the caller graph for this function:


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