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

#include <G4QuadrangularFacet.hh>

+ Inheritance diagram for G4QuadrangularFacet:

Public Member Functions

 G4QuadrangularFacet (const G4ThreeVector &Pt0, const G4ThreeVector &vt1, const G4ThreeVector &vt2, const G4ThreeVector &vt3, G4FacetVertexType)
 
 G4QuadrangularFacet (const G4QuadrangularFacet &right)
 
 ~G4QuadrangularFacet () override
 
G4QuadrangularFacetoperator= (const G4QuadrangularFacet &right)
 
G4VFacetGetClone () override
 
G4ThreeVector Distance (const G4ThreeVector &p)
 
G4double Distance (const G4ThreeVector &p, G4double minDist) override
 
G4double Distance (const G4ThreeVector &p, G4double minDist, const G4bool outgoing) override
 
G4double Extent (const G4ThreeVector axis) override
 
G4bool Intersect (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool outgoing, G4double &distance, G4double &distFromSurface, G4ThreeVector &normal) override
 
G4ThreeVector GetSurfaceNormal () const override
 
G4double GetArea () const override
 
G4ThreeVector GetPointOnFace () const override
 
G4GeometryType GetEntityType () const override
 
G4bool IsDefined () const override
 
G4int GetNumberOfVertices () const override
 
G4ThreeVector GetVertex (G4int i) const override
 
void SetVertex (G4int i, const G4ThreeVector &val) override
 
void SetVertices (std::vector< G4ThreeVector > *v) override
 
G4double GetRadius () const override
 
G4ThreeVector GetCircumcentre () const override
 
- Public Member Functions inherited from G4VFacet
 G4VFacet ()
 
virtual ~G4VFacet ()
 
G4bool operator== (const G4VFacet &right) const
 
void ApplyTranslation (const G4ThreeVector &v)
 
std::ostream & StreamInfo (std::ostream &os) const
 
G4bool IsInside (const G4ThreeVector &p) const
 

Additional Inherited Members

- Protected Attributes inherited from G4VFacet
G4double kCarTolerance
 
- Static Protected Attributes inherited from G4VFacet
static const G4double dirTolerance = 1.0E-14
 

Detailed Description

Definition at line 61 of file G4QuadrangularFacet.hh.

Constructor & Destructor Documentation

◆ G4QuadrangularFacet() [1/2]

G4QuadrangularFacet::G4QuadrangularFacet ( const G4ThreeVector & Pt0,
const G4ThreeVector & vt1,
const G4ThreeVector & vt2,
const G4ThreeVector & vt3,
G4FacetVertexType vertexType )

Definition at line 51 of file G4QuadrangularFacet.cc.

