source: trunk/source/geometry/solids/specific/include/G4VTwistSurface.icc @ 1315

Last change on this file since 1315 was 1228, checked in by garnier, 14 years ago

update geant4.9.3 tag

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