Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4BREPSolidCone.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// $Id$
27//
28// ----------------------------------------------------------------------
29// GEANT 4 class source file
30//
31// G4BREPSolidCone.cc
32//
33// ----------------------------------------------------------------------
34
35#include "G4BREPSolidCone.hh"
36#include "G4FPlane.hh"
37#include "G4FConicalSurface.hh"
39#include "G4CircularCurve.hh"
40
42 const G4ThreeVector& origin,
43 const G4ThreeVector& axis,
44 const G4ThreeVector& direction,
45 G4double length,
46 G4double radius,
47 G4double large_radius)
48 : G4BREPSolid(name)
49{
51 active=1;
52
53 // Save constructor parameters
54 constructorParams.origin = origin;
55 constructorParams.axis = axis;
56 constructorParams.direction = direction;
57 constructorParams.length = length;
58 constructorParams.radius = radius;
59 constructorParams.large_radius = large_radius;
60
61 InitializeCone();
62}
63
65 : G4BREPSolid(a)
66{
67}
68
70{
71}
72
74 : G4BREPSolid(rhs)
75{
76 constructorParams.origin = rhs.constructorParams.origin;
77 constructorParams.axis = rhs.constructorParams.axis;
78 constructorParams.direction = rhs.constructorParams.direction;
79 constructorParams.length = rhs.constructorParams.length;
80 constructorParams.radius = rhs.constructorParams.radius;
81 constructorParams.large_radius = rhs.constructorParams.large_radius;
82
83 InitializeCone();
84}
85
87{
88 // Check assignment to self
89 //
90 if (this == &rhs) { return *this; }
91
92 // Copy base class data
93 //
95
96 // Copy data
97 //
98 constructorParams.origin = rhs.constructorParams.origin;
99 constructorParams.axis = rhs.constructorParams.axis;
100 constructorParams.direction = rhs.constructorParams.direction;
101 constructorParams.length = rhs.constructorParams.length;
102 constructorParams.radius = rhs.constructorParams.radius;
103 constructorParams.large_radius = rhs.constructorParams.large_radius;
104
105 InitializeCone();
106
107 return *this;
108}
109
110void G4BREPSolidCone::InitializeCone()
111{
112
113 SurfaceVec = new G4Surface*[3];
114 G4Point3D ArcStart1 = G4Point3D(constructorParams.origin
115 + (constructorParams.radius
116 * constructorParams.direction));
117 G4Vector3D tmpaxis(constructorParams.axis);
118 G4Vector3D tmporigin(constructorParams.origin);
119 G4Point3D tmppoint;
120
121 tmppoint= G4Point3D(constructorParams.origin)
122 + (constructorParams.length*tmpaxis);
123 G4Point3D origin2(tmppoint.x(), tmppoint.y(), tmppoint.z());
124
125 tmppoint= origin2 + (constructorParams.large_radius*tmpaxis);
126 G4Point3D ArcStart2(tmppoint.x(), tmppoint.y(), tmppoint.z());
127
128 G4Ray::Vcross(tmpaxis, constructorParams.axis, constructorParams.direction);
129 G4ThreeVector axis2(tmpaxis.x(),tmpaxis.y(), tmpaxis.z());
130
131 G4CurveVector CVec;
132 G4CircularCurve* tmp;
133
134 tmp = new G4CircularCurve();
135 tmp->Init(G4Axis2Placement3D(constructorParams.direction,
136 axis2, constructorParams.origin),
137 constructorParams.large_radius);
138 tmp->SetBounds(ArcStart1, ArcStart1);
139 CVec.push_back(tmp);
140
141 tmp = new G4CircularCurve();
142 tmp->Init(G4Axis2Placement3D(constructorParams.direction, axis2, origin2),
143 constructorParams.large_radius);
144 tmp->SetBounds(ArcStart2, ArcStart2);
145 CVec.push_back(tmp);
146
147 SurfaceVec[0] = new G4FConicalSurface(tmporigin, constructorParams.axis,
148 constructorParams.length,
149 constructorParams.radius,
150 constructorParams.large_radius);
151 SurfaceVec[0]->SetBoundaries(&CVec);
152
153 // Create end planes & boundaries for cone solid
154 G4CurveVector CVec2;
155 tmp = new G4CircularCurve();
156 tmp->Init(G4Axis2Placement3D(constructorParams.direction,
157 axis2, constructorParams.origin),
158 constructorParams.radius);
159 tmp->SetBounds(ArcStart1, ArcStart1);
160 CVec2.push_back(tmp);
161
162 SurfaceVec[1] = new G4FPlane(tmpaxis, constructorParams.direction, origin2);
163 SurfaceVec[1]->SetBoundaries(&CVec2);
164
165 CVec2[0] = tmp = new G4CircularCurve();
166 tmp->Init(G4Axis2Placement3D(constructorParams.direction, axis2, origin2),
167 constructorParams.large_radius);
168 tmp->SetBounds(ArcStart2, ArcStart2);
169
170 SurfaceVec[2] = new G4FPlane(tmpaxis, constructorParams.direction,
171 constructorParams.origin);
172 SurfaceVec[2]->SetBoundaries(&CVec2);
173
174 Initialize();
175}
176
178{
179 // Calc bounding box for solids and surfaces
180 // Convert concave planes to convex
181 //
182 ShortestDistance=1000000;
184 if(!Box || !AxisBox) { IsConvex(); }
185 CalcBBoxes();
186}
187
189{
190 G4double dist1 = SurfaceVec[0]->HowNear(Pt);
193 if(dist1 > dist2) dist1 = dist2;
194 if(dist1 > dist3) dist1 = dist3;
195 if(dist1 > 0) return kInside;
196 if(dist1 < 0) return kOutside;
197 return kSurface;
198}
199
201{
202 G4Vector3D n = SurfaceVec[0]->Normal(Pt);
203 G4ThreeVector norm(n.x(), n.y(), n.z());
204 return norm;
205}
206
208{
209 G4double dist1 = std::fabs(SurfaceVec[0]->HowNear(Pt));
210 G4double dist2 = std::fabs(SurfaceVec[1]->ClosestDistanceToPoint(Pt));
211 G4double dist3 = std::fabs(SurfaceVec[2]->ClosestDistanceToPoint(Pt));
212 if(dist1 > dist2) dist1 = dist2;
213 if(dist1 > dist3) dist1 = dist3;
214 return dist1;
215
216}
217
219 register const G4ThreeVector& V) const
220{
221 Reset();
222 G4Vector3D Pttmp(Pt);
223 G4Vector3D Vtmp(V);
224 // G4double kInfinity = 10e20;
225 G4Ray r(Pttmp, Vtmp);
226
227 if(SurfaceVec[0]->Intersect( r ))
228 {
230 return ShortestDistance;
231 }
232 return kInfinity;
233}
234
236 register const G4ThreeVector& V,
237 const G4bool,
238 G4bool *validNorm,
239 G4ThreeVector *) const
240{
241 if(validNorm)
242 *validNorm = false;
243 Reset();
244
245 G4Vector3D Pttmp(Pt);
246 G4Vector3D Vtmp(V);
247 // G4double kInfinity = 10e20;
248
249 G4Ray r(Pttmp, Vtmp);
250 if(SurfaceVec[0]->Intersect( r ))
251 {
253 return ShortestDistance;
254 }
255 return kInfinity;
256}
257
259{
260 G4double dist1 = std::fabs(SurfaceVec[0]->HowNear(Pt));
261 G4double dist2 = std::fabs(SurfaceVec[1]->ClosestDistanceToPoint(Pt));
262 G4double dist3 = std::fabs(SurfaceVec[2]->ClosestDistanceToPoint(Pt));
263 if(dist1 > dist2) dist1 = dist2;
264 if(dist1 > dist3) dist1 = dist3;
265 return dist1;
266}
267
269{
270 return new G4BREPSolidCone(*this);
271}
272
273std::ostream& G4BREPSolidCone::StreamInfo(std::ostream& os) const
274{
275 // Streams solid contents to output stream.
276
278 << "\n origin: " << constructorParams.origin
279 << "\n axis: " << constructorParams.axis
280 << "\n direction: " << constructorParams.direction
281 << "\n length: " << constructorParams.length
282 << "\n radius: " << constructorParams.radius
283 << "\n large_radius: " << constructorParams.large_radius
284 << "\n-----------------------------------------------------------\n";
285
286 return os;
287}
288
std::vector< G4Curve * > G4CurveVector
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
double G4double
Definition: G4Types.hh:64
bool G4bool
Definition: G4Types.hh:67
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4BREPSolidCone & operator=(const G4BREPSolidCone &rhs)
std::ostream & StreamInfo(std::ostream &os) const
EInside Inside(register const G4ThreeVector &Pt) const
G4VSolid * Clone() const
G4double DistanceToOut(register const G4ThreeVector &p, register const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
G4double DistanceToIn(const G4ThreeVector &p) const
G4BREPSolidCone(const G4String &name, const G4ThreeVector &origin, const G4ThreeVector &axis, const G4ThreeVector &direction, G4double length, G4double radius, G4double large_radius)
G4Surface ** SurfaceVec
Definition: G4BREPSolid.hh:231
G4BREPSolid & operator=(const G4BREPSolid &rhs)
Definition: G4BREPSolid.cc:138
G4int Intersect(register const G4Ray &) const
G4bool IsConvex()
Definition: G4BREPSolid.cc:460
G4int nb_of_surfaces
Definition: G4BREPSolid.hh:229
virtual std::ostream & StreamInfo(std::ostream &os) const
virtual void Reset() const
Definition: G4BREPSolid.cc:201
void CheckSurfaceNormals()
Definition: G4BREPSolid.cc:213
virtual void CalcBBoxes()
static G4double ShortestDistance
Definition: G4BREPSolid.hh:221
void Init(const G4Axis2Placement3D &position0, G4double radius0)
void SetBounds(G4double p1, G4double p2)
Definition: G4Ray.hh:49
static void Vcross(G4Plane &a, const G4Vector3D &b, const G4Vector3D &c)
Definition: G4Ray.cc:267
virtual G4double ClosestDistanceToPoint(const G4Point3D &Pt)
Definition: G4Surface.cc:203
virtual G4Vector3D Normal(const G4Vector3D &p) const
Definition: G4Surface.cc:162
void SetBoundaries(G4CurveVector *)
Definition: G4Surface.cc:140
virtual G4double HowNear(const G4Vector3D &x) const
Definition: G4Surface.cc:283
G4double GetDistance() const
EInside
Definition: geomdefs.hh:58
@ kInside
Definition: geomdefs.hh:58
@ kOutside
Definition: geomdefs.hh:58
@ kSurface
Definition: geomdefs.hh:58