56{
57 G4double delta = 1.0 * kCarTolerance; // dimension tolerance
58 G4double epsilon = 0.01 * kCarTolerance; // planarity tolerance
59
60 G4ThreeVector e1, e2, e3;
61 SetVertex(0, vt0);
62 if (vertexType == ABSOLUTE)
63 {
64 SetVertex(1, vt1);
65 SetVertex(2, vt2);
66 SetVertex(3, vt3);
67
68 e1 = vt1 - vt0;
69 e2 = vt2 - vt0;
70 e3 = vt3 - vt0;
71 }
72 else
73 {
74 SetVertex(1, vt0 + vt1);
75 SetVertex(2, vt0 + vt2);
76 SetVertex(3, vt0 + vt3);
77
78 e1 = vt1;
79 e2 = vt2;
80 e3 = vt3;
81 }
82
83 // Check length of sides and diagonals
84 //
85 G4double leng1 = e1.mag();
86 G4double leng2 = (e2-e1).mag();
87 G4double leng3 = (e3-e2).mag();
88 G4double leng4 = e3.mag();
89
90 G4double diag1 = e2.mag();
91 G4double diag2 = (e3-e1).mag();
92
93 if (leng1 <= delta || leng2 <= delta || leng3 <= delta || leng4 <= delta ||
94 diag1 <= delta || diag2 <= delta)
95 {
96 ostringstream message;
97 message << "Sides/diagonals of facet are too small." << G4endl
98 << "P0 = " << GetVertex(0) << G4endl
99 << "P1 = " << GetVertex(1) << G4endl
100 << "P2 = " << GetVertex(2) << G4endl
101 << "P3 = " << GetVertex(3) << G4endl
102 << "Side1 length (P0->P1) = " << leng1 << G4endl
103 << "Side2 length (P1->P2) = " << leng2 << G4endl
104 << "Side3 length (P2->P3) = " << leng3 << G4endl
105 << "Side4 length (P3->P0) = " << leng4 << G4endl
106 << "Diagonal1 length (P0->P2) = " << diag1 << G4endl
107 << "Diagonal2 length (P1->P3) = " << diag2;
108 G4Exception("G4QuadrangularFacet::G4QuadrangularFacet()",
109 "GeomSolids1001", JustWarning, message);
110 return;
111 }
112
113 // Check that vertices are not collinear
114 //
115 G4double s1 = (e1.cross(e2)).mag()*0.5;
116 G4double s2 = ((e2-e1).cross(e3-e2)).mag()*0.5;
117 G4double s3 = (e2.cross(e3)).mag()*0.5;
118 G4double s4 = (e1.cross(e3)).mag()*0.5;
119
120 G4double h1 = 2.*s1 / std::max(std::max(leng1,leng2),diag1);
121 G4double h2 = 2.*s2 / std::max(std::max(leng2,leng3),diag2);
122 G4double h3 = 2.*s3 / std::max(std::max(leng3,leng4),diag1);
123 G4double h4 = 2.*s4 / std::max(std::max(leng4,leng1),diag2);
124
125 if (h1 <= delta || h2 <= delta || h3 <= delta || h4 <= delta )
126 {
127 ostringstream message;
128 message << "Facet has three or more collinear vertices." << G4endl
129 << "P0 = " << GetVertex(0) << G4endl
130 << "P1 = " << GetVertex(1) << G4endl
131 << "P2 = " << GetVertex(2) << G4endl
132 << "P3 = " << GetVertex(3) << G4endl
133 << "Smallest heights:" << G4endl
134 << " in triangle P0-P1-P2 = " << h1 << G4endl
135 << " in triangle P1-P2-P3 = " << h2 << G4endl
136 << " in triangle P2-P3-P0 = " << h3 << G4endl
137 << " in triangle P3-P0-P1 = " << h4;
138 G4Exception("G4QuadrangularFacet::G4QuadrangularFacet()",
139 "GeomSolids1001", JustWarning, message);
140 return;
141 }
142
143 // Check that vertices are coplanar by computing minimal
144 // height of tetrahedron comprising of vertices
145 //
146 G4double smax = std::max( std::max(s1,s2), std::max(s3,s4) );
147 G4double hmin = 0.5 * std::fabs( e1.dot(e2.cross(e3)) ) / smax;
148 if (hmin >= epsilon)
149 {
150 ostringstream message;
151 message << "Facet is not planar." << G4endl
152 << "Disrepancy = " << hmin << G4endl
153 << "P0 = " << GetVertex(0) << G4endl
154 << "P1 = " << GetVertex(1) << G4endl
155 << "P2 = " << GetVertex(2) << G4endl
156 << "P3 = " << GetVertex(3);
157 G4Exception("G4QuadrangularFacet::G4QuadrangularFacet()",
158 "GeomSolids1001", JustWarning, message);
159 return;
160 }
161
162 // Check that facet is convex by computing crosspoint
163 // of diagonals
164 //
165 G4ThreeVector normal = e2.cross(e3-e1);
166 G4double s = kInfinity, t = kInfinity, magnitude2 = normal.mag2();
167 if (magnitude2 > delta*delta) // check: magnitude2 != 0.
168 {
169 s = normal.dot(e1.cross(e3-e1)) / magnitude2;
170 t = normal.dot(e1.cross(e2)) / magnitude2;
171 }
172 if (s <= 0. || s >= 1. || t <= 0. || t >= 1.)
173 {
174 ostringstream message;
175 message << "Facet is not convex." << G4endl
176 << "Parameters of crosspoint of diagonals: "
177 << s << " and " << t << G4endl
178 << "should both be within (0,1) range" << G4endl
179 << "P0 = " << GetVertex(0) << G4endl
180 << "P1 = " << GetVertex(1) << G4endl
181 << "P2 = " << GetVertex(2) << G4endl
182 << "P3 = " << GetVertex(3);
183 G4Exception("G4QuadrangularFacet::G4QuadrangularFacet()",
184 "GeomSolids1001", JustWarning, message);
185 return;
186 }
187
188 // Define facet
189 //
192
193 normal = normal.unit();
194 fFacet1.SetSurfaceNormal(normal);
195 fFacet2.SetSurfaceNormal(normal);
196
197 G4ThreeVector vtmp = 0.5 * (e1 + e2);
198 fCircumcentre = GetVertex(0) + vtmp;
199 G4double radiusSqr = vtmp.mag2();
200 fRadius = std::sqrt(radiusSqr);
201 // 29.02.2016 Remark by E.Tcherniaev: computation
202 // of fCircumcenter and fRadius is wrong, however
203 // it did not create any problem till now.
204 // Bizarre! Need to investigate!
205}
G4double epsilon(G4double density, G4double temperature)
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
double G4double
Definition G4Types.hh:83
@ ABSOLUTE
Definition G4VFacet.hh:48
#define G4endl
Definition G4ios.hh:67
Hep3Vector unit() const
double mag2() const
Hep3Vector cross(const Hep3Vector &) const
double dot(const Hep3Vector &) const
double mag() const
G4ThreeVector GetVertex(G4int i) const override
void SetVertex(G4int i, const G4ThreeVector &val) override
void SetSurfaceNormal(const G4ThreeVector &normal)
G4double kCarTolerance
Definition G4VFacet.hh:93

