Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
UIntersectingCone Class Reference

#include <UIntersectingCone.hh>

Public Member Functions

 UIntersectingCone (const double r[2], const double z[2])
 
virtual ~UIntersectingCone ()
 
int LineHitsCone (const UVector3 &p, const UVector3 &v, double &s1, double &s2)
 
bool HitOn (const double r, const double z)
 
double RLo () const
 
double RHi () const
 
double ZLo () const
 
double ZHi () const
 

Protected Member Functions

int LineHitsCone1 (const UVector3 &p, const UVector3 &v, double &s1, double &s2)
 
int LineHitsCone1Optimized (const UVector3 &p, const UVector3 &v, double &s1, double &s2)
 
int LineHitsCone2 (const UVector3 &p, const UVector3 &v, double &s1, double &s2)
 

Protected Attributes

double zLo
 
double zHi
 
double rLo
 
double rHi
 
bool type1
 
double A
 
double B
 

Static Protected Attributes

static const double EpsilonQuad = 1.0 / 9.0E99
 

Detailed Description

Definition at line 27 of file UIntersectingCone.hh.

Constructor & Destructor Documentation

UIntersectingCone::UIntersectingCone ( const double  r[2],
const double  z[2] 
)

Definition at line 29 of file UIntersectingCone.cc.

References A, B, rHi, rLo, VUSolid::Tolerance(), type1, zHi, and zLo.

31 {
32  static const double halfCarTolerance
33  = 0.5 * VUSolid::Tolerance(); // UGeometryTolerance::GetInstance()->GetSurfaceTolerance();
34 
35  //
36  // What type of cone are we?
37  //
38  type1 = (std::fabs(z[1] - z[0]) > std::fabs(r[1] - r[0]));
39 
40  if (type1)
41  {
42  B = (r[1] - r[0]) / (z[1] - z[0]); // tube like
43  A = 0.5 * (r[1] + r[0] - B * (z[1] + z[0]));
44  }
45  else
46  {
47  B = (z[1] - z[0]) / (r[1] - r[0]); // disk like
48  A = 0.5 * (z[1] + z[0] - B * (r[1] + r[0]));
49  }
50  //
51  // Calculate extent
52  //
53  if (r[0] < r[1])
54  {
55  rLo = r[0] - halfCarTolerance;
56  rHi = r[1] + halfCarTolerance;
57  }
58  else
59  {
60  rLo = r[1] - halfCarTolerance;
61  rHi = r[0] + halfCarTolerance;
62  }
63 
64  if (z[0] < z[1])
65  {
66  zLo = z[0] - halfCarTolerance;
67  zHi = z[1] + halfCarTolerance;
68  }
69  else
70  {
71  zLo = z[1] - halfCarTolerance;
72  zHi = z[0] + halfCarTolerance;
73  }
74 }
G4double z
Definition: TRTMaterials.hh:39
static double Tolerance()
Definition: VUSolid.hh:127
UIntersectingCone::~UIntersectingCone ( )
virtual

Definition at line 92 of file UIntersectingCone.cc.

93 {
94 }

Member Function Documentation

bool UIntersectingCone::HitOn ( const double  r,
const double  z 
)

Definition at line 103 of file UIntersectingCone.cc.

References rHi, type1, and zHi.

Referenced by UPolyconeSide::PointOnCone().

105 {
106  //
107  // Be careful! The inequalities cannot be "<=" and ">=" here without
108  // punching a tiny hole in our shape!
109  //
110  if (type1)
111  {
112  if (z < zLo || z > zHi) return false;
113  }
114  else
115  {
116  if (r < rLo || r > rHi) return false;
117  }
118 
119  return true;
120 }
int UIntersectingCone::LineHitsCone ( const UVector3 p,
const UVector3 v,
double &  s1,
double &  s2 
)

Definition at line 129 of file UIntersectingCone.cc.

References LineHitsCone1(), LineHitsCone2(), and type1.

Referenced by UPolyhedraSide::Distance(), UPolyconeSide::Distance(), and UPolyhedraSide::LineHitsSegments().

