Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4BREPSolidSphere.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
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. *
10 // * *
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. *
17 // * *
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 // ********************************************************************
25 //
26 //
27 // $Id$
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4BREPSolidSphere.cc
33 //
34 // ----------------------------------------------------------------------
35 
36 #include "G4BREPSolidSphere.hh"
37 #include "G4PhysicalConstants.hh"
38 #include "G4SphericalSurface.hh"
39 
41  const G4Vector3D& origin,
42  const G4Vector3D& xhat,
43  const G4Vector3D& zhat,
44  G4double radius)
45  : G4BREPSolid(name)
46 {
47  constructorParams.origin = origin;
48  constructorParams.xhat = xhat;
49  constructorParams.zhat = zhat;
50  constructorParams.radius = radius;
51 
52  active=1;
53  InitializeSphere();
54 }
55 
57  : G4BREPSolid(a)
58 {
59 }
60 
62 {
63 }
64 
66  : G4BREPSolid(rhs)
67 {
68  constructorParams.origin = rhs.constructorParams.origin;
69  constructorParams.xhat = rhs.constructorParams.xhat;
70  constructorParams.zhat = rhs.constructorParams.zhat;
71  constructorParams.radius = rhs.constructorParams.radius;
72 
73  InitializeSphere();
74 }
75 
78 {
79  // Check assignment to self
80  //
81  if (this == &rhs) { return *this; }
82 
83  // Copy base class data
84  //
86 
87  // Copy data
88  //
89  constructorParams.origin = rhs.constructorParams.origin;
90  constructorParams.xhat = rhs.constructorParams.xhat;
91  constructorParams.zhat = rhs.constructorParams.zhat;
92  constructorParams.radius = rhs.constructorParams.radius;
93 
94  InitializeSphere();
95 
96  return *this;
97 }
98 
99 void G4BREPSolidSphere::InitializeSphere()
100 {
101  SurfaceVec = new G4Surface*[1];
102  G4double ph1 = 0;
103  G4double ph2 = 2*pi;
104  G4double th1 = 0;
105  G4double th2 = pi;
106  SurfaceVec[0] = new G4SphericalSurface(constructorParams.origin,
107  constructorParams.xhat,
108  constructorParams.zhat,
109  constructorParams.radius,
110  ph1, ph2, th1, th2);
111  nb_of_surfaces = 1;
112  Initialize();
113 }
114 
116 {
117  G4double Dist = SurfaceVec[0]->HowNear(Pt);
118  if(Dist > 0+kCarTolerance) return kInside;
119  if(Dist < 0-kCarTolerance) return kOutside;
120  return kSurface;
121 }
122 
123 
125 {
126  G4Vector3D n = SurfaceVec[0]->Normal(Pt);
127  G4ThreeVector norm(n.x(), n.y(), n.z());
128  return norm;
129 }
130 
131 
133 {
134  return std::fabs(SurfaceVec[0]->HowNear(Pt));
135 }
136 
137 
139  register const G4ThreeVector& V) const
140 {
141  // SphReset();
142  G4Vector3D Pttmp(Pt);
143  G4Vector3D Vtmp(V);
144  G4Ray r(Pttmp, Vtmp);
145  G4int Result = SurfaceVec[0]->Intersect( r );
146 
147  if(Result>0)
148  {
150  return std::sqrt(ShortestDistance);
151  }
152  return kInfinity;
153 }
154 
155 
157  register const G4ThreeVector& V,
158  const G4bool calcNorm,
159  G4bool *validNorm,
160  G4ThreeVector *n) const
161 {
162  if(validNorm) *validNorm = false;
163  // SphReset();
164  G4Vector3D Pttmp(Pt);
165  G4Vector3D Vtmp(V);
166  G4Ray r(Pttmp, Vtmp);
167 
168  if(SurfaceVec[0]->Intersect( r ))
169  {
170  if(calcNorm)
171  {
172  if(validNorm) *validNorm = true;
173  *n = SurfaceNormal(Pt);
174  }
175 
177  return std::sqrt(ShortestDistance);
178  }
179  return kInfinity;
180 }
181 
182 
184 {
185  return std::fabs(SurfaceVec[0]->HowNear(Pt));
186 }
187 
189 {
190  return new G4BREPSolidSphere(*this);
191 }
192 
193 std::ostream& G4BREPSolidSphere::StreamInfo(std::ostream& os) const
194 {
195  // Streams solid contents to output stream.
196 
198  << "\n origin: " << constructorParams.origin
199  << "\n xhat: " << constructorParams.xhat
200  << "\n zhat: " << constructorParams.zhat
201  << "\n radius: " << constructorParams.radius
202  << "\n-----------------------------------------------------------\n";
203 
204  return os;
205 }
206