Referenced by GetClone().

◆ G4QuadrangularFacet() [2/2]

G4QuadrangularFacet::G4QuadrangularFacet ( const G4QuadrangularFacet & right)

Definition at line 213 of file G4QuadrangularFacet.cc.

214 : G4VFacet(rhs)
215{
216 fFacet1 = rhs.fFacet1;
217 fFacet2 = rhs.fFacet2;
218 fRadius = 0.0;
219}

◆ ~G4QuadrangularFacet()

G4QuadrangularFacet::~G4QuadrangularFacet ( )
overridedefault

Member Function Documentation

◆ Distance() [1/3]

G4ThreeVector G4QuadrangularFacet::Distance ( const G4ThreeVector & p)

Definition at line 246 of file G4QuadrangularFacet.cc.

247{
248 G4ThreeVector v1 = fFacet1.Distance(p);
249 G4ThreeVector v2 = fFacet2.Distance(p);
250
251 if (v1.mag2() < v2.mag2()) return v1;
252 else return v2;
253}
G4ThreeVector Distance(const G4ThreeVector &p)

Referenced by Distance(), and Distance().

◆ Distance() [2/3]

G4double G4QuadrangularFacet::Distance ( const G4ThreeVector & p,
G4double minDist )
overridevirtual

Implements G4VFacet.

Definition at line 257 of file G4QuadrangularFacet.cc.

259{
260 G4double dist = Distance(p).mag();
261 return dist;
262}
G4ThreeVector Distance(const G4ThreeVector &p)

◆ Distance() [3/3]

G4double G4QuadrangularFacet::Distance ( const G4ThreeVector & p,
G4double minDist,
const G4bool outgoing )
overridevirtual

Implements G4VFacet.

Definition at line 266 of file G4QuadrangularFacet.cc.

268{
269 G4double dist;
270
271 G4ThreeVector v = Distance(p);
272 G4double dir = v.dot(GetSurfaceNormal());
273 if ( ((dir > dirTolerance) && (!outgoing))
274 || ((dir < -dirTolerance) && outgoing))
275 dist = kInfinity;
276 else
277 dist = v.mag();
278 return dist;
279}
G4ThreeVector GetSurfaceNormal() const override
static const G4double dirTolerance
Definition G4VFacet.hh:92

◆ Extent()

G4double G4QuadrangularFacet::Extent ( const G4ThreeVector axis)
overridevirtual

Implements G4VFacet.

Definition at line 283 of file G4QuadrangularFacet.cc.

284{
285 G4double ss = 0;
286
287 for (G4int i = 0; i <= 3; ++i)
288 {
289 G4double sp = GetVertex(i).dot(axis);
290 if (sp > ss) ss = sp;
291 }
292 return ss;
293}
int G4int
Definition G4Types.hh:85

◆ GetArea()

G4double G4QuadrangularFacet::GetArea ( ) const
overridevirtual

Implements G4VFacet.

Definition at line 332 of file G4QuadrangularFacet.cc.

333{
334 G4double area = fFacet1.GetArea() + fFacet2.GetArea();
335 return area;
336}
G4double GetArea() const override

◆ GetCircumcentre()

G4ThreeVector G4QuadrangularFacet::GetCircumcentre ( ) const
inlineoverridevirtual

Implements G4VFacet.

Definition at line 136 of file G4QuadrangularFacet.hh.

137{
138 return fCircumcentre;
139}

◆ GetClone()

G4VFacet * G4QuadrangularFacet::GetClone ( )
overridevirtual

Implements G4VFacet.

Definition at line 237 of file G4QuadrangularFacet.cc.

