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// ********************************************************************
26// Implementation of inline methods of G4Sphere
27// --------------------------------------------------------------------
30G4double G4Sphere::GetInnerRadius() const
36G4double G4Sphere::GetOuterRadius() const
42G4double G4Sphere::GetStartPhiAngle() const
48G4double G4Sphere::GetDeltaPhiAngle() const
54G4double G4Sphere::GetStartThetaAngle() const
59G4double G4Sphere::GetDeltaThetaAngle() const
65G4double G4Sphere::GetSinStartPhi () const
71G4double G4Sphere::GetCosStartPhi () const
77G4double G4Sphere::GetSinEndPhi () const
83G4double G4Sphere::GetCosEndPhi () const
89G4double G4Sphere::GetSinStartTheta () const
95G4double G4Sphere::GetCosStartTheta () const
101G4double G4Sphere::GetSinEndTheta () const
107G4double G4Sphere::GetCosEndTheta () const
113void G4Sphere::Initialize()
117 fRebuildPolyhedron = true;
121void G4Sphere::InitializePhiTrigonometry()
123 hDPhi = 0.5*fDPhi; // half delta phi
124 cPhi = fSPhi + hDPhi;
125 ePhi = fSPhi + fDPhi;
127 sinCPhi = std::sin(cPhi);
128 cosCPhi = std::cos(cPhi);
129 cosHDPhi = std::cos(hDPhi);
130 cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
131 cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
132 sinSPhi = std::sin(fSPhi);
133 cosSPhi = std::cos(fSPhi);
134 sinEPhi = std::sin(ePhi);
135 cosEPhi = std::cos(ePhi);
139void G4Sphere::InitializeThetaTrigonometry()
141 eTheta = fSTheta + fDTheta;
143 sinSTheta = std::sin(fSTheta);
144 cosSTheta = std::cos(fSTheta);
145 sinETheta = std::sin(eTheta);
146 cosETheta = std::cos(eTheta);
148 tanSTheta = sinSTheta/cosSTheta;
149 tanSTheta2 = tanSTheta*tanSTheta;
150 tanETheta = sinETheta/cosETheta;
151 tanETheta2 = tanETheta*tanETheta;
155void G4Sphere::CheckThetaAngles(G4double sTheta, G4double dTheta)
157 if ( (sTheta<0) || (sTheta>CLHEP::pi) )
159 std::ostringstream message;
160 message << "sTheta outside 0-PI range." << G4endl
161 << "Invalid starting Theta angle for solid: " << GetName();
162 G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002",
163 FatalException, message);
169 if ( dTheta+sTheta >= CLHEP::pi )
171 fDTheta=CLHEP::pi-sTheta;
173 else if ( dTheta > 0 )
179 std::ostringstream message;
180 message << "Invalid dTheta." << G4endl
181 << "Negative delta-Theta (" << dTheta << "), for solid: "
183 G4Exception("G4Sphere::CheckThetaAngles()", "GeomSolids0002",
184 FatalException, message);
186 if ( fDTheta-fSTheta < CLHEP::pi ) { fFullThetaSphere = false; }
187 else { fFullThetaSphere = true ; }
188 fFullSphere = fFullPhiSphere && fFullThetaSphere;
190 InitializeThetaTrigonometry();
194void G4Sphere::CheckSPhiAngle(G4double sPhi)
196 // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
200 fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi);
204 fSPhi = std::fmod(sPhi,CLHEP::twopi) ;
206 if ( fSPhi+fDPhi > CLHEP::twopi )
208 fSPhi -= CLHEP::twopi ;
213void G4Sphere::CheckDPhiAngle(G4double dPhi)
215 fFullPhiSphere = true;
216 if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 )
222 fFullPhiSphere = false;
229 std::ostringstream message;
230 message << "Invalid dphi." << G4endl
231 << "Negative delta-Phi (" << dPhi << "), for solid: "
233 G4Exception("G4Sphere::CheckDPhiAngle()", "GeomSolids0002",
234 FatalException, message);
240void G4Sphere::CheckPhiAngles(G4double sPhi, G4double dPhi)
242 CheckDPhiAngle(dPhi);
243 if (!fFullPhiSphere && sPhi) { CheckSPhiAngle(sPhi); }
244 fFullSphere = fFullPhiSphere && fFullThetaSphere;
246 InitializePhiTrigonometry();
250void G4Sphere::SetInnerRadius(G4double newRmin)
253 fRminTolerance = (fRmin) ? std::max( kRadTolerance, fEpsilon*fRmin ) : 0;
258void G4Sphere::SetOuterRadius(G4double newRmax)
261 fRmaxTolerance = std::max( kRadTolerance, fEpsilon*fRmax );
266void G4Sphere::SetStartPhiAngle(G4double newSPhi, G4bool compute)
268 // Flag 'compute' can be used to explicitely avoid recomputation of
269 // trigonometry in case SetDeltaPhiAngle() is invoked afterwards
271 CheckSPhiAngle(newSPhi);
272 fFullPhiSphere = false;
273 if (compute) { InitializePhiTrigonometry(); }
278void G4Sphere::SetDeltaPhiAngle(G4double newDPhi)
280 CheckPhiAngles(fSPhi, newDPhi);
285void G4Sphere::SetStartThetaAngle(G4double newSTheta)
287 CheckThetaAngles(newSTheta, fDTheta);
292void G4Sphere::SetDeltaThetaAngle(G4double newDTheta)
294 CheckThetaAngles(fSTheta, newDTheta);