130 {
131  if (type1)
132  {
133  return LineHitsCone1(p, v, s1, s2);
134  }
135  else
136  {
137  return LineHitsCone2(p, v, s1, s2);
138  }
139 }
int LineHitsCone1(const UVector3 &p, const UVector3 &v, double &s1, double &s2)
int LineHitsCone2(const UVector3 &p, const UVector3 &v, double &s1, double &s2)
int UIntersectingCone::LineHitsCone1 ( const UVector3 p,
const UVector3 v,
double &  s1,
double &  s2 
)
protected

Definition at line 209 of file UIntersectingCone.cc.

References test::a, A, test::b, B, test::c, EpsilonQuad, UUtils::sqr(), UVector3::x, UVector3::y, UVector3::z, and G4InuclParticleNames::z0.

Referenced by LineHitsCone().

210 {
211  double x0 = p.x, y0 = p.y, z0 = p.z;
212  double tx = v.x, ty = v.y, tz = v.z;
213 
214  double a = tx * tx + ty * ty - UUtils::sqr(B * tz);
215  double b = 2 * (x0 * tx + y0 * ty - (A * B + B * B * z0) * tz);
216  double c = x0 * x0 + y0 * y0 - UUtils::sqr(A + B * z0);
217 
218  double radical = b * b - 4 * a * c;
219  double radicalSqrt;
220 
221  double minRadical = 1E-6 * std::fabs(b);
222 
223  if (radical < -minRadical)
224  {
225  return 0; // No solution
226  }
227 
228  if (radical < minRadical)
229  {
230  //
231  // The radical is roughly zero: check for special, very rare, cases
232  //
233  if (std::fabs(a) > EpsilonQuad)
234  {
235  if (B == 0.)
236  {
237  return 0;
238  }
239  if (std::fabs(x0 * ty - y0 * tx) < std::fabs(1E-6 / B))
240  {
241  s1 = -0.5 * b / a;
242  return 1;
243  }
244  return 0;
245  }
246  radicalSqrt = radical; //TODO: check this case
247  }
248  else
249  {
250  radicalSqrt = std::sqrt(radical);
251  }
252 
253  if (a > EpsilonQuad)
254  {
255  double sa, sb, q = -0.5 * (b + (b < 0 ? -radicalSqrt : +radicalSqrt));
256  sa = q / a;
257  sb = c / q;
258  if (sa < sb)
259  {
260  s1 = sa;
261  s2 = sb;
262  }
263  else
264  {
265  s1 = sb;
266  s2 = sa;
267  }
268  if (A + B * (z0 + (s1)*tz) < 0)
269  {
270  return 0;
271  }
272  // if ((z0 + (s1)*tz - A)/B < 0) { return 0; } // these lines are equivalent
273  return 2;
274  }
275  else if (a < -EpsilonQuad)
276  {
277  double sa, sb, q = -0.5 * (b + (b < 0 ? -radicalSqrt : +radicalSqrt));
278  sa = q / a;
279  sb = c / q;
280  s1 = (tz * B > 0) ^ (sa > sb) ? sb : sa;
281  return 1;
282  }
283  else if (std::fabs(b) < EpsilonQuad)
284  {
285  return 0;
286  }
287  else
288  {
289  s1 = -c / b;
290  if (A + B * (z0 + (s1)*tz) < 0)
291  {
292  return 0;
293  }
294  return 1;
295  }
296 }
double x
Definition: UVector3.hh:136
static const double EpsilonQuad
T sqr(const T &x)
Definition: UUtils.hh:142
double z
Definition: UVector3.hh:138
double y
Definition: UVector3.hh:137
int UIntersectingCone::LineHitsCone1Optimized ( const UVector3 p,
const UVector3 v,
double &  s1,
double &  s2 
)
protected

Definition at line 301 of file UIntersectingCone.cc.

References test::a, A, test::b, B, test::c, EpsilonQuad, UUtils::sqr(), UVector3::x, UVector3::y, UVector3::z, and G4InuclParticleNames::z0.

