Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VTwistSurface.icc
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// G4VTwistSurface class inline methods
27//
28// 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp), created.
29// 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
30// from original version in Jupiter-2.5.02 application.
31// --------------------------------------------------------------------
32
33//=====================================================================
34//* DistanceToPlaneWithV ----------------------------------------------
35
36inline
37G4double G4VTwistSurface::DistanceToPlaneWithV(const G4ThreeVector& p,
38 const G4ThreeVector& v,
39 const G4ThreeVector& x0,
40 const G4ThreeVector& n0,
41 G4ThreeVector& xx)
42{
43 G4double q = n0 * v;
44 G4double t = kInfinity;
45 if (q) { t = (n0 * (x0 - p)) / q; }
46 xx = p + t * v;
47 return t;
48}
49
50//=====================================================================
51//* DistanceToPlane ---------------------------------------------------
52
53inline
54G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector& p,
55 const G4ThreeVector& x0,
56 const G4ThreeVector& n0,
57 G4ThreeVector& xx)
58{
59 // DistanceToPlane :
60 // Calculate distance to plane in local coordinate,
61 // then return distance and global intersection points.
62 //
63 // p - location of flying particle
64 // x0 - reference point of surface
65 // xx - a foot of perpendicular line from p to the plane
66 // t - distance from xx to p
67 // n - a unit normal of this plane from plane to p.
68 //
69 // equation of plane:
70 // n*(x - x0) = 0;
71 //
72 // vector to xx:
73 // xx = p - t*n
74 //
75 // where
76 // t = n * (p - x0) / std::fabs(n)
77 //
78 G4double t;
79 G4ThreeVector n = n0.unit();
80 t = n * (p - x0);
81 xx = p - t * n;
82 return t;
83}
84
85//=====================================================================
86//* DistanceToPlane ---------------------------------------------------
87
88inline
89G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector& p,
90 const G4ThreeVector& x0,
91 const G4ThreeVector& t1,
92 const G4ThreeVector& t2,
93 G4ThreeVector& xx,
94 G4ThreeVector& n)
95{
96 // DistanceToPlane :
97 // Calculate distance to plane in local coordinate,
98 // then return distance and global intersection points.
99 // t1 - 1st. vector lying on the plane
100 // t2 - 2nd. vector lying on the plane
101
102 n = (t1.cross(t2)).unit();
103 return DistanceToPlane(p, x0, n, xx);
104}
105
106//=====================================================================
107//* DistanceToLine ----------------------------------------------------
108
109inline
110G4double G4VTwistSurface::DistanceToLine(const G4ThreeVector& p,
111 const G4ThreeVector& x0,
112 const G4ThreeVector& d,
113 G4ThreeVector& xx)
114{
115 // DistanceToLine :
116 // Calculate distance to line,
117 // then return distance and global intersection points.
118 //
119 // p - location of flying particle
120 // x0 - reference point of line
121 // d - direction vector of line
122 // xx - a foot of perpendicular line from p to the plane
123 // t - distance from xx to p
124 //
125 // Equation
126 //
127 // distance^2 = |(xx - p)|^2
128 // with
129 // xx = x0 + t*d
130 //
131 // (d/dt)distance^2 = (d/dt)|((x0 + t*d) - p)|^2
132 // = 2*t*|d|^2 + 2*d*(x0 - p)
133 // = 0 // smallest distance
134 // then
135 // t = - d*(x0 - p) / |d|^2
136 //
137
138 G4double t;
139 G4ThreeVector dir = d.unit();
140 t = - dir * (x0 - p); // |dir|^2 = 1.
141 xx = x0 + t * dir;
142
143 G4ThreeVector dist = xx - p;
144 return dist.mag();
145}
146
147//=====================================================================
148//* IsAxis0 -----------------------------------------------------------
149
150inline
151G4bool G4VTwistSurface::IsAxis0(G4int areacode) const
152{
153 if (areacode & sAxis0) return true;
154 return false;
155}
156
157//=====================================================================
158//* IsAxis1 -----------------------------------------------------------
159
160inline
161G4bool G4VTwistSurface::IsAxis1(G4int areacode) const
162{
163 if (areacode & sAxis1) return true;
164 return false;
165}
166
167//=====================================================================
168//* IsOutside ---------------------------------------------------------
169
170inline
171G4bool G4VTwistSurface::IsOutside(G4int areacode) const
172{
173 if (areacode & sInside) return false;
174 return true;
175}
176
177//=====================================================================
178//* IsInside ----------------------------------------------------------
179
180inline
181G4bool G4VTwistSurface::IsInside(G4int areacode, G4bool testbitmode) const
182{
183 if (areacode & sInside) {
184 if (testbitmode) {
185 return true;
186 } else {
187 if (!((areacode & sBoundary) || (areacode & sCorner))) return true;
188 }
189 }
190 return false;
191}
192
193//=====================================================================
194//* IsBoundary --------------------------------------------------------
195
196inline
197G4bool G4VTwistSurface::IsBoundary(G4int areacode, G4bool testbitmode) const
198{
199 if ((areacode & sBoundary) == sBoundary) {
200 if (testbitmode) {
201 return true;
202 } else {
203 if ((areacode & sInside) == sInside) return true;
204 }
205 }
206 return false;
207}
208
209//=====================================================================
210//* IsCorner ----------------------------------------------------------
211
212inline
213G4bool G4VTwistSurface::IsCorner(G4int areacode, G4bool testbitmode) const
214{
215 if ((areacode & sCorner) == sCorner) {
216 if (testbitmode) {
217 return true;
218 } else {
219 if ((areacode & sInside) == sInside) return true;
220 }
221 }
222 return false;
223}
224
225//=====================================================================
226//* GetAxisType -------------------------------------------------------
227
228inline
229G4int G4VTwistSurface::GetAxisType(G4int areacode, G4int whichaxis) const
230{
231 G4int axiscode = areacode & sAxisMask & whichaxis;
232
233 if (axiscode == (sAxisX & sAxis0) ||
234 axiscode == (sAxisX & sAxis1)) {
235 return sAxisX;
236 } else if (axiscode == (sAxisY & sAxis0) ||
237 axiscode == (sAxisY & sAxis1)) {
238 return sAxisY;
239 } else if (axiscode == (sAxisZ & sAxis0) ||
240 axiscode == (sAxisZ & sAxis1)) {
241 return sAxisZ;
242 } else if (axiscode == (sAxisRho & sAxis0) ||
243 axiscode == (sAxisRho & sAxis1)) {
244 return sAxisRho;
245 } else if (axiscode == (sAxisPhi & sAxis0) ||
246 axiscode == (sAxisPhi & sAxis1)) {
247 return sAxisPhi;
248 } else {
249 std::ostringstream message;
250 message << "Configuration not supported." << G4endl
251 << " areacode = " << areacode;
252 G4Exception("G4VTwistSurface::GetAxisType()","GeomSolids0001",
253 FatalException, message);
254 }
255 return 1;
256}
257
258//=====================================================================
259//* ComputeGlobalPoint ------------------------------------------------
260
261inline
262G4ThreeVector G4VTwistSurface::ComputeGlobalPoint(const G4ThreeVector& lp) const
263{
264 return fRot * G4ThreeVector(lp) + fTrans;
265}
266
267//=====================================================================
268//* ComputeGlobalPoint ------------------------------------------------
269
270inline
271G4ThreeVector G4VTwistSurface::ComputeLocalPoint(const G4ThreeVector& gp) const
272{
273 return fRot.inverse() * ( G4ThreeVector(gp) - fTrans ) ;
274}
275
276//=====================================================================
277//* ComputeGlobalDirection --------------------------------------------
278
279inline G4ThreeVector
280G4VTwistSurface::ComputeGlobalDirection(const G4ThreeVector& lp) const
281{
282 return fRot * G4ThreeVector(lp);
283}
284
285//=====================================================================
286//* ComputeLocalDirection ---------------------------------------------
287
288inline G4ThreeVector
289G4VTwistSurface::ComputeLocalDirection(const G4ThreeVector& gp) const
290{
291 return fRot.inverse() * G4ThreeVector(gp);
292}
293
294//=====================================================================
295//* SetNeighbours -----------------------------------------------------
296
297inline void
298G4VTwistSurface::SetNeighbours(G4VTwistSurface* ax0min, G4VTwistSurface* ax1min,
299 G4VTwistSurface* ax0max, G4VTwistSurface* ax1max)
300{
301 fNeighbours[0] = ax0min;
302 fNeighbours[1] = ax1min;
303 fNeighbours[2] = ax0max;
304 fNeighbours[3] = ax1max;
305}
306
307//=====================================================================
308//* GetNeighbours -----------------------------------------------------
309
310inline G4int
311G4VTwistSurface::GetNeighbours(G4int areacode, G4VTwistSurface** surfaces)
312{
313
314 G4int sAxis0Min = sAxis0 & sAxisMin ;
315 G4int sAxis1Min = sAxis1 & sAxisMin ;
316 G4int sAxis0Max = sAxis0 & sAxisMax ;
317 G4int sAxis1Max = sAxis1 & sAxisMax ;
318
319 G4int i = 0;
320
321 if ( (areacode & sAxis0Min ) == sAxis0Min )
322 {
323 surfaces[i] = fNeighbours[0] ;
324 ++i ;
325 }
326
327 if ( ( areacode & sAxis1Min ) == sAxis1Min )
328 {
329 surfaces[i] = fNeighbours[1] ;
330 ++i ;
331 if ( i == 2 ) return i ;
332 }
333
334 if ( ( areacode & sAxis0Max ) == sAxis0Max )
335 {
336 surfaces[i] = fNeighbours[2] ;
337 ++i ;
338 if ( i == 2 ) return i ;
339 }
340
341 if ( ( areacode & sAxis1Max ) == sAxis1Max )
342 {
343 surfaces[i] = fNeighbours[3] ;
344 ++i ;
345 if ( i == 2 ) return i ;
346 }
347
348 return i ;
349}
350
351//=====================================================================
352//* GetCorner ---------------------------------------------------------
353
354inline
355G4ThreeVector G4VTwistSurface::GetCorner(G4int areacode) const
356{
357 if (!(areacode & sCorner))
358 {
359 std::ostringstream message;
360 message << "Area code must represent corner." << G4endl
361 << " areacode = " << areacode;
362 G4Exception("G4VTwistSurface::GetCorner()","GeomSolids0002",
363 FatalException, message);
364 }
365
366 if ((areacode & sC0Min1Min) == sC0Min1Min) {
367 return fCorners[0];
368 } else if ((areacode & sC0Max1Min) == sC0Max1Min) {
369 return fCorners[1];
370 } else if ((areacode & sC0Max1Max) == sC0Max1Max) {
371 return fCorners[2];
372 } else if ((areacode & sC0Min1Max) == sC0Min1Max) {
373 return fCorners[3];
374 } else {
375 std::ostringstream message;
376 message << "Configuration not supported." << G4endl
377 << " areacode = " << areacode;
378 G4Exception("G4VTwistSurface::GetCorner()", "GeomSolids0001",
379 FatalException, message);
380 }
381 return fCorners[0];
382}