Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/solids/specific/src/G4PolyconeSide.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/solids/specific/src/G4PolyconeSide.cc (Version 11.3.0) and /geometry/solids/specific/src/G4PolyconeSide.cc (Version 9.2.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // Implementation of G4PolyconeSide, the face  << 
 27 // one conical side of a polycone              << 
 28 //                                                 26 //
 29 // Author: David C. Williams (davidw@scipp.ucs <<  27 // $Id: G4PolyconeSide.cc,v 1.19.2.2 2010/01/26 11:33:53 gcosmo Exp $
                                                   >>  28 // GEANT4 tag $Name: geant4-09-02-patch-03 $
                                                   >>  29 //
                                                   >>  30 // 
                                                   >>  31 // --------------------------------------------------------------------
                                                   >>  32 // GEANT 4 class source file
                                                   >>  33 //
                                                   >>  34 //
                                                   >>  35 // G4PolyconeSide.cc
                                                   >>  36 //
                                                   >>  37 // Implementation of the face representing one conical side of a polycone
                                                   >>  38 //
 30 // -------------------------------------------     39 // --------------------------------------------------------------------
 31                                                    40 
 32 #include "G4PolyconeSide.hh"                       41 #include "G4PolyconeSide.hh"
 33 #include "meshdefs.hh"                         << 
 34 #include "G4PhysicalConstants.hh"              << 
 35 #include "G4IntersectingCone.hh"                   42 #include "G4IntersectingCone.hh"
 36 #include "G4ClippablePolygon.hh"                   43 #include "G4ClippablePolygon.hh"
 37 #include "G4AffineTransform.hh"                    44 #include "G4AffineTransform.hh"
                                                   >>  45 #include "meshdefs.hh"
 38 #include "G4SolidExtentList.hh"                    46 #include "G4SolidExtentList.hh"
 39 #include "G4GeometryTolerance.hh"                  47 #include "G4GeometryTolerance.hh"
 40                                                    48 
 41 #include "Randomize.hh"                            49 #include "Randomize.hh"
 42                                                    50 
 43 // This new field helps to use the class G4PlS << 
 44 //                                                 51 //
 45 G4PlSideManager G4PolyconeSide::subInstanceMan << 
 46                                                << 
 47 // This macro changes the references to fields << 
 48 // in the class G4PlSideData.                  << 
 49 //                                             << 
 50 #define G4MT_pcphix ((subInstanceManager.offse << 
 51 #define G4MT_pcphiy ((subInstanceManager.offse << 
 52 #define G4MT_pcphiz ((subInstanceManager.offse << 
 53 #define G4MT_pcphik ((subInstanceManager.offse << 
 54                                                << 
 55 // Returns the private data instance manager.  << 
 56 //                                             << 
 57 const G4PlSideManager& G4PolyconeSide::GetSubI << 
 58 {                                              << 
 59   return subInstanceManager;                   << 
 60 }                                              << 
 61                                                << 
 62 // Constructor                                     52 // Constructor
 63 //                                                 53 //
 64 // Values for r1,z1 and r2,z2 should be specif     54 // Values for r1,z1 and r2,z2 should be specified in clockwise
 65 // order in (r,z).                                 55 // order in (r,z).
 66 //                                                 56 //
 67 G4PolyconeSide::G4PolyconeSide( const G4Polyco <<  57 G4PolyconeSide::G4PolyconeSide( const G4PolyconeSideRZ *prevRZ,
 68                                 const G4Polyco <<  58                                 const G4PolyconeSideRZ *tail,
 69                                 const G4Polyco <<  59                                 const G4PolyconeSideRZ *head,
 70                                 const G4Polyco <<  60                                 const G4PolyconeSideRZ *nextRZ,
 71                                       G4double     61                                       G4double thePhiStart, 
 72                                       G4double     62                                       G4double theDeltaPhi, 
 73                                       G4bool t     63                                       G4bool thePhiIsOpen, 
 74                                       G4bool i     64                                       G4bool isAllBehind )
                                                   >>  65   : ncorners(0), corners(0)
 75 {                                                  66 {
 76   instanceID = subInstanceManager.CreateSubIns << 
 77                                                << 
 78   kCarTolerance = G4GeometryTolerance::GetInst     67   kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
 79   G4MT_pcphix = 0.0; G4MT_pcphiy = 0.0; G4MT_p <<  68   fSurfaceArea = 0.0;
 80                                                    69 
 81   //                                               70   //
 82   // Record values                                 71   // Record values
 83   //                                               72   //
 84   r[0] = tail->r; z[0] = tail->z;                  73   r[0] = tail->r; z[0] = tail->z;
 85   r[1] = head->r; z[1] = head->z;                  74   r[1] = head->r; z[1] = head->z;
 86                                                    75   
 87   phiIsOpen = thePhiIsOpen;                        76   phiIsOpen = thePhiIsOpen;
 88   if (phiIsOpen)                                   77   if (phiIsOpen)
 89   {                                                78   {
 90     deltaPhi = theDeltaPhi;                        79     deltaPhi = theDeltaPhi;
 91     startPhi = thePhiStart;                        80     startPhi = thePhiStart;
 92                                                    81 
 93     //                                             82     //
 94     // Set phi values to our conventions           83     // Set phi values to our conventions
 95     //                                             84     //
 96     while (deltaPhi < 0.0)    // Loop checking <<  85     while (deltaPhi < 0.0) deltaPhi += twopi;
 97      deltaPhi += twopi;                        <<  86     while (startPhi < 0.0) startPhi += twopi;
 98     while (startPhi < 0.0)    // Loop checking << 
 99      startPhi += twopi;                        << 
100                                                    87     
101     //                                             88     //
102     // Calculate corner coordinates                89     // Calculate corner coordinates
103     //                                             90     //
104     ncorners = 4;                                  91     ncorners = 4;
105     corners = new G4ThreeVector[ncorners];         92     corners = new G4ThreeVector[ncorners];
106                                                    93     
107     corners[0] = G4ThreeVector( tail->r*std::c     94     corners[0] = G4ThreeVector( tail->r*std::cos(startPhi),
108                                 tail->r*std::s     95                                 tail->r*std::sin(startPhi), tail->z );
109     corners[1] = G4ThreeVector( head->r*std::c     96     corners[1] = G4ThreeVector( head->r*std::cos(startPhi),
110                                 head->r*std::s     97                                 head->r*std::sin(startPhi), head->z );
111     corners[2] = G4ThreeVector( tail->r*std::c     98     corners[2] = G4ThreeVector( tail->r*std::cos(startPhi+deltaPhi),
112                                 tail->r*std::s     99                                 tail->r*std::sin(startPhi+deltaPhi), tail->z );
113     corners[3] = G4ThreeVector( head->r*std::c    100     corners[3] = G4ThreeVector( head->r*std::cos(startPhi+deltaPhi),
114                                 head->r*std::s    101                                 head->r*std::sin(startPhi+deltaPhi), head->z );
115   }                                               102   }
116   else                                            103   else
117   {                                               104   {
118     deltaPhi = twopi;                             105     deltaPhi = twopi;
119     startPhi = 0.0;                               106     startPhi = 0.0;
120   }                                               107   }
121                                                   108   
122   allBehind = isAllBehind;                        109   allBehind = isAllBehind;
123                                                   110     
124   //                                              111   //
125   // Make our intersecting cone                   112   // Make our intersecting cone
126   //                                              113   //
127   cone = new G4IntersectingCone( r, z );          114   cone = new G4IntersectingCone( r, z );
128                                                   115   
129   //                                              116   //
130   // Calculate vectors in r,z space               117   // Calculate vectors in r,z space
131   //                                              118   //
132   rS = r[1]-r[0]; zS = z[1]-z[0];                 119   rS = r[1]-r[0]; zS = z[1]-z[0];
133   length = std::sqrt( rS*rS + zS*zS);             120   length = std::sqrt( rS*rS + zS*zS);
134   rS /= length; zS /= length;                     121   rS /= length; zS /= length;
135                                                   122   
136   rNorm = +zS;                                    123   rNorm = +zS;
137   zNorm = -rS;                                    124   zNorm = -rS;
138                                                   125   
139   G4double lAdj;                                  126   G4double lAdj;
140                                                   127   
141   prevRS = r[0]-prevRZ->r;                        128   prevRS = r[0]-prevRZ->r;
142   prevZS = z[0]-prevRZ->z;                        129   prevZS = z[0]-prevRZ->z;
143   lAdj = std::sqrt( prevRS*prevRS + prevZS*pre    130   lAdj = std::sqrt( prevRS*prevRS + prevZS*prevZS );
144   prevRS /= lAdj;                                 131   prevRS /= lAdj;
145   prevZS /= lAdj;                                 132   prevZS /= lAdj;
146                                                   133 
147   rNormEdge[0] = rNorm + prevZS;                  134   rNormEdge[0] = rNorm + prevZS;
148   zNormEdge[0] = zNorm - prevRS;                  135   zNormEdge[0] = zNorm - prevRS;
149   lAdj = std::sqrt( rNormEdge[0]*rNormEdge[0]     136   lAdj = std::sqrt( rNormEdge[0]*rNormEdge[0] + zNormEdge[0]*zNormEdge[0] );
150   rNormEdge[0] /= lAdj;                           137   rNormEdge[0] /= lAdj;
151   zNormEdge[0] /= lAdj;                           138   zNormEdge[0] /= lAdj;
152                                                   139 
153   nextRS = nextRZ->r-r[1];                        140   nextRS = nextRZ->r-r[1];
154   nextZS = nextRZ->z-z[1];                        141   nextZS = nextRZ->z-z[1];
155   lAdj = std::sqrt( nextRS*nextRS + nextZS*nex    142   lAdj = std::sqrt( nextRS*nextRS + nextZS*nextZS );
156   nextRS /= lAdj;                                 143   nextRS /= lAdj;
157   nextZS /= lAdj;                                 144   nextZS /= lAdj;
158                                                   145 
159   rNormEdge[1] = rNorm + nextZS;                  146   rNormEdge[1] = rNorm + nextZS;
160   zNormEdge[1] = zNorm - nextRS;                  147   zNormEdge[1] = zNorm - nextRS;
161   lAdj = std::sqrt( rNormEdge[1]*rNormEdge[1]     148   lAdj = std::sqrt( rNormEdge[1]*rNormEdge[1] + zNormEdge[1]*zNormEdge[1] );
162   rNormEdge[1] /= lAdj;                           149   rNormEdge[1] /= lAdj;
163   zNormEdge[1] /= lAdj;                           150   zNormEdge[1] /= lAdj;
164 }                                                 151 }
165                                                   152 
                                                   >> 153 
                                                   >> 154 //
166 // Fake default constructor - sets only member    155 // Fake default constructor - sets only member data and allocates memory
167 //                            for usage restri    156 //                            for usage restricted to object persistency.
168 //                                                157 //
169 G4PolyconeSide::G4PolyconeSide( __void__& )       158 G4PolyconeSide::G4PolyconeSide( __void__& )
170   : startPhi(0.), deltaPhi(0.),                << 159   : phiIsOpen(false), cone(0), ncorners(0), corners(0)
171     rNorm(0.), zNorm(0.), rS(0.), zS(0.), leng << 
172     prevRS(0.), prevZS(0.), nextRS(0.), nextZS << 
173     kCarTolerance(0.), instanceID(0)           << 
174 {                                                 160 {
175   r[0] = r[1] = 0.;                            << 
176   z[0] = z[1] = 0.;                            << 
177   rNormEdge[0]= rNormEdge[1] = 0.;             << 
178   zNormEdge[0]= zNormEdge[1] = 0.;             << 
179 }                                                 161 }
180                                                   162 
                                                   >> 163 
                                                   >> 164 //
181 // Destructor                                     165 // Destructor
182 //                                                166 //  
183 G4PolyconeSide::~G4PolyconeSide()                 167 G4PolyconeSide::~G4PolyconeSide()
184 {                                                 168 {
185   delete cone;                                    169   delete cone;
186   if (phiIsOpen)  { delete [] corners; }       << 170   if (phiIsOpen) delete [] corners;
187 }                                                 171 }
188                                                   172 
                                                   >> 173 
                                                   >> 174 //
189 // Copy constructor                               175 // Copy constructor
190 //                                                176 //
191 G4PolyconeSide::G4PolyconeSide( const G4Polyco << 177 G4PolyconeSide::G4PolyconeSide( const G4PolyconeSide &source )
                                                   >> 178   : G4VCSGface()
192 {                                                 179 {
193   instanceID = subInstanceManager.CreateSubIns << 
194                                                << 
195   CopyStuff( source );                            180   CopyStuff( source );
196 }                                                 181 }
197                                                   182 
                                                   >> 183 
                                                   >> 184 //
198 // Assignment operator                            185 // Assignment operator
199 //                                                186 //
200 G4PolyconeSide& G4PolyconeSide::operator=( con << 187 G4PolyconeSide& G4PolyconeSide::operator=( const G4PolyconeSide &source )
201 {                                                 188 {
202   if (this == &source)  { return *this; }      << 189   if (this == &source) return *this;
203                                                   190 
204   delete cone;                                    191   delete cone;
205   if (phiIsOpen)  { delete [] corners; }       << 192   if (phiIsOpen) delete [] corners;
206                                                   193   
207   CopyStuff( source );                            194   CopyStuff( source );
208                                                   195   
209   return *this;                                   196   return *this;
210 }                                                 197 }
211                                                   198 
                                                   >> 199 
                                                   >> 200 //
212 // CopyStuff                                      201 // CopyStuff
213 //                                                202 //
214 void G4PolyconeSide::CopyStuff( const G4Polyco << 203 void G4PolyconeSide::CopyStuff( const G4PolyconeSide &source )
215 {                                                 204 {
216   r[0]    = source.r[0];                          205   r[0]    = source.r[0];
217   r[1]    = source.r[1];                          206   r[1]    = source.r[1];
218   z[0]    = source.z[0];                          207   z[0]    = source.z[0];
219   z[1]    = source.z[1];                          208   z[1]    = source.z[1];
220                                                   209   
221   startPhi  = source.startPhi;                    210   startPhi  = source.startPhi;
222   deltaPhi  = source.deltaPhi;                    211   deltaPhi  = source.deltaPhi;
223   phiIsOpen  = source.phiIsOpen;                  212   phiIsOpen  = source.phiIsOpen;
224   allBehind  = source.allBehind;                  213   allBehind  = source.allBehind;
225                                                   214 
226   kCarTolerance = source.kCarTolerance;           215   kCarTolerance = source.kCarTolerance;
227   fSurfaceArea = source.fSurfaceArea;             216   fSurfaceArea = source.fSurfaceArea;
228                                                   217   
229   cone    = new G4IntersectingCone( *source.co    218   cone    = new G4IntersectingCone( *source.cone );
230                                                   219   
231   rNorm    = source.rNorm;                        220   rNorm    = source.rNorm;
232   zNorm    = source.zNorm;                        221   zNorm    = source.zNorm;
233   rS    = source.rS;                              222   rS    = source.rS;
234   zS    = source.zS;                              223   zS    = source.zS;
235   length    = source.length;                      224   length    = source.length;
236   prevRS    = source.prevRS;                      225   prevRS    = source.prevRS;
237   prevZS    = source.prevZS;                      226   prevZS    = source.prevZS;
238   nextRS    = source.nextRS;                      227   nextRS    = source.nextRS;
239   nextZS    = source.nextZS;                      228   nextZS    = source.nextZS;
240                                                   229   
241   rNormEdge[0]   = source.rNormEdge[0];           230   rNormEdge[0]   = source.rNormEdge[0];
242   rNormEdge[1]  = source.rNormEdge[1];            231   rNormEdge[1]  = source.rNormEdge[1];
243   zNormEdge[0]  = source.zNormEdge[0];            232   zNormEdge[0]  = source.zNormEdge[0];
244   zNormEdge[1]  = source.zNormEdge[1];            233   zNormEdge[1]  = source.zNormEdge[1];
245                                                   234   
246   if (phiIsOpen)                                  235   if (phiIsOpen)
247   {                                               236   {
248     ncorners = 4;                                 237     ncorners = 4;
249     corners = new G4ThreeVector[ncorners];        238     corners = new G4ThreeVector[ncorners];
250                                                   239     
251     corners[0] = source.corners[0];               240     corners[0] = source.corners[0];
252     corners[1] = source.corners[1];               241     corners[1] = source.corners[1];
253     corners[2] = source.corners[2];               242     corners[2] = source.corners[2];
254     corners[3] = source.corners[3];               243     corners[3] = source.corners[3];
255   }                                               244   }
256 }                                                 245 }
257                                                   246 
                                                   >> 247 
                                                   >> 248 //
258 // Intersect                                      249 // Intersect
259 //                                                250 //
260 G4bool G4PolyconeSide::Intersect( const G4Thre << 251 G4bool G4PolyconeSide::Intersect( const G4ThreeVector &p,
261                                   const G4Thre << 252                                   const G4ThreeVector &v,  
262                                         G4bool    253                                         G4bool outgoing,
263                                         G4doub    254                                         G4double surfTolerance,
264                                         G4doub << 255                                         G4double &distance,
265                                         G4doub << 256                                         G4double &distFromSurface,
266                                         G4Thre << 257                                         G4ThreeVector &normal,
267                                         G4bool << 258                                         G4bool &isAllBehind )
268 {                                                 259 {
269   G4double s1=0., s2=0.;                       << 260   G4double s1, s2;
270   G4double normSign = outgoing ? +1 : -1;         261   G4double normSign = outgoing ? +1 : -1;
271                                                   262   
272   isAllBehind = allBehind;                        263   isAllBehind = allBehind;
273                                                   264 
274   //                                              265   //
275   // Check for two possible intersections         266   // Check for two possible intersections
276   //                                              267   //
277   G4int nside = cone->LineHitsCone( p, v, &s1,    268   G4int nside = cone->LineHitsCone( p, v, &s1, &s2 );
278   if (nside == 0) return false;                   269   if (nside == 0) return false;
279                                                   270     
280   //                                              271   //
281   // Check the first side first, since it is (    272   // Check the first side first, since it is (supposed to be) closest
282   //                                              273   //
283   G4ThreeVector hit = p + s1*v;                   274   G4ThreeVector hit = p + s1*v;
284                                                   275   
285   if (PointOnCone( hit, normSign, p, v, normal    276   if (PointOnCone( hit, normSign, p, v, normal ))
286   {                                               277   {
287     //                                            278     //
288     // Good intersection! What about the norma    279     // Good intersection! What about the normal? 
289     //                                            280     //
290     if (normSign*v.dot(normal) > 0)               281     if (normSign*v.dot(normal) > 0)
291     {                                             282     {
292       //                                          283       //
293       // We have a valid intersection, but it     284       // We have a valid intersection, but it could very easily
294       // be behind the point. To decide if we     285       // be behind the point. To decide if we tolerate this,
295       // we have to see if the point p is on t    286       // we have to see if the point p is on the surface near
296       // the intersecting point.                  287       // the intersecting point.
297       //                                          288       //
298       // What does it mean exactly for the poi    289       // What does it mean exactly for the point p to be "near"
299       // the intersection? It means that if we    290       // the intersection? It means that if we draw a line from
300       // p to the hit, the line remains entire    291       // p to the hit, the line remains entirely within the
301       // tolerance bounds of the cone. To test    292       // tolerance bounds of the cone. To test this, we can
302       // ask if the normal is correct near p.     293       // ask if the normal is correct near p.
303       //                                          294       //
304       G4double pr = p.perp();                     295       G4double pr = p.perp();
305       if (pr < DBL_MIN) pr = DBL_MIN;             296       if (pr < DBL_MIN) pr = DBL_MIN;
306       G4ThreeVector pNormal( rNorm*p.x()/pr, r    297       G4ThreeVector pNormal( rNorm*p.x()/pr, rNorm*p.y()/pr, zNorm );
307       if (normSign*v.dot(pNormal) > 0)            298       if (normSign*v.dot(pNormal) > 0)
308       {                                           299       {
309         //                                        300         //
310         // p and intersection in same hemisphe    301         // p and intersection in same hemisphere
311         //                                        302         //
312         G4double distOutside2;                    303         G4double distOutside2;
313         distFromSurface = -normSign*DistanceAw    304         distFromSurface = -normSign*DistanceAway( p, false, distOutside2 );
314         if (distOutside2 < surfTolerance*surfT    305         if (distOutside2 < surfTolerance*surfTolerance)
315         {                                         306         {
316           if (distFromSurface > -surfTolerance    307           if (distFromSurface > -surfTolerance)
317           {                                       308           {
318             //                                    309             //
319             // We are just inside or away from    310             // We are just inside or away from the
320             // surface. Accept *any* value of     311             // surface. Accept *any* value of distance.
321             //                                    312             //
322             distance = s1;                        313             distance = s1;
323             return true;                          314             return true;
324           }                                       315           }
325         }                                         316         }
326       }                                           317       }
327       else                                        318       else 
328         distFromSurface = s1;                     319         distFromSurface = s1;
329                                                   320       
330       //                                          321       //
331       // Accept positive distances                322       // Accept positive distances
332       //                                          323       //
333       if (s1 > 0)                                 324       if (s1 > 0)
334       {                                           325       {
335         distance = s1;                            326         distance = s1;
336         return true;                              327         return true;
337       }                                           328       }
338     }                                             329     }
339   }                                               330   }  
340                                                   331   
341   if (nside==1) return false;                     332   if (nside==1) return false;
342                                                   333   
343   //                                              334   //
344   // Well, try the second hit                     335   // Well, try the second hit
345   //                                              336   //  
346   hit = p + s2*v;                                 337   hit = p + s2*v;
347                                                   338   
348   if (PointOnCone( hit, normSign, p, v, normal    339   if (PointOnCone( hit, normSign, p, v, normal ))
349   {                                               340   {
350     //                                            341     //
351     // Good intersection! What about the norma    342     // Good intersection! What about the normal? 
352     //                                            343     //
353     if (normSign*v.dot(normal) > 0)               344     if (normSign*v.dot(normal) > 0)
354     {                                             345     {
355       G4double pr = p.perp();                     346       G4double pr = p.perp();
356       if (pr < DBL_MIN) pr = DBL_MIN;             347       if (pr < DBL_MIN) pr = DBL_MIN;
357       G4ThreeVector pNormal( rNorm*p.x()/pr, r    348       G4ThreeVector pNormal( rNorm*p.x()/pr, rNorm*p.y()/pr, zNorm );
358       if (normSign*v.dot(pNormal) > 0)            349       if (normSign*v.dot(pNormal) > 0)
359       {                                           350       {
360         G4double distOutside2;                    351         G4double distOutside2;
361         distFromSurface = -normSign*DistanceAw    352         distFromSurface = -normSign*DistanceAway( p, false, distOutside2 );
362         if (distOutside2 < surfTolerance*surfT    353         if (distOutside2 < surfTolerance*surfTolerance)
363         {                                         354         {
364           if (distFromSurface > -surfTolerance    355           if (distFromSurface > -surfTolerance)
365           {                                       356           {
366             distance = s2;                        357             distance = s2;
367             return true;                          358             return true;
368           }                                       359           }
369         }                                         360         }
370       }                                           361       }
371       else                                        362       else 
372         distFromSurface = s2;                     363         distFromSurface = s2;
373                                                   364       
374       if (s2 > 0)                                 365       if (s2 > 0)
375       {                                           366       {
376         distance = s2;                            367         distance = s2;
377         return true;                              368         return true;
378       }                                           369       }
379     }                                             370     }
380   }                                               371   }  
381                                                   372 
382   //                                              373   //
383   // Better luck next time                        374   // Better luck next time
384   //                                              375   //
385   return false;                                   376   return false;
386 }                                                 377 }
387                                                   378 
388 // Distance                                    << 379 
389 //                                             << 380 G4double G4PolyconeSide::Distance( const G4ThreeVector &p, G4bool outgoing )
390 G4double G4PolyconeSide::Distance( const G4Thr << 
391 {                                                 381 {
392   G4double normSign = outgoing ? -1 : +1;         382   G4double normSign = outgoing ? -1 : +1;
393   G4double distFrom, distOut2;                    383   G4double distFrom, distOut2;
394                                                   384   
395   //                                              385   //
396   // We have two tries for each hemisphere. Tr    386   // We have two tries for each hemisphere. Try the closest first.
397   //                                              387   //
398   distFrom = normSign*DistanceAway( p, false,     388   distFrom = normSign*DistanceAway( p, false, distOut2 );
399   if (distFrom > -0.5*kCarTolerance )             389   if (distFrom > -0.5*kCarTolerance )
400   {                                               390   {
401     //                                            391     //
402     // Good answer                                392     // Good answer
403     //                                            393     //
404     if (distOut2 > 0)                             394     if (distOut2 > 0) 
405       return std::sqrt( distFrom*distFrom + di    395       return std::sqrt( distFrom*distFrom + distOut2 );
406     else                                          396     else 
407       return std::fabs(distFrom);                 397       return std::fabs(distFrom);
408   }                                               398   }
409                                                   399   
410   //                                              400   //
411   // Try second side.                             401   // Try second side. 
412   //                                              402   //
413   distFrom = normSign*DistanceAway( p,  true,     403   distFrom = normSign*DistanceAway( p,  true, distOut2 );
414   if (distFrom > -0.5*kCarTolerance)              404   if (distFrom > -0.5*kCarTolerance)
415   {                                               405   {
416                                                   406 
417     if (distOut2 > 0)                             407     if (distOut2 > 0) 
418       return std::sqrt( distFrom*distFrom + di    408       return std::sqrt( distFrom*distFrom + distOut2 );
419     else                                          409     else
420       return std::fabs(distFrom);                 410       return std::fabs(distFrom);
421   }                                               411   }
422                                                   412   
423   return kInfinity;                               413   return kInfinity;
424 }                                                 414 }
425                                                   415 
                                                   >> 416 
                                                   >> 417 //
426 // Inside                                         418 // Inside
427 //                                                419 //
428 EInside G4PolyconeSide::Inside( const G4ThreeV << 420 EInside G4PolyconeSide::Inside( const G4ThreeVector &p,
429                                       G4double    421                                       G4double tolerance, 
430                                       G4double << 422                                       G4double *bestDistance )
431 {                                                 423 {
432   G4double distFrom, distOut2, dist2;          << 424   //
433   G4double edgeRZnorm;                         << 425   // Check both sides
                                                   >> 426   //
                                                   >> 427   G4double distFrom[2], distOut2[2], dist2[2];
                                                   >> 428   G4double edgeRZnorm[2];
434                                                   429      
435   distFrom =  DistanceAway( p, distOut2, &edge << 430   distFrom[0] =  DistanceAway( p, false, distOut2[0], edgeRZnorm   );
436   dist2 = distFrom*distFrom + distOut2;        << 431   distFrom[1] =  DistanceAway( p,  true, distOut2[1], edgeRZnorm+1 );
437                                                << 432   
438   *bestDistance = std::sqrt( dist2);           << 433   dist2[0] = distFrom[0]*distFrom[0] + distOut2[0];
                                                   >> 434   dist2[1] = distFrom[1]*distFrom[1] + distOut2[1];
                                                   >> 435   
                                                   >> 436   //
                                                   >> 437   // Who's closest?
                                                   >> 438   //
                                                   >> 439   G4int i = std::fabs(dist2[0]) < std::fabs(dist2[1]) ? 0 : 1;
439                                                   440   
                                                   >> 441   *bestDistance = std::sqrt( dist2[i] );
                                                   >> 442   
                                                   >> 443   //
440   // Okay then, inside or out?                    444   // Okay then, inside or out?
441   //                                              445   //
442   if ( (std::fabs(edgeRZnorm) < tolerance)     << 446   if ( (std::fabs(edgeRZnorm[i]) < tolerance)
443     && (distOut2< tolerance*tolerance) )       << 447     && (distOut2[i] < tolerance*tolerance) )
444     return kSurface;                              448     return kSurface;
445   else if (edgeRZnorm < 0)                     << 449   else if (edgeRZnorm[i] < 0)
446     return kInside;                               450     return kInside;
447   else                                            451   else
448     return kOutside;                              452     return kOutside;
449 }                                                 453 }
450                                                   454 
                                                   >> 455 
                                                   >> 456 //
451 // Normal                                         457 // Normal
452 //                                                458 //
453 G4ThreeVector G4PolyconeSide::Normal( const G4 << 459 G4ThreeVector G4PolyconeSide::Normal( const G4ThreeVector &p,
454                                             G4 << 460                                             G4double *bestDistance )
455 {                                                 461 {
456   if (p == G4ThreeVector(0.,0.,0.))  { return     462   if (p == G4ThreeVector(0.,0.,0.))  { return p; }
457                                                   463 
458   G4double dFrom, dOut2;                          464   G4double dFrom, dOut2;
459                                                   465   
460   dFrom = DistanceAway( p, false, dOut2 );        466   dFrom = DistanceAway( p, false, dOut2 );
461                                                   467   
462   *bestDistance = std::sqrt( dFrom*dFrom + dOu    468   *bestDistance = std::sqrt( dFrom*dFrom + dOut2 );
463                                                   469   
464   G4double rds = p.perp();                     << 470   G4double rad = p.perp();
465   if (rds!=0.) { return {rNorm*p.x()/rds,rNorm << 471   if (rad!=0.) { return G4ThreeVector(rNorm*p.x()/rad,rNorm*p.y()/rad,zNorm); }
466   return G4ThreeVector( 0.,0., zNorm ).unit();    472   return G4ThreeVector( 0.,0., zNorm ).unit();
467 }                                                 473 }
468                                                   474 
                                                   >> 475 
                                                   >> 476 //
469 // Extent                                         477 // Extent
470 //                                                478 //
471 G4double G4PolyconeSide::Extent( const G4Three    479 G4double G4PolyconeSide::Extent( const G4ThreeVector axis )
472 {                                                 480 {
473   if (axis.perp2() < DBL_MIN)                     481   if (axis.perp2() < DBL_MIN)
474   {                                               482   {
475     //                                            483     //
476     // Special case                               484     // Special case
477     //                                            485     //
478     return axis.z() < 0 ? -cone->ZLo() : cone-    486     return axis.z() < 0 ? -cone->ZLo() : cone->ZHi();
479   }                                               487   }
480                                                   488 
481   //                                              489   //
482   // Is the axis pointing inside our phi gap?     490   // Is the axis pointing inside our phi gap?
483   //                                              491   //
484   if (phiIsOpen)                                  492   if (phiIsOpen)
485   {                                               493   {
486     G4double phi = GetPhi(axis);               << 494     G4double phi = axis.phi();
487     while( phi < startPhi )    // Loop checkin << 495     while( phi < startPhi ) phi += twopi;
488       phi += twopi;                            << 
489                                                   496     
490     if (phi > deltaPhi+startPhi)                  497     if (phi > deltaPhi+startPhi)
491     {                                             498     {
492       //                                          499       //
493       // Yeah, looks so. Make four three vecto    500       // Yeah, looks so. Make four three vectors defining the phi
494       // opening                                  501       // opening
495       //                                          502       //
496       G4double cosP = std::cos(startPhi), sinP    503       G4double cosP = std::cos(startPhi), sinP = std::sin(startPhi);
497       G4ThreeVector a( r[0]*cosP, r[0]*sinP, z    504       G4ThreeVector a( r[0]*cosP, r[0]*sinP, z[0] );
498       G4ThreeVector b( r[1]*cosP, r[1]*sinP, z    505       G4ThreeVector b( r[1]*cosP, r[1]*sinP, z[1] );
499       cosP = std::cos(startPhi+deltaPhi); sinP    506       cosP = std::cos(startPhi+deltaPhi); sinP = std::sin(startPhi+deltaPhi);
500       G4ThreeVector c( r[0]*cosP, r[0]*sinP, z    507       G4ThreeVector c( r[0]*cosP, r[0]*sinP, z[0] );
501       G4ThreeVector d( r[1]*cosP, r[1]*sinP, z    508       G4ThreeVector d( r[1]*cosP, r[1]*sinP, z[1] );
502                                                   509       
503       G4double ad = axis.dot(a),                  510       G4double ad = axis.dot(a),
504                bd = axis.dot(b),               << 511          bd = axis.dot(b),
505                cd = axis.dot(c),               << 512          cd = axis.dot(c),
506                dd = axis.dot(d);               << 513          dd = axis.dot(d);
507                                                   514       
508       if (bd > ad) ad = bd;                       515       if (bd > ad) ad = bd;
509       if (cd > ad) ad = cd;                       516       if (cd > ad) ad = cd;
510       if (dd > ad) ad = dd;                       517       if (dd > ad) ad = dd;
511                                                   518       
512       return ad;                                  519       return ad;
513     }                                             520     }
514   }                                               521   }
515                                                   522 
516   //                                              523   //
517   // Check either end                             524   // Check either end
518   //                                              525   //
519   G4double aPerp = axis.perp();                   526   G4double aPerp = axis.perp();
520                                                   527   
521   G4double a = aPerp*r[0] + axis.z()*z[0];        528   G4double a = aPerp*r[0] + axis.z()*z[0];
522   G4double b = aPerp*r[1] + axis.z()*z[1];        529   G4double b = aPerp*r[1] + axis.z()*z[1];
523                                                   530   
524   if (b > a) a = b;                               531   if (b > a) a = b;
525                                                   532   
526   return a;                                       533   return a;
527 }                                                 534 }
528                                                   535 
                                                   >> 536 
                                                   >> 537 
                                                   >> 538 //
529 // CalculateExtent                                539 // CalculateExtent
530 //                                                540 //
531 // See notes in G4VCSGface                        541 // See notes in G4VCSGface
532 //                                                542 //
533 void G4PolyconeSide::CalculateExtent( const EA    543 void G4PolyconeSide::CalculateExtent( const EAxis axis, 
534                                       const G4 << 544                                       const G4VoxelLimits &voxelLimit,
535                                       const G4 << 545                                       const G4AffineTransform &transform,
536                                             G4 << 546                                             G4SolidExtentList &extentList )
537 {                                                 547 {
538   G4ClippablePolygon polygon;                     548   G4ClippablePolygon polygon;
539                                                   549   
540   //                                              550   //
541   // Here we will approximate (ala G4Cons) and    551   // Here we will approximate (ala G4Cons) and divide our conical section
542   // into segments, like G4Polyhedra. When doi    552   // into segments, like G4Polyhedra. When doing so, the radius
543   // is extented far enough such that the segm    553   // is extented far enough such that the segments always lie
544   // just outside the surface of the conical s    554   // just outside the surface of the conical section we are
545   // approximating.                               555   // approximating.
546   //                                              556   //
547                                                   557   
548   //                                              558   //
549   // Choose phi size of our segment(s) based o    559   // Choose phi size of our segment(s) based on constants as
550   // defined in meshdefs.hh                       560   // defined in meshdefs.hh
551   //                                              561   //
552   G4int numPhi = (G4int)(deltaPhi/kMeshAngleDe    562   G4int numPhi = (G4int)(deltaPhi/kMeshAngleDefault) + 1;
553   if (numPhi < kMinMeshSections)                  563   if (numPhi < kMinMeshSections) 
554     numPhi = kMinMeshSections;                    564     numPhi = kMinMeshSections;
555   else if (numPhi > kMaxMeshSections)             565   else if (numPhi > kMaxMeshSections)
556     numPhi = kMaxMeshSections;                    566     numPhi = kMaxMeshSections;
557                                                   567     
558   G4double sigPhi = deltaPhi/numPhi;              568   G4double sigPhi = deltaPhi/numPhi;
559                                                   569   
560   //                                              570   //
561   // Determine radius factor to keep segments     571   // Determine radius factor to keep segments outside
562   //                                              572   //
563   G4double rFudge = 1.0/std::cos(0.5*sigPhi);     573   G4double rFudge = 1.0/std::cos(0.5*sigPhi);
564                                                   574   
565   //                                              575   //
566   // Decide which radius to use on each end of    576   // Decide which radius to use on each end of the side,
567   // and whether a transition mesh is required    577   // and whether a transition mesh is required
568   //                                              578   //
569   // {r0,z0}  - Beginning of this side            579   // {r0,z0}  - Beginning of this side
570   // {r1,z1}  - Ending of this side               580   // {r1,z1}  - Ending of this side
571   // {r2,z0}  - Beginning of transition piece     581   // {r2,z0}  - Beginning of transition piece connecting previous
572   //            side (and ends at beginning of    582   //            side (and ends at beginning of this side)
573   //                                              583   //
574   // So, order is 2 --> 0 --> 1.                  584   // So, order is 2 --> 0 --> 1.
575   //                    -------                   585   //                    -------
576   //                                              586   //
577   // r2 < 0 indicates that no transition piece    587   // r2 < 0 indicates that no transition piece is required
578   //                                              588   //
579   G4double r0, r1, r2, z0, z1;                    589   G4double r0, r1, r2, z0, z1;
580                                                   590   
581   r2 = -1;  // By default: no transition piece    591   r2 = -1;  // By default: no transition piece
582                                                   592   
583   if (rNorm < -DBL_MIN)                           593   if (rNorm < -DBL_MIN)
584   {                                               594   {
585     //                                            595     //
586     // This side faces *inward*, and so our me    596     // This side faces *inward*, and so our mesh has
587     // the same radius                            597     // the same radius
588     //                                            598     //
589     r1 = r[1];                                    599     r1 = r[1];
590     z1 = z[1];                                    600     z1 = z[1];
591     z0 = z[0];                                    601     z0 = z[0];
592     r0 = r[0];                                    602     r0 = r[0];
593                                                   603     
594     r2 = -1;                                      604     r2 = -1;
595                                                   605     
596     if (prevZS > DBL_MIN)                         606     if (prevZS > DBL_MIN)
597     {                                             607     {
598       //                                          608       //
599       // The previous side is facing outwards     609       // The previous side is facing outwards
600       //                                          610       //
601       if ( prevRS*zS - prevZS*rS > 0 )            611       if ( prevRS*zS - prevZS*rS > 0 )
602       {                                           612       {
603         //                                        613         //
604         // Transition was convex: build transi    614         // Transition was convex: build transition piece
605         //                                        615         //
606         if (r[0] > DBL_MIN) r2 = r[0]*rFudge;     616         if (r[0] > DBL_MIN) r2 = r[0]*rFudge;
607       }                                           617       }
608       else                                        618       else
609       {                                           619       {
610         //                                        620         //
611         // Transition was concave: short this     621         // Transition was concave: short this side
612         //                                        622         //
613         FindLineIntersect( z0, r0, zS, rS,        623         FindLineIntersect( z0, r0, zS, rS,
614                            z0, r0*rFudge, prev    624                            z0, r0*rFudge, prevZS, prevRS*rFudge, z0, r0 );
615       }                                           625       }
616     }                                             626     }
617                                                   627     
618     if ( nextZS > DBL_MIN && (rS*nextZS - zS*n    628     if ( nextZS > DBL_MIN && (rS*nextZS - zS*nextRS < 0) )
619     {                                             629     {
620       //                                          630       //
621       // The next side is facing outwards, for    631       // The next side is facing outwards, forming a 
622       // concave transition: short this side      632       // concave transition: short this side
623       //                                          633       //
624       FindLineIntersect( z1, r1, zS, rS,          634       FindLineIntersect( z1, r1, zS, rS,
625                          z1, r1*rFudge, nextZS    635                          z1, r1*rFudge, nextZS, nextRS*rFudge, z1, r1 );
626     }                                             636     }
627   }                                               637   }
628   else if (rNorm > DBL_MIN)                       638   else if (rNorm > DBL_MIN)
629   {                                               639   {
630     //                                            640     //
631     // This side faces *outward* and is given     641     // This side faces *outward* and is given a boost to
632     // it radius                                  642     // it radius
633     //                                            643     //
634     r0 = r[0]*rFudge;                             644     r0 = r[0]*rFudge;
635     z0 = z[0];                                    645     z0 = z[0];
636     r1 = r[1]*rFudge;                             646     r1 = r[1]*rFudge;
637     z1 = z[1];                                    647     z1 = z[1];
638                                                   648     
639     if (prevZS < -DBL_MIN)                        649     if (prevZS < -DBL_MIN)
640     {                                             650     {
641       //                                          651       //
642       // The previous side is facing inwards      652       // The previous side is facing inwards
643       //                                          653       //
644       if ( prevRS*zS - prevZS*rS > 0 )            654       if ( prevRS*zS - prevZS*rS > 0 )
645       {                                           655       {
646         //                                        656         //
647         // Transition was convex: build transi    657         // Transition was convex: build transition piece
648         //                                        658         //
649         if (r[0] > DBL_MIN) r2 = r[0];            659         if (r[0] > DBL_MIN) r2 = r[0];
650       }                                           660       }
651       else                                        661       else
652       {                                           662       {
653         //                                        663         //
654         // Transition was concave: short this     664         // Transition was concave: short this side
655         //                                        665         //
656         FindLineIntersect( z0, r0, zS, rS*rFud    666         FindLineIntersect( z0, r0, zS, rS*rFudge,
657                            z0, r[0], prevZS, p    667                            z0, r[0], prevZS, prevRS, z0, r0 );
658       }                                           668       }
659     }                                             669     }
660                                                   670     
661     if ( nextZS < -DBL_MIN && (rS*nextZS - zS*    671     if ( nextZS < -DBL_MIN && (rS*nextZS - zS*nextRS < 0) )
662     {                                             672     {
663       //                                          673       //
664       // The next side is facing inwards, form    674       // The next side is facing inwards, forming a 
665       // concave transition: short this side      675       // concave transition: short this side
666       //                                          676       //
667       FindLineIntersect( z1, r1, zS, rS*rFudge    677       FindLineIntersect( z1, r1, zS, rS*rFudge,
668                          z1, r[1], nextZS, nex    678                          z1, r[1], nextZS, nextRS, z1, r1 );
669     }                                             679     }
670   }                                               680   }
671   else                                            681   else
672   {                                               682   {
673     //                                            683     //
674     // This side is perpendicular to the z axi    684     // This side is perpendicular to the z axis (is a disk)
675     //                                            685     //
676     // Whether or not r0 needs a rFudge factor    686     // Whether or not r0 needs a rFudge factor depends
677     // on the normal of the previous edge. Sim    687     // on the normal of the previous edge. Similar with r1
678     // and the next edge. No transition piece     688     // and the next edge. No transition piece is required.
679     //                                            689     //
680     r0 = r[0];                                    690     r0 = r[0];
681     r1 = r[1];                                    691     r1 = r[1];
682     z0 = z[0];                                    692     z0 = z[0];
683     z1 = z[1];                                    693     z1 = z[1];
684                                                   694     
685     if (prevZS > DBL_MIN) r0 *= rFudge;           695     if (prevZS > DBL_MIN) r0 *= rFudge;
686     if (nextZS > DBL_MIN) r1 *= rFudge;           696     if (nextZS > DBL_MIN) r1 *= rFudge;
687   }                                               697   }
688                                                   698   
689   //                                              699   //
690   // Loop                                         700   // Loop
691   //                                              701   //
692   G4double phi = startPhi,                        702   G4double phi = startPhi, 
693            cosPhi = std::cos(phi),                703            cosPhi = std::cos(phi), 
694            sinPhi = std::sin(phi);                704            sinPhi = std::sin(phi);
695                                                   705   
696   G4ThreeVector v0( r0*cosPhi, r0*sinPhi, z0 )    706   G4ThreeVector v0( r0*cosPhi, r0*sinPhi, z0 ),
697                     v1( r1*cosPhi, r1*sinPhi,     707                     v1( r1*cosPhi, r1*sinPhi, z1 ),
698   v2, w0, w1, w2;                                 708   v2, w0, w1, w2;
699   transform.ApplyPointTransform( v0 );            709   transform.ApplyPointTransform( v0 );
700   transform.ApplyPointTransform( v1 );            710   transform.ApplyPointTransform( v1 );
701                                                   711   
702   if (r2 >= 0)                                    712   if (r2 >= 0)
703   {                                               713   {
704     v2 = G4ThreeVector( r2*cosPhi, r2*sinPhi,     714     v2 = G4ThreeVector( r2*cosPhi, r2*sinPhi, z0 );
705     transform.ApplyPointTransform( v2 );          715     transform.ApplyPointTransform( v2 );
706   }                                               716   }
707                                                   717 
708   do    // Loop checking, 13.08.2015, G.Cosmo  << 718   do
709   {                                               719   {
710     phi += sigPhi;                                720     phi += sigPhi;
711     if (numPhi == 1) phi = startPhi+deltaPhi;     721     if (numPhi == 1) phi = startPhi+deltaPhi;  // Try to avoid roundoff
712     cosPhi = std::cos(phi),                       722     cosPhi = std::cos(phi), 
713     sinPhi = std::sin(phi);                       723     sinPhi = std::sin(phi);
714                                                   724     
715     w0 = G4ThreeVector( r0*cosPhi, r0*sinPhi,     725     w0 = G4ThreeVector( r0*cosPhi, r0*sinPhi, z0 );
716     w1 = G4ThreeVector( r1*cosPhi, r1*sinPhi,     726     w1 = G4ThreeVector( r1*cosPhi, r1*sinPhi, z1 );
717     transform.ApplyPointTransform( w0 );          727     transform.ApplyPointTransform( w0 );
718     transform.ApplyPointTransform( w1 );          728     transform.ApplyPointTransform( w1 );
719                                                   729     
720     G4ThreeVector deltaV = r0 > r1 ? w0-v0 : w    730     G4ThreeVector deltaV = r0 > r1 ? w0-v0 : w1-v1;
721                                                   731     
722     //                                            732     //
723     // Build polygon, taking special care to k    733     // Build polygon, taking special care to keep the vertices
724     // in order                                   734     // in order
725     //                                            735     //
726     polygon.ClearAllVertices();                   736     polygon.ClearAllVertices();
727                                                   737 
728     polygon.AddVertexInOrder( v0 );               738     polygon.AddVertexInOrder( v0 );
729     polygon.AddVertexInOrder( v1 );               739     polygon.AddVertexInOrder( v1 );
730     polygon.AddVertexInOrder( w1 );               740     polygon.AddVertexInOrder( w1 );
731     polygon.AddVertexInOrder( w0 );               741     polygon.AddVertexInOrder( w0 );
732                                                   742 
733     //                                            743     //
734     // Get extent                                 744     // Get extent
735     //                                            745     //
736     if (polygon.PartialClip( voxelLimit, axis     746     if (polygon.PartialClip( voxelLimit, axis ))
737     {                                             747     {
738       //                                          748       //
739       // Get dot product of normal with target    749       // Get dot product of normal with target axis
740       //                                          750       //
741       polygon.SetNormal( deltaV.cross(v1-v0).u    751       polygon.SetNormal( deltaV.cross(v1-v0).unit() );
742                                                   752       
743       extentList.AddSurface( polygon );           753       extentList.AddSurface( polygon );
744     }                                             754     }
745                                                   755     
746     if (r2 >= 0)                                  756     if (r2 >= 0)
747     {                                             757     {
748       //                                          758       //
749       // Repeat, for transition piece             759       // Repeat, for transition piece
750       //                                          760       //
751       w2 = G4ThreeVector( r2*cosPhi, r2*sinPhi    761       w2 = G4ThreeVector( r2*cosPhi, r2*sinPhi, z0 );
752       transform.ApplyPointTransform( w2 );        762       transform.ApplyPointTransform( w2 );
753                                                   763 
754       polygon.ClearAllVertices();                 764       polygon.ClearAllVertices();
755                                                   765 
756       polygon.AddVertexInOrder( v2 );             766       polygon.AddVertexInOrder( v2 );
757       polygon.AddVertexInOrder( v0 );             767       polygon.AddVertexInOrder( v0 );
758       polygon.AddVertexInOrder( w0 );             768       polygon.AddVertexInOrder( w0 );
759       polygon.AddVertexInOrder( w2 );             769       polygon.AddVertexInOrder( w2 );
760                                                   770 
761       if (polygon.PartialClip( voxelLimit, axi    771       if (polygon.PartialClip( voxelLimit, axis ))
762       {                                           772       {
763         polygon.SetNormal( deltaV.cross(v0-v2)    773         polygon.SetNormal( deltaV.cross(v0-v2).unit() );
764                                                   774         
765         extentList.AddSurface( polygon );         775         extentList.AddSurface( polygon );
766       }                                           776       }
767                                                   777       
768       v2 = w2;                                    778       v2 = w2;
769     }                                             779     }
770                                                   780     
771     //                                            781     //
772     // Next vertex                                782     // Next vertex
773     //                                            783     //    
774     v0 = w0;                                      784     v0 = w0;
775     v1 = w1;                                      785     v1 = w1;
776   } while( --numPhi > 0 );                        786   } while( --numPhi > 0 );
777                                                   787   
778   //                                              788   //
779   // We are almost done. But, it is important     789   // We are almost done. But, it is important that we leave no
780   // gaps in the surface of our solid. By usin    790   // gaps in the surface of our solid. By using rFudge, however,
781   // we've done exactly that, if we have a phi    791   // we've done exactly that, if we have a phi segment. 
782   // Add two additional faces if necessary        792   // Add two additional faces if necessary
783   //                                              793   //
784   if (phiIsOpen && rNorm > DBL_MIN)               794   if (phiIsOpen && rNorm > DBL_MIN)
785   {                                               795   {    
786     cosPhi = std::cos(startPhi);               << 796     G4double cosPhi = std::cos(startPhi),
787     sinPhi = std::sin(startPhi);               << 797        sinPhi = std::sin(startPhi);
788                                                   798 
789     G4ThreeVector a0( r[0]*cosPhi, r[0]*sinPhi    799     G4ThreeVector a0( r[0]*cosPhi, r[0]*sinPhi, z[0] ),
790                   a1( r[1]*cosPhi, r[1]*sinPhi    800                   a1( r[1]*cosPhi, r[1]*sinPhi, z[1] ),
791                   b0( r0*cosPhi, r0*sinPhi, z[    801                   b0( r0*cosPhi, r0*sinPhi, z[0] ),
792                   b1( r1*cosPhi, r1*sinPhi, z[    802                   b1( r1*cosPhi, r1*sinPhi, z[1] );
793                                                   803   
794     transform.ApplyPointTransform( a0 );          804     transform.ApplyPointTransform( a0 );
795     transform.ApplyPointTransform( a1 );          805     transform.ApplyPointTransform( a1 );
796     transform.ApplyPointTransform( b0 );          806     transform.ApplyPointTransform( b0 );
797     transform.ApplyPointTransform( b1 );          807     transform.ApplyPointTransform( b1 );
798                                                   808 
799     polygon.ClearAllVertices();                   809     polygon.ClearAllVertices();
800                                                   810 
801     polygon.AddVertexInOrder( a0 );               811     polygon.AddVertexInOrder( a0 );
802     polygon.AddVertexInOrder( a1 );               812     polygon.AddVertexInOrder( a1 );
803     polygon.AddVertexInOrder( b0 );               813     polygon.AddVertexInOrder( b0 );
804     polygon.AddVertexInOrder( b1 );               814     polygon.AddVertexInOrder( b1 );
805                                                   815     
806     if (polygon.PartialClip( voxelLimit , axis    816     if (polygon.PartialClip( voxelLimit , axis))
807     {                                             817     {
808       G4ThreeVector normal( sinPhi, -cosPhi, 0    818       G4ThreeVector normal( sinPhi, -cosPhi, 0 );
809       polygon.SetNormal( transform.TransformAx    819       polygon.SetNormal( transform.TransformAxis( normal ) );
810                                                   820         
811       extentList.AddSurface( polygon );           821       extentList.AddSurface( polygon );
812     }                                             822     }
813                                                   823     
814     cosPhi = std::cos(startPhi+deltaPhi);         824     cosPhi = std::cos(startPhi+deltaPhi);
815     sinPhi = std::sin(startPhi+deltaPhi);         825     sinPhi = std::sin(startPhi+deltaPhi);
816                                                   826     
817     a0 = G4ThreeVector( r[0]*cosPhi, r[0]*sinP    827     a0 = G4ThreeVector( r[0]*cosPhi, r[0]*sinPhi, z[0] ),
818     a1 = G4ThreeVector( r[1]*cosPhi, r[1]*sinP    828     a1 = G4ThreeVector( r[1]*cosPhi, r[1]*sinPhi, z[1] ),
819     b0 = G4ThreeVector( r0*cosPhi, r0*sinPhi,     829     b0 = G4ThreeVector( r0*cosPhi, r0*sinPhi, z[0] ),
820     b1 = G4ThreeVector( r1*cosPhi, r1*sinPhi,     830     b1 = G4ThreeVector( r1*cosPhi, r1*sinPhi, z[1] );
821     transform.ApplyPointTransform( a0 );          831     transform.ApplyPointTransform( a0 );
822     transform.ApplyPointTransform( a1 );          832     transform.ApplyPointTransform( a1 );
823     transform.ApplyPointTransform( b0 );          833     transform.ApplyPointTransform( b0 );
824     transform.ApplyPointTransform( b1 );          834     transform.ApplyPointTransform( b1 );
825                                                   835 
826     polygon.ClearAllVertices();                   836     polygon.ClearAllVertices();
827                                                   837 
828     polygon.AddVertexInOrder( a0 );               838     polygon.AddVertexInOrder( a0 );
829     polygon.AddVertexInOrder( a1 );               839     polygon.AddVertexInOrder( a1 );
830     polygon.AddVertexInOrder( b0 );               840     polygon.AddVertexInOrder( b0 );
831     polygon.AddVertexInOrder( b1 );               841     polygon.AddVertexInOrder( b1 );
832                                                   842     
833     if (polygon.PartialClip( voxelLimit, axis     843     if (polygon.PartialClip( voxelLimit, axis ))
834     {                                             844     {
835       G4ThreeVector normal( -sinPhi, cosPhi, 0    845       G4ThreeVector normal( -sinPhi, cosPhi, 0 );
836       polygon.SetNormal( transform.TransformAx    846       polygon.SetNormal( transform.TransformAxis( normal ) );
837                                                   847         
838       extentList.AddSurface( polygon );           848       extentList.AddSurface( polygon );
839     }                                             849     }
840   }                                               850   }
841                                                   851     
842   return;                                         852   return;
843 }                                                 853 }
844                                                   854 
845 // GetPhi                                      << 
846 //                                             << 
847 // Calculate Phi for a given 3-vector (point), << 
848 // same point, in the attempt to avoid consecu << 
849 // quantity                                    << 
850 //                                             << 
851 G4double G4PolyconeSide::GetPhi( const G4Three << 
852 {                                              << 
853   G4double val=0.;                             << 
854   G4ThreeVector vphi(G4MT_pcphix, G4MT_pcphiy, << 
855                                                << 
856   if (vphi != p)                               << 
857   {                                            << 
858     val = p.phi();                             << 
859     G4MT_pcphix = p.x(); G4MT_pcphiy = p.y();  << 
860     G4MT_pcphik = val;                         << 
861   }                                            << 
862   else                                         << 
863   {                                            << 
864     val = G4MT_pcphik;                         << 
865   }                                            << 
866   return val;                                  << 
867 }                                              << 
868                                                   855 
                                                   >> 856 //
869 // DistanceAway                                   857 // DistanceAway
870 //                                                858 //
871 // Calculate distance of a point from our coni    859 // Calculate distance of a point from our conical surface, including the effect
872 // of any phi segmentation                        860 // of any phi segmentation
873 //                                                861 //
874 // Arguments:                                     862 // Arguments:
875 //  p             - (in) Point to check           863 //  p             - (in) Point to check
876 //  opposite      - (in) If true, check opposi    864 //  opposite      - (in) If true, check opposite hemisphere (see below)
877 //  distOutside   - (out) Additional distance     865 //  distOutside   - (out) Additional distance outside the edges of the surface
878 //  edgeRZnorm    - (out) if negative, point i    866 //  edgeRZnorm    - (out) if negative, point is inside
879 //                                                867 //
880 //  return value = distance from the conical p    868 //  return value = distance from the conical plane, if extrapolated beyond edges,
881 //                 signed by whether the point    869 //                 signed by whether the point is in inside or outside the shape
882 //                                                870 //
883 // Notes:                                         871 // Notes:
884 //  * There are two answers, depending on whic    872 //  * There are two answers, depending on which hemisphere is considered.
885 //                                                873 //
886 G4double G4PolyconeSide::DistanceAway( const G << 874 G4double G4PolyconeSide::DistanceAway( const G4ThreeVector &p,
887                                              G    875                                              G4bool opposite,
888                                              G << 876                                              G4double &distOutside2,
889                                              G << 877                                              G4double *edgeRZnorm  )
890 {                                                 878 {
891   //                                              879   //
892   // Convert our point to r and z                 880   // Convert our point to r and z
893   //                                              881   //
894   G4double rx = p.perp(), zx = p.z();             882   G4double rx = p.perp(), zx = p.z();
895                                                   883   
896   //                                              884   //
897   // Change sign of r if opposite says we shou    885   // Change sign of r if opposite says we should
898   //                                              886   //
899   if (opposite) rx = -rx;                         887   if (opposite) rx = -rx;
900                                                   888   
901   //                                              889   //
902   // Calculate return value                       890   // Calculate return value
903   //                                              891   //
904   G4double deltaR  = rx - r[0], deltaZ = zx -     892   G4double deltaR  = rx - r[0], deltaZ = zx - z[0];
905   G4double answer = deltaR*rNorm + deltaZ*zNor    893   G4double answer = deltaR*rNorm + deltaZ*zNorm;
906                                                   894   
907   //                                              895   //
908   // Are we off the surface in r,z space?         896   // Are we off the surface in r,z space?
909   //                                              897   //
910   G4double q = deltaR*rS + deltaZ*zS;          << 898   G4double s = deltaR*rS + deltaZ*zS;
911   if (q < 0)                                   << 899   if (s < 0)
912   {                                               900   {
913     distOutside2 = q*q;                        << 901     distOutside2 = s*s;
914     if (edgeRZnorm != nullptr)                 << 902     if (edgeRZnorm) *edgeRZnorm = deltaR*rNormEdge[0] + deltaZ*zNormEdge[0];
915       *edgeRZnorm = deltaR*rNormEdge[0] + delt << 
916   }                                               903   }
917   else if (q > length)                         << 904   else if (s > length)
918   {                                               905   {
919     distOutside2 = sqr( q-length );            << 906     distOutside2 = sqr( s-length );
920     if (edgeRZnorm != nullptr)                 << 907     if (edgeRZnorm)
921     {                                             908     {
922       deltaR = rx - r[1];                      << 909       G4double deltaR  = rx - r[1], deltaZ = zx - z[1];
923       deltaZ = zx - z[1];                      << 
924       *edgeRZnorm = deltaR*rNormEdge[1] + delt    910       *edgeRZnorm = deltaR*rNormEdge[1] + deltaZ*zNormEdge[1];
925     }                                             911     }
926   }                                               912   }
927   else                                            913   else
928   {                                               914   {
929     distOutside2 = 0.;                         << 915     distOutside2 = 0;
930     if (edgeRZnorm != nullptr) *edgeRZnorm = a << 916     if (edgeRZnorm) *edgeRZnorm = answer;
931   }                                               917   }
932                                                   918 
933   if (phiIsOpen)                                  919   if (phiIsOpen)
934   {                                               920   {
935     //                                            921     //
936     // Finally, check phi                         922     // Finally, check phi
937     //                                            923     //
938     G4double phi = GetPhi(p);                  << 924     G4double phi = p.phi();
939     while( phi < startPhi )    // Loop checkin << 925     while( phi < startPhi ) phi += twopi;
940       phi += twopi;                            << 
941                                                   926     
942     if (phi > startPhi+deltaPhi)                  927     if (phi > startPhi+deltaPhi)
943     {                                             928     {
944       //                                          929       //
945       // Oops. Are we closer to the start phi     930       // Oops. Are we closer to the start phi or end phi?
946       //                                          931       //
947       G4double d1 = phi-startPhi-deltaPhi;        932       G4double d1 = phi-startPhi-deltaPhi;
948       while( phi > startPhi )    // Loop check << 933       while( phi > startPhi ) phi -= twopi;
949         phi -= twopi;                          << 
950       G4double d2 = startPhi-phi;                 934       G4double d2 = startPhi-phi;
951                                                   935       
952       if (d2 < d1) d1 = d2;                       936       if (d2 < d1) d1 = d2;
953                                                   937       
954       //                                          938       //
955       // Add result to our distance               939       // Add result to our distance
956       //                                          940       //
957       G4double dist = d1*rx;                      941       G4double dist = d1*rx;
958                                                   942       
959       distOutside2 += dist*dist;                  943       distOutside2 += dist*dist;
960       if (edgeRZnorm != nullptr)               << 944       if (edgeRZnorm)
961       {                                           945       {
962         *edgeRZnorm = std::max(std::fabs(*edge    946         *edgeRZnorm = std::max(std::fabs(*edgeRZnorm),std::fabs(dist));
963       }                                           947       }
964     }                                             948     }
965   }                                               949   }
966                                                   950 
967   return answer;                                  951   return answer;
968 }                                                 952 }
969                                                   953 
970 // DistanceAway                                << 
971 //                                             << 
972 // Special version of DistanceAway for Inside. << 
973 // Opposite parameter is not used, instead use << 
974 //                                             << 
975 G4double G4PolyconeSide::DistanceAway( const G << 
976                                              G << 
977                                              G << 
978 {                                              << 
979   //                                           << 
980   // Convert our point to r and z              << 
981   //                                           << 
982   G4double rx = p.perp(), zx = p.z();          << 
983                                                << 
984   //                                           << 
985   // Change sign of r if we should             << 
986   //                                           << 
987   G4int part = 1;                              << 
988   if (rx < 0) part = -1;                       << 
989                                                << 
990   //                                           << 
991   // Calculate return value                    << 
992   //                                           << 
993   G4double deltaR = rx - r[0]*part, deltaZ = z << 
994   G4double answer = deltaR*rNorm*part + deltaZ << 
995                                                << 
996   //                                           << 
997   // Are we off the surface in r,z space?      << 
998   //                                           << 
999   G4double q = deltaR*rS*part + deltaZ*zS;     << 
1000   if (q < 0)                                  << 
1001   {                                           << 
1002     distOutside2 = q*q;                       << 
1003     if (edgeRZnorm != nullptr)                << 
1004     {                                         << 
1005       *edgeRZnorm = deltaR*rNormEdge[0]*part  << 
1006     }                                         << 
1007   }                                           << 
1008   else if (q > length)                        << 
1009   {                                           << 
1010     distOutside2 = sqr( q-length );           << 
1011     if (edgeRZnorm != nullptr)                << 
1012     {                                         << 
1013       deltaR = rx - r[1]*part;                << 
1014       deltaZ = zx - z[1];                     << 
1015       *edgeRZnorm = deltaR*rNormEdge[1]*part  << 
1016     }                                         << 
1017   }                                           << 
1018   else                                        << 
1019   {                                           << 
1020     distOutside2 = 0.;                        << 
1021     if (edgeRZnorm != nullptr) *edgeRZnorm =  << 
1022   }                                           << 
1023                                               << 
1024   if (phiIsOpen)                              << 
1025   {                                           << 
1026     //                                        << 
1027     // Finally, check phi                     << 
1028     //                                        << 
1029     G4double phi = GetPhi(p);                 << 
1030     while( phi < startPhi )    // Loop checki << 
1031       phi += twopi;                           << 
1032                                               << 
1033     if (phi > startPhi+deltaPhi)              << 
1034     {                                         << 
1035       //                                      << 
1036       // Oops. Are we closer to the start phi << 
1037       //                                      << 
1038       G4double d1 = phi-startPhi-deltaPhi;    << 
1039       while( phi > startPhi )    // Loop chec << 
1040         phi -= twopi;                         << 
1041       G4double d2 = startPhi-phi;             << 
1042                                               << 
1043       if (d2 < d1) d1 = d2;                   << 
1044                                               << 
1045       //                                      << 
1046       // Add result to our distance           << 
1047       //                                      << 
1048       G4double dist = d1*rx*part;             << 
1049                                               << 
1050       distOutside2 += dist*dist;              << 
1051       if (edgeRZnorm != nullptr)              << 
1052       {                                       << 
1053         *edgeRZnorm = std::max(std::fabs(*edg << 
1054       }                                       << 
1055     }                                         << 
1056   }                                           << 
1057                                               << 
1058   return answer;                              << 
1059 }                                             << 
1060                                                  954 
                                                   >> 955 //
1061 // PointOnCone                                   956 // PointOnCone
1062 //                                               957 //
1063 // Decide if a point is on a cone and return     958 // Decide if a point is on a cone and return normal if it is
1064 //                                               959 //
1065 G4bool G4PolyconeSide::PointOnCone( const G4T << 960 G4bool G4PolyconeSide::PointOnCone( const G4ThreeVector &hit,
1066                                           G4d    961                                           G4double normSign,
1067                                     const G4T << 962                                     const G4ThreeVector &p,
1068                                     const G4T << 963                                     const G4ThreeVector &v,
1069                                           G4T << 964                                           G4ThreeVector &normal )
1070 {                                                965 {
1071   G4double rx = hit.perp();                      966   G4double rx = hit.perp();
1072   //                                             967   //
1073   // Check radial/z extent, as appropriate       968   // Check radial/z extent, as appropriate
1074   //                                             969   //
1075   if (!cone->HitOn( rx, hit.z() )) return fal    970   if (!cone->HitOn( rx, hit.z() )) return false;
1076                                                  971   
1077   if (phiIsOpen)                                 972   if (phiIsOpen)
1078   {                                              973   {
1079     G4double phiTolerant = 2.0*kCarTolerance/    974     G4double phiTolerant = 2.0*kCarTolerance/(rx+kCarTolerance);
1080     //                                           975     //
1081     // Check phi segment. Here we have to be     976     // Check phi segment. Here we have to be careful
1082     // to use the standard method consistent     977     // to use the standard method consistent with
1083     // PolyPhiFace. See PolyPhiFace::InsideEd    978     // PolyPhiFace. See PolyPhiFace::InsideEdgesExact
1084     //                                           979     //
1085     G4double phi = GetPhi(hit);               << 980     G4double phi = hit.phi();
1086     while( phi < startPhi-phiTolerant )   //  << 981     while( phi < startPhi-phiTolerant ) phi += twopi;
1087       phi += twopi;                           << 
1088                                                  982     
1089     if (phi > startPhi+deltaPhi+phiTolerant)     983     if (phi > startPhi+deltaPhi+phiTolerant) return false;
1090                                                  984     
1091     if (phi > startPhi+deltaPhi-phiTolerant)     985     if (phi > startPhi+deltaPhi-phiTolerant)
1092     {                                            986     {
1093       //                                         987       //
1094       // Exact treatment                         988       // Exact treatment
1095       //                                         989       //
1096       G4ThreeVector qx = p + v;                  990       G4ThreeVector qx = p + v;
1097       G4ThreeVector qa = qx - corners[2],        991       G4ThreeVector qa = qx - corners[2],
1098               qb = qx - corners[3];              992               qb = qx - corners[3];
1099       G4ThreeVector qacb = qa.cross(qb);         993       G4ThreeVector qacb = qa.cross(qb);
1100                                                  994       
1101       if (normSign*qacb.dot(v) < 0) return fa    995       if (normSign*qacb.dot(v) < 0) return false;
1102     }                                            996     }
1103     else if (phi < phiTolerant)                  997     else if (phi < phiTolerant)
1104     {                                            998     {
1105       G4ThreeVector qx = p + v;                  999       G4ThreeVector qx = p + v;
1106       G4ThreeVector qa = qx - corners[1],        1000       G4ThreeVector qa = qx - corners[1],
1107               qb = qx - corners[0];              1001               qb = qx - corners[0];
1108       G4ThreeVector qacb = qa.cross(qb);         1002       G4ThreeVector qacb = qa.cross(qb);
1109                                                  1003       
1110       if (normSign*qacb.dot(v) < 0) return fa    1004       if (normSign*qacb.dot(v) < 0) return false;
1111     }                                            1005     }
1112   }                                              1006   }
1113                                                  1007   
1114   //                                             1008   //
1115   // We have a good hit! Calculate normal        1009   // We have a good hit! Calculate normal
1116   //                                             1010   //
1117   if (rx < DBL_MIN)                              1011   if (rx < DBL_MIN) 
1118     normal = G4ThreeVector( 0, 0, zNorm < 0 ?    1012     normal = G4ThreeVector( 0, 0, zNorm < 0 ? -1 : 1 );
1119   else                                           1013   else
1120     normal = G4ThreeVector( rNorm*hit.x()/rx,    1014     normal = G4ThreeVector( rNorm*hit.x()/rx, rNorm*hit.y()/rx, zNorm );
1121   return true;                                   1015   return true;
1122 }                                                1016 }
1123                                                  1017 
                                                   >> 1018 
                                                   >> 1019 //
1124 // FindLineIntersect                             1020 // FindLineIntersect
1125 //                                               1021 //
1126 // Decide the point at which two 2-dimensiona    1022 // Decide the point at which two 2-dimensional lines intersect
1127 //                                               1023 //
1128 // Equation of line: x = x1 + s*tx1              1024 // Equation of line: x = x1 + s*tx1
1129 //                   y = y1 + s*ty1              1025 //                   y = y1 + s*ty1
1130 //                                               1026 //
1131 // It is assumed that the lines are *not* par    1027 // It is assumed that the lines are *not* parallel
1132 //                                               1028 //
1133 void G4PolyconeSide::FindLineIntersect( G4dou    1029 void G4PolyconeSide::FindLineIntersect( G4double x1,  G4double y1,
1134                                         G4dou    1030                                         G4double tx1, G4double ty1,
1135                                         G4dou    1031                                         G4double x2,  G4double y2,
1136                                         G4dou    1032                                         G4double tx2, G4double ty2,
1137                                         G4dou << 1033                                         G4double &x,  G4double &y )
1138 {                                                1034 {
1139   //                                             1035   //
1140   // The solution is a simple linear equation    1036   // The solution is a simple linear equation
1141   //                                             1037   //
1142   G4double deter = tx1*ty2 - tx2*ty1;            1038   G4double deter = tx1*ty2 - tx2*ty1;
1143                                                  1039   
1144   G4double s1 = ((x2-x1)*ty2 - tx2*(y2-y1))/d    1040   G4double s1 = ((x2-x1)*ty2 - tx2*(y2-y1))/deter;
1145   G4double s2 = ((x2-x1)*ty1 - tx1*(y2-y1))/d    1041   G4double s2 = ((x2-x1)*ty1 - tx1*(y2-y1))/deter;
1146                                                  1042 
1147   //                                             1043   //
1148   // We want the answer to not depend on whic    1044   // We want the answer to not depend on which order the
1149   // lines were specified. Take average.         1045   // lines were specified. Take average.
1150   //                                             1046   //
1151   x = 0.5*( x1+s1*tx1 + x2+s2*tx2 );             1047   x = 0.5*( x1+s1*tx1 + x2+s2*tx2 );
1152   y = 0.5*( y1+s1*ty1 + y2+s2*ty2 );             1048   y = 0.5*( y1+s1*ty1 + y2+s2*ty2 );
1153 }                                                1049 }
1154                                                  1050 
                                                   >> 1051 //
1155 // Calculate surface area for GetPointOnSurfa    1052 // Calculate surface area for GetPointOnSurface()
1156 //                                               1053 //
1157 G4double G4PolyconeSide::SurfaceArea()           1054 G4double G4PolyconeSide::SurfaceArea() 
1158 {                                                1055 { 
1159   if(fSurfaceArea==0.)                        << 1056   if(fSurfaceArea==0)
1160   {                                              1057   {
1161     fSurfaceArea = (r[0]+r[1])* std::sqrt(sqr    1058     fSurfaceArea = (r[0]+r[1])* std::sqrt(sqr(r[0]-r[1])+sqr(z[0]-z[1]));
1162     fSurfaceArea *= 0.5*(deltaPhi);              1059     fSurfaceArea *= 0.5*(deltaPhi);
1163   }                                              1060   }  
1164   return fSurfaceArea;                           1061   return fSurfaceArea;
1165 }                                                1062 }
1166                                                  1063 
                                                   >> 1064 //
1167 // GetPointOnFace                                1065 // GetPointOnFace
1168 //                                               1066 //
1169 G4ThreeVector G4PolyconeSide::GetPointOnFace(    1067 G4ThreeVector G4PolyconeSide::GetPointOnFace()
1170 {                                                1068 {
1171   G4double x,y,zz;                               1069   G4double x,y,zz;
1172   G4double rr,phi,dz,dr;                         1070   G4double rr,phi,dz,dr;
1173   dr=r[1]-r[0];dz=z[1]-z[0];                     1071   dr=r[1]-r[0];dz=z[1]-z[0];
1174   phi=startPhi+deltaPhi*G4UniformRand();         1072   phi=startPhi+deltaPhi*G4UniformRand();
1175   rr=r[0]+dr*G4UniformRand();                    1073   rr=r[0]+dr*G4UniformRand();
1176                                                  1074  
1177   x=rr*std::cos(phi);                            1075   x=rr*std::cos(phi);
1178   y=rr*std::sin(phi);                            1076   y=rr*std::sin(phi);
1179                                                  1077 
1180   // PolyconeSide has a Ring Form                1078   // PolyconeSide has a Ring Form
1181   //                                             1079   //
1182   if (dz==0.)                                    1080   if (dz==0.)
1183   {                                              1081   {
1184     zz=z[0];                                     1082     zz=z[0];
1185   }                                              1083   }
1186   else                                           1084   else
1187   {                                              1085   {
1188     if(dr==0.)  // PolyconeSide has a Tube Fo    1086     if(dr==0.)  // PolyconeSide has a Tube Form
1189     {                                            1087     {
1190       zz = z[0]+dz*G4UniformRand();              1088       zz = z[0]+dz*G4UniformRand();
1191     }                                            1089     }
1192     else                                         1090     else
1193     {                                            1091     {
1194       zz = z[0]+(rr-r[0])*dz/dr;                 1092       zz = z[0]+(rr-r[0])*dz/dr;
1195     }                                            1093     }
1196   }                                              1094   }
1197                                                  1095 
1198   return {x,y,zz};                            << 1096   return G4ThreeVector(x,y,zz);
1199 }                                                1097 }
1200                                                  1098