GeoModel - GeoModelCore
GeoPgon.cxx
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GeoModelKernel/GeoPgon.h"
6 #include "GeoModelKernel/GeoShapeAction.h"
7 #include <cmath>
8 #include <stdexcept>
9 
10 const std::string GeoPgon::s_classType = "Pgon";
11 const ShapeType GeoPgon::s_classTypeID = 0x14;
12 
13 GeoPgon::GeoPgon (double SPhi, double DPhi, unsigned int NSides)
14  : m_sPhi (SPhi)
15  , m_dPhi (DPhi)
16  , m_nSides (NSides)
17 {
18 }
19 
20 GeoPgon::~GeoPgon()
21 {
22 }
23 
24 double GeoPgon::volume () const
25 {
26  if (!isValid ())
27  throw std::runtime_error ("Volume requested for incomplete polygon");
28  double v = 0;
29  int sides = getNSides ();
30  double alpha = m_dPhi/sides;
31  double sinAlpha = sin(alpha);
32 
33  for (size_t s = 0; s < getNPlanes () - 1; s++) {
34  double z2 = getZPlane (s);;
35  double z1 = getZPlane (s + 1);;
36  double fRmin1 = getRMinPlane (s + 1);
37  double fRmin2 = getRMinPlane (s);
38  double fRmax1 = getRMaxPlane (s + 1);
39  double fRmax2 = getRMaxPlane (s);
40 
41  double b1 = (fRmax1 - fRmax2)/(z1 - z2);
42  double b2 = (fRmin1 - fRmin2)/(z1 - z2);
43 
44  double a1 = fRmax2 - b1 * z2;
45  double a2 = fRmin2 - b2 * z2;
46 
47  //v+=fabs((a1*a1-a2*a2)*(z1-z2) + (a1*b1-a2*b2)*(z1*z1-z2*z2) + (b1*b1-b2*b2)*(z1*z1*z1-z2*z2*z2)/3.);
48  // Equivalent which should be less sensitive to numerical precision errors:
49  v += fabs(z1 - z2) * ((a1 - a2) * (a1 + a2) +
50  (a1*b1 - a2*b2) * (z1 + z2) +
51  (b1 - b2) * (b1 + b2) * (z1*z1+z2*z2+z1*z2)*(1./3));
52  }
53  v *= 0.5 * sides * sinAlpha;
54  return v;
55 }
56 
57 const std::string & GeoPgon::type () const
58 {
59  return s_classType;
60 }
61 
62 ShapeType GeoPgon::typeID () const
63 {
64  return s_classTypeID;
65 }
66 
67 void GeoPgon::addPlane (double ZPlane, double RMinPlane, double RMaxPlane)
68 {
69  m_zPlane.push_back (ZPlane);
70  m_rMinPlane.push_back (RMinPlane);
71  m_rMaxPlane.push_back (RMaxPlane);
72 }
73 
74 void GeoPgon::exec (GeoShapeAction *action) const
75 {
76  action->handlePgon(this);
77 }
This class is a visitor for shapes. It allows a navigation of the boolean expression tree for shapes...