238{
239 auto c = new G4QuadrangularFacet (GetVertex(0), GetVertex(1),
241 return c;
242}
G4QuadrangularFacet(const G4ThreeVector &Pt0, const G4ThreeVector &vt1, const G4ThreeVector &vt2, const G4ThreeVector &vt3, G4FacetVertexType)

◆ GetEntityType()

G4String G4QuadrangularFacet::GetEntityType ( ) const
overridevirtual

Implements G4VFacet.

Definition at line 340 of file G4QuadrangularFacet.cc.

341{
342 return "G4QuadrangularFacet";
343}

◆ GetNumberOfVertices()

G4int G4QuadrangularFacet::GetNumberOfVertices ( ) const
inlineoverridevirtual

Implements G4VFacet.

Definition at line 120 of file G4QuadrangularFacet.hh.

121{
122 return 4;
123}

◆ GetPointOnFace()

G4ThreeVector G4QuadrangularFacet::GetPointOnFace ( ) const
overridevirtual

Implements G4VFacet.

Definition at line 320 of file G4QuadrangularFacet.cc.

321{
322 G4double s1 = fFacet1.GetArea();
323 G4double s2 = fFacet2.GetArea();
324 return ((s1+s2)*G4UniformRand() < s1) ?
325 fFacet1.GetPointOnFace() : fFacet2.GetPointOnFace();
326}
#define G4UniformRand()
Definition Randomize.hh:52
G4ThreeVector GetPointOnFace() const override

◆ GetRadius()

G4double G4QuadrangularFacet::GetRadius ( ) const
inlineoverridevirtual

Implements G4VFacet.

Definition at line 131 of file G4QuadrangularFacet.hh.

132{
133 return fRadius;
134}

◆ GetSurfaceNormal()

G4ThreeVector G4QuadrangularFacet::GetSurfaceNormal ( ) const
overridevirtual

Implements G4VFacet.

Definition at line 347 of file G4QuadrangularFacet.cc.

348{
349 return fFacet1.GetSurfaceNormal();
350}
G4ThreeVector GetSurfaceNormal() const override

Referenced by Distance().

◆ GetVertex()

G4ThreeVector G4QuadrangularFacet::GetVertex ( G4int i) const
inlineoverridevirtual

Implements G4VFacet.

Definition at line 125 of file G4QuadrangularFacet.hh.

126{
127 return i == 3 ? fFacet2.GetVertex(2) : fFacet1.GetVertex(i);
128}
G4ThreeVector GetVertex(G4int i) const override

Referenced by Extent(), G4QuadrangularFacet(), and GetClone().

◆ Intersect()

G4bool G4QuadrangularFacet::Intersect ( const G4ThreeVector & p,
const G4ThreeVector & v,
const G4bool outgoing,
G4double & distance,
G4double & distFromSurface,
G4ThreeVector & normal )
overridevirtual

Implements G4VFacet.

Definition at line 297 of file G4QuadrangularFacet.cc.

303{
304 G4bool intersect =
305 fFacet1.Intersect(p,v,outgoing,distance,distFromSurface,normal);
306 if (!intersect) intersect =
307 fFacet2.Intersect(p,v,outgoing,distance,distFromSurface,normal);
308 if (!intersect)
309 {
310 distance = distFromSurface = kInfinity;
311 normal.set(0,0,0);
312 }
313 return intersect;
314}
bool G4bool
Definition G4Types.hh:86
void set(double x, double y, double z)
G4bool Intersect(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool outgoing, G4double &distance, G4double &distFromSurface, G4ThreeVector &normal) override

◆ IsDefined()

G4bool G4QuadrangularFacet::IsDefined ( ) const
inlineoverridevirtual

Implements G4VFacet.

Definition at line 168 of file G4QuadrangularFacet.hh.

169{
170 return fFacet1.IsDefined();
171}
G4bool IsDefined() const override

◆ operator=()

G4QuadrangularFacet & G4QuadrangularFacet::operator= ( const G4QuadrangularFacet & right)

Definition at line 224 of file G4QuadrangularFacet.cc.

225{
226 if (this == &rhs) return *this;
227
228 fFacet1 = rhs.fFacet1;
229 fFacet2 = rhs.fFacet2;
230 fRadius = 0.0;
231
232 return *this;
233}

◆ SetVertex()

void G4QuadrangularFacet::SetVertex ( G4int i,
const G4ThreeVector & val )
inlineoverridevirtual

Implements G4VFacet.

Definition at line 141 of file G4QuadrangularFacet.hh.

142{
143 switch (i)
144 {
145 case 0:
146 fFacet1.SetVertex(0, val);
147 fFacet2.SetVertex(0, val);
148 break;
149 case 1:
150 fFacet1.SetVertex(1, val);
151 break;
152 case 2:
153 fFacet1.SetVertex(2, val);
154 fFacet2.SetVertex(1, val);
155 break;
156 case 3:
157 fFacet2.SetVertex(2, val);
158 break;
159 }
160}
void SetVertex(G4int i, const G4ThreeVector &val) override

Referenced by G4QuadrangularFacet().

◆ SetVertices()

void G4QuadrangularFacet::SetVertices ( std::vector< G4ThreeVector > * v)
inlineoverridevirtual

Implements G4VFacet.

Definition at line 162 of file G4QuadrangularFacet.hh.

163{
164 fFacet1.SetVertices(v);
165 fFacet2.SetVertices(v);
166}
void SetVertices(std::vector< G4ThreeVector > *v) override

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