302 {
303  double x0 = p.x, y0 = p.y, z0 = p.z;
304  double tx = v.x, ty = v.y, tz = v.z;
305 
306  double a = tx * tx + ty * ty - UUtils::sqr(B * tz);
307  double b = 2 * (x0 * tx + y0 * ty - (A * B + B * B * z0) * tz);
308  double c = x0 * x0 + y0 * y0 - UUtils::sqr(A + B * z0);
309 
310  double radical = b * b - 4 * a * c;
311 
312  double minRadical = 1E-6 * std::fabs(b);
313 
314  if (radical < -minRadical)
315  {
316  return 0; // No solution
317  }
318 
319  if (std::fabs(a) > EpsilonQuad)
320  {
321  if (radical < minRadical)
322  {
323  //
324  // The radical is roughly zero: check for special, very rare, cases
325  //
326 
327  if (B == 0.)
328  {
329  return 0;
330  }
331  if (std::fabs(x0 * ty - y0 * tx) < std::fabs(1E-6 / B))
332  {
333  s1 = -0.5 * b / a;
334  return 1;
335  }
336  return 0;
337  }
338  else
339  {
340  double radicalSqrt = std::sqrt(radical);
341 
342  if (a > 0)
343  {
344  double sa, sb, q = -0.5 * (b + (b < 0 ? -radicalSqrt : +radicalSqrt));
345  sa = q / a;
346  sb = c / q;
347  if (sa < sb)
348  {
349  s1 = sa;
350  s2 = sb;
351  }
352  else
353  {
354  s1 = sb;
355  s2 = sa;
356  }
357  if (A + B * (z0 + (s1)*tz) < 0)
358  {
359  return 0;
360  }
361  // if ((z0 + (s1)*tz - A)/B < 0) { return 0; } // these lines are equivalent
362  return 2;
363  }
364  else
365  {
366  double sa, sb, q = -0.5 * (b + (b < 0 ? -radicalSqrt : +radicalSqrt));
367  sa = q / a;
368  sb = c / q;
369  s1 = (tz * B > 0) ^ (sa > sb) ? sb : sa;
370  return 1;
371  }
372 
373  }
374  }
375 
376  if (std::fabs(b) < EpsilonQuad)
377  {
378  return 0;
379  }
380  else
381  {
382  s1 = -c / b;
383  if (A + B * (z0 + (s1)*tz) < 0)
384  {
385  return 0;
386  }
387  return 1;
388  }
389 }
double x
Definition: UVector3.hh:136
static const double EpsilonQuad
T sqr(const T &x)
Definition: UUtils.hh:142
double z
Definition: UVector3.hh:138
double y
Definition: UVector3.hh:137
int UIntersectingCone::LineHitsCone2 ( const UVector3 p,
const UVector3 v,
double &  s1,
double &  s2 
)
protected

Definition at line 416 of file UIntersectingCone.cc.

References test::a, A, test::b, B, test::c, EpsilonQuad, UUtils::sqr(), UVector3::x, UVector3::y, UVector3::z, and G4InuclParticleNames::z0.

Referenced by LineHitsCone().

