2 // ********************************************************************
 
    3 // * License and Disclaimer                                           *
 
    5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
 
    6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
 
    7 // * conditions of the Geant4 Software License,  included in the file *
 
    8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
 
    9 // * include a list of copyright holders.                             *
 
   11 // * Neither the authors of this software system, nor their employing *
 
   12 // * institutes,nor the agencies providing financial support for this *
 
   13 // * work  make  any representation or  warranty, express or implied, *
 
   14 // * regarding  this  software system or assume any liability for its *
 
   15 // * use.  Please see the license in the file  LICENSE  and URL above *
 
   16 // * for the full disclaimer and the limitation of liability.         *
 
   18 // * This  code  implementation is the result of  the  scientific and *
 
   19 // * technical work of the GEANT4 collaboration.                      *
 
   20 // * By using,  copying,  modifying or  distributing the software (or *
 
   21 // * any work based  on the software)  you  agree  to acknowledge its *
 
   22 // * use  in  resulting  scientific  publications,  and indicate your *
 
   23 // * acceptance of all terms of the Geant4 Software license.          *
 
   24 // ********************************************************************
 
   27 // $Id: G4Sphere.icc 83572 2014-09-01 15:23:27Z gcosmo $
 
   29 // --------------------------------------------------------------------
 
   30 // GEANT 4 inline definitions file
 
   34 // Implementation of inline methods of G4Sphere
 
   35 // --------------------------------------------------------------------
 
   38 G4double G4Sphere::GetInsideRadius() const
 
   44 G4double G4Sphere::GetInnerRadius() const
 
   50 G4double G4Sphere::GetOuterRadius() const
 
   56 G4double G4Sphere::GetStartPhiAngle() const
 
   62 G4double G4Sphere::GetDeltaPhiAngle() const
 
   68 G4double G4Sphere::GetStartThetaAngle() const
 
   73 G4double G4Sphere::GetDeltaThetaAngle() const
 
   79 void G4Sphere::Initialize()
 
   83   fRebuildPolyhedron = true;
 
   87 void G4Sphere::InitializePhiTrigonometry()
 
   89   hDPhi = 0.5*fDPhi;                       // half delta phi
 
   93   sinCPhi    = std::sin(cPhi);
 
   94   cosCPhi    = std::cos(cPhi);
 
   95   cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
 
   96   cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
 
   97   sinSPhi = std::sin(fSPhi);
 
   98   cosSPhi = std::cos(fSPhi);
 
   99   sinEPhi = std::sin(ePhi);
 
  100   cosEPhi = std::cos(ePhi);
 
  104 void G4Sphere::InitializeThetaTrigonometry()
 
  106   eTheta  = fSTheta + fDTheta;
 
  108   sinSTheta = std::sin(fSTheta);
 
  109   cosSTheta = std::cos(fSTheta);
 
  110   sinETheta = std::sin(eTheta);
 
  111   cosETheta = std::cos(eTheta);
 
  113   tanSTheta  = std::tan(fSTheta);
 
  114   tanSTheta2 = tanSTheta*tanSTheta;
 
  115   tanETheta  = std::tan(eTheta);
 
  116   tanETheta2 = tanETheta*tanETheta;
 
  120 void G4Sphere::CheckThetaAngles(G4double sTheta, G4double dTheta)
 
  122   if ( (sTheta<0) || (sTheta>CLHEP::pi) )
 
  124     std::ostringstream message;
 
  125     message << "sTheta outside 0-PI range." << G4endl
 
  126             << "Invalid starting Theta angle for solid: " << GetName();
 
  127     G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002",
 
  128                 FatalException, message);
 
  134   if ( dTheta+sTheta >= CLHEP::pi )
 
  136     fDTheta=CLHEP::pi-sTheta;
 
  138   else if ( dTheta > 0 )
 
  144     std::ostringstream message;
 
  145     message << "Invalid dTheta." << G4endl
 
  146             << "Negative delta-Theta (" << dTheta << "), for solid: "
 
  148     G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002",
 
  149                 FatalException, message);
 
  151   if ( fDTheta-fSTheta < CLHEP::pi ) { fFullThetaSphere = false; }
 
  152   else                               { fFullThetaSphere = true ; }
 
  153   fFullSphere = fFullPhiSphere && fFullThetaSphere;
 
  155   InitializeThetaTrigonometry();
 
  159 void G4Sphere::CheckSPhiAngle(G4double sPhi)
 
  161   // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
 
  165     fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi);
 
  169     fSPhi = std::fmod(sPhi,CLHEP::twopi) ;
 
  171   if ( fSPhi+fDPhi > CLHEP::twopi )
 
  173     fSPhi -= CLHEP::twopi ;
 
  178 void G4Sphere::CheckDPhiAngle(G4double dPhi)
 
  180   fFullPhiSphere = true;
 
  181   if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 )
 
  187     fFullPhiSphere = false;
 
  194       std::ostringstream message;
 
  195       message << "Invalid dphi." << G4endl
 
  196               << "Negative delta-Phi (" << dPhi << "), for solid: "
 
  198       G4Exception("G4Sphere::CheckDPhiAngle()", "GeomSolids0002",
 
  199                   FatalException, message);
 
  205 void G4Sphere::CheckPhiAngles(G4double sPhi, G4double dPhi)
 
  207   CheckDPhiAngle(dPhi);
 
  208   if (!fFullPhiSphere && sPhi) { CheckSPhiAngle(sPhi); }
 
  209   fFullSphere = fFullPhiSphere && fFullThetaSphere;
 
  211   InitializePhiTrigonometry();
 
  215 void G4Sphere::SetInsideRadius(G4double newRmin)
 
  218   fRminTolerance = (fRmin) ? std::max( kRadTolerance, fEpsilon*fRmin ) : 0;
 
  223 void G4Sphere::SetInnerRadius(G4double newRmin)
 
  225   SetInsideRadius(newRmin);
 
  229 void G4Sphere::SetOuterRadius(G4double newRmax)
 
  232   fRmaxTolerance = std::max( kRadTolerance, fEpsilon*fRmax );
 
  237 void G4Sphere::SetStartPhiAngle(G4double newSPhi, G4bool compute)
 
  239   // Flag 'compute' can be used to explicitely avoid recomputation of
 
  240   // trigonometry in case SetDeltaPhiAngle() is invoked afterwards
 
  242   CheckSPhiAngle(newSPhi);
 
  243   fFullPhiSphere = false;
 
  244   if (compute)  { InitializePhiTrigonometry(); }
 
  249 void G4Sphere::SetDeltaPhiAngle(G4double newDPhi)
 
  251   CheckPhiAngles(fSPhi, newDPhi);
 
  256 void G4Sphere::SetStartThetaAngle(G4double newSTheta)
 
  258   CheckThetaAngles(newSTheta, fDTheta);
 
  263 void G4Sphere::SetDeltaThetaAngle(G4double newDTheta)
 
  265   CheckThetaAngles(fSTheta, newDTheta);
 
  269 // Old access functions
 
  272 G4double G4Sphere::GetRmin() const 
 
  274   return GetInsideRadius();
 
  278 G4double G4Sphere::GetRmax() const
 
  280   return GetOuterRadius();
 
  284 G4double G4Sphere::GetSPhi() const
 
  286   return GetStartPhiAngle();
 
  290 G4double G4Sphere::GetDPhi() const
 
  292   return GetDeltaPhiAngle();
 
  296 G4double G4Sphere::GetSTheta() const
 
  298   return GetStartThetaAngle();
 
  302 G4double G4Sphere::GetDTheta() const
 
  304   return GetDeltaThetaAngle();
 
  308 G4double G4Sphere::GetCubicVolume()
 
  310   if(fCubicVolume != 0.) {;}
 
  311   else { fCubicVolume = fDPhi*(std::cos(fSTheta)-std::cos(fSTheta+fDTheta))*
 
  312                               (fRmax*fRmax*fRmax-fRmin*fRmin*fRmin)/3.; }