Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TessellatedGeometryAlgorithms Class Reference

G4TessellatedGeometryAlgorithms contains standard methods to determine whether (and if so where) simple geometric shapes intersect. More...

#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

G4TessellatedGeometryAlgorithms contains standard methods to determine whether (and if so where) simple geometric shapes intersect.

Definition at line 74 of file G4TessellatedGeometryAlgorithms.hh.

Member Function Documentation

◆ cross()

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

Ficticious "cross-product" function for two 2D vectors.

Parameters
[in]v1First 2D vector.
[in]v2Second 2D vector.
Returns
The cross-product of v1 and v2.

Definition at line 243 of file G4TessellatedGeometryAlgorithms.cc.

245{
246 return v1.x()*v2.y() - v1.y()*v2.x();
247}
double x() const
double y() const

Referenced by IntersectLineAndLineSegment2D().

◆ IntersectLineAndLineSegment2D()

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

Determines whether there is an intersection between a line defined by r = p0 + s.d0 and a line-segment with endpoints p1 and p1+d1.

Parameters
[in]p0Coefficient of line equation.
[in]d0Coefficient of line equation.
[in]p1First line-segment end-point..
[in]d1Delta line-segment end-point.
[out]locationThe returned location of the intersection.
Returns
false if no intersection occours.

Definition at line 163 of file G4TessellatedGeometryAlgorithms.cc.

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

Referenced by IntersectLineAndTriangle2D().

◆ IntersectLineAndTriangle2D()

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

Determines whether there is an intersection between a line defined by r = p + s.v and a triangle defined by vertices p0, p0+e0 and p0+e1.

Parameters
[in]pCoefficient of line equation.
[in]vCoefficient of line equation.
[in]p0First vertex of triangle.
[in]e0Second vertex of triangle.
[in]e1Third vertex of triangle.
[out]locationThe returned location of the intersection.
Returns
false if no intersection occours.

Definition at line 55 of file G4TessellatedGeometryAlgorithms.cc.

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

Referenced by G4TriangularFacet::Intersect().


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