419 {
420  double x0 = p.x, y0 = p.y, z0 = p.z;
421  double tx = v.x, ty = v.y, tz = v.z;
422 
423  // Special case which might not be so rare: B = 0 (precisely)
424  //
425  if (B == 0)
426  {
427  if (std::fabs(tz) < EpsilonQuad)
428  {
429  return 0;
430  }
431 
432  s1 = (A - z0) / tz;
433  return 1;
434  }
435 
436  double B2 = B * B;
437 
438  double a = tz * tz - B2 * (tx * tx + ty * ty);
439  double b = 2 * ((z0 - A) * tz - B2 * (x0 * tx + y0 * ty));
440  double c = UUtils::sqr(z0 - A) - B2 * (x0 * x0 + y0 * y0);
441 
442  double radical = b * b - 4 * a * c;
443 
444  if (radical < -1E-6 * std::fabs(b))
445  {
446  return 0; // No solution
447  }
448 
449  if (radical < 1E-6 * std::fabs(b))
450  {
451  //
452  // The radical is roughly zero: check for special, very rare, cases
453  //
454  if (std::fabs(a) > EpsilonQuad)
455  {
456  if (std::fabs(x0 * ty - y0 * tx) < std::fabs(1E-6 / B))
457  {
458  s1 = -0.5 * b / a;
459  return 1;
460  }
461  return 0;
462  }
463  }
464  else
465  {
466  radical = std::sqrt(radical);
467  }
468 
469  if (a < -EpsilonQuad)
470  {
471  double sa, sb, q = -0.5 * (b + (b < 0 ? -radical : +radical));
472  sa = q / a;
473  sb = c / q;
474  if (sa < sb)
475  {
476  s1 = sa;
477  s2 = sb;
478  }
479  else
480  {
481  s1 = sb;
482  s2 = sa;
483  }
484  if ((z0 + (s1)*tz - A) / B < 0)
485  {
486  return 0;
487  }
488  return 2;
489  }
490  else if (a > EpsilonQuad)
491  {
492  double sa, sb, q = -0.5 * (b + (b < 0 ? -radical : +radical));
493  sa = q / a;
494  sb = c / q;
495  s1 = (tz * B > 0) ^ (sa > sb) ? sb : sa;
496  return 1;
497  }
498  else if (std::fabs(b) < EpsilonQuad)
499  {
500  return 0;
501  }
502  else
503  {
504  s1 = -c / b;
505  if ((z0 + (s1)*tz - A) / B < 0)
506  {
507  return 0;
508  }
509  return 1;
510  }
511 }
double x
Definition: UVector3.hh:136
static const double EpsilonQuad
T sqr(const T &x)
Definition: UUtils.hh:142
double z
Definition: UVector3.hh:138
double y
Definition: UVector3.hh:137
double UIntersectingCone::RHi ( ) const
inline

Definition at line 42 of file UIntersectingCone.hh.

References rHi.

43  {
44  return rHi;
45  }
double UIntersectingCone::RLo ( ) const
inline

Definition at line 38 of file UIntersectingCone.hh.

References rLo.

39  {
40  return rLo;
41  }
double UIntersectingCone::ZHi ( ) const
inline

Definition at line 50 of file UIntersectingCone.hh.

References zHi.

Referenced by UPolyhedraSide::Extent(), and UPolyconeSide::Extent().

51  {
52  return zHi;
53  }
double UIntersectingCone::ZLo ( ) const
inline

Definition at line 46 of file UIntersectingCone.hh.

References zLo.

Referenced by UPolyhedraSide::Extent(), and UPolyconeSide::Extent().

47  {
48  return zLo;
49  }

Field Documentation

double UIntersectingCone::A
protected
double UIntersectingCone::B
protected
const double UIntersectingCone::EpsilonQuad = 1.0 / 9.0E99
staticprotected

Definition at line 88 of file UIntersectingCone.hh.

Referenced by LineHitsCone1(), LineHitsCone1Optimized(), and LineHitsCone2().

double UIntersectingCone::rHi
protected

Definition at line 67 of file UIntersectingCone.hh.

Referenced by HitOn(), RHi(), and UIntersectingCone().

double UIntersectingCone::rLo
protected

Definition at line 67 of file UIntersectingCone.hh.

Referenced by RLo(), and UIntersectingCone().

bool UIntersectingCone::type1
protected

Definition at line 70 of file UIntersectingCone.hh.

Referenced by HitOn(), LineHitsCone(), and UIntersectingCone().

double UIntersectingCone::zHi
protected

Definition at line 67 of file UIntersectingCone.hh.

Referenced by HitOn(), UIntersectingCone(), and ZHi().

double UIntersectingCone::zLo
protected

Definition at line 67 of file UIntersectingCone.hh.

Referenced by UIntersectingCone(), and ZLo().


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