G4VTwistSurface.icc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4VTwistSurface.icc 67011 2013-01-29 16:17:41Z gcosmo $
00028 //
00029 // 
00030 // --------------------------------------------------------------------
00031 // G4VTwistSurface class inline methods
00032 //
00033 // Author: 
00034 //   01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp)
00035 //
00036 // History:
00037 //   13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
00038 //                 from original version in Jupiter-2.5.02 application.
00039 // --------------------------------------------------------------------
00040 
00041 //=====================================================================
00042 //* DistanceToPlaneWithV ----------------------------------------------
00043 
00044 inline
00045 G4double G4VTwistSurface::DistanceToPlaneWithV(const G4ThreeVector &p,
00046                                           const G4ThreeVector &v,
00047                                           const G4ThreeVector &x0,
00048                                           const G4ThreeVector &n0,
00049                                                 G4ThreeVector &xx)
00050 {
00051    G4double q = n0 * v;
00052    G4double t = kInfinity;
00053    if (q) { t = (n0 * (x0 - p)) / q; }
00054    xx = p + t * v;
00055    return t;
00056 }
00057 
00058 //=====================================================================
00059 //* DistanceToPlane ---------------------------------------------------
00060 
00061 inline
00062 G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector &p,
00063                                      const G4ThreeVector &x0,
00064                                      const G4ThreeVector &n0,
00065                                            G4ThreeVector &xx)
00066 {
00067    // DistanceToPlane :
00068    // Calculate distance to plane in local coordinate,
00069    // then return distance and global intersection points.
00070    //
00071    // p          - location of flying particle   
00072    // x0         - reference point of surface
00073    // xx         - a foot of perpendicular line from p to the plane 
00074    // t          - distance from xx to p
00075    // n          - a unit normal of this plane from plane to p. 
00076    //
00077    // equation of plane:
00078    //      n*(x - x0) = 0;
00079    //
00080    // vector to xx:
00081    //      xx = p - t*n
00082    //
00083    //         where
00084    //         t = n * (p - x0) / std::fabs(n)
00085    //
00086    G4double t;
00087    G4ThreeVector n = n0.unit();
00088    t = n * (p - x0);
00089    xx = p - t * n;
00090    return t;
00091 }
00092 
00093 //=====================================================================
00094 //* DistanceToPlane ---------------------------------------------------
00095 
00096 inline
00097 G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector &p,
00098                                      const G4ThreeVector &x0,
00099                                      const G4ThreeVector &t1,
00100                                      const G4ThreeVector &t2,
00101                                            G4ThreeVector &xx,
00102                                            G4ThreeVector &n)
00103 {
00104    // DistanceToPlane :
00105    // Calculate distance to plane in local coordinate,
00106    // then return distance and global intersection points.
00107    // t1         - 1st. vector lying on the plane 
00108    // t2         - 2nd. vector lying on the plane
00109 
00110    n = (t1.cross(t2)).unit();
00111    return DistanceToPlane(p, x0, n, xx); 
00112 }
00113 
00114 //=====================================================================
00115 //* DistanceToLine ----------------------------------------------------
00116 
00117 inline
00118 G4double G4VTwistSurface::DistanceToLine(const G4ThreeVector &p,
00119                                     const G4ThreeVector &x0,
00120                                     const G4ThreeVector &d,
00121                                           G4ThreeVector &xx)
00122 {
00123    // DistanceToLine :
00124    // Calculate distance to line,
00125    // then return distance and global intersection points.
00126    //
00127    // p          - location of flying particle   
00128    // x0         - reference point of line
00129    // d          - direction vector of line
00130    // xx         - a foot of perpendicular line from p to the plane 
00131    // t          - distance from xx to p
00132    //
00133    // Equation
00134    //
00135    //    distance^2 = |(xx - p)|^2
00136    //    with
00137    //       xx = x0 + t*d
00138    //
00139    //   (d/dt)distance^2 = (d/dt)|((x0 + t*d) - p)|^2
00140    //                    = 2*t*|d|^2 + 2*d*(x0 - p)
00141    //                    = 0  // smallest distance
00142    //   then
00143    //      t = - d*(x0 - p) / |d|^2
00144    //
00145 
00146    G4double t;
00147    G4ThreeVector dir = d.unit();
00148    t  = - dir * (x0 - p);      // |dir|^2 = 1.
00149    xx = x0 + t * dir;
00150    
00151    G4ThreeVector dist = xx - p;
00152    return dist.mag();
00153 }
00154 
00155 //=====================================================================
00156 //* IsAxis0 -----------------------------------------------------------
00157 
00158 inline
00159 G4bool G4VTwistSurface::IsAxis0(G4int areacode) const 
00160 {
00161    if (areacode & sAxis0) return true;
00162    return false;
00163 }
00164 
00165 //=====================================================================
00166 //* IsAxis1 -----------------------------------------------------------
00167 
00168 inline
00169 G4bool G4VTwistSurface::IsAxis1(G4int areacode) const 
00170 {
00171    if (areacode & sAxis1) return true;
00172    return false;
00173 }
00174 
00175 //=====================================================================
00176 //* IsOutside ---------------------------------------------------------
00177 
00178 inline
00179 G4bool G4VTwistSurface::IsOutside(G4int areacode) const 
00180 {
00181    if (areacode & sInside) return false;
00182    return true;
00183 }
00184 
00185 //=====================================================================
00186 //* IsInside ----------------------------------------------------------
00187 
00188 inline
00189 G4bool G4VTwistSurface::IsInside(G4int areacode, G4bool testbitmode) const 
00190 {
00191    if (areacode & sInside) {
00192       if (testbitmode) {
00193          return true;
00194       } else {
00195        if (!((areacode & sBoundary) || (areacode & sCorner))) return true;
00196       }
00197    }
00198    return false;
00199 }
00200 
00201 //=====================================================================
00202 //* IsBoundary --------------------------------------------------------
00203 
00204 inline
00205 G4bool G4VTwistSurface::IsBoundary(G4int areacode, G4bool testbitmode) const 
00206 {
00207    if ((areacode & sBoundary) == sBoundary) {
00208       if (testbitmode) {
00209          return true; 
00210       } else {
00211          if ((areacode & sInside) == sInside) return true;
00212       }
00213    }
00214    return false;
00215 }
00216 
00217 //=====================================================================
00218 //* IsCorner ----------------------------------------------------------
00219 
00220 inline
00221 G4bool G4VTwistSurface::IsCorner(G4int areacode, G4bool testbitmode) const 
00222 {
00223    if ((areacode & sCorner) == sCorner) {
00224       if (testbitmode) {
00225          return true;
00226       } else {
00227          if ((areacode & sInside) == sInside) return true;
00228       }
00229    }
00230    return false;
00231 }
00232 
00233 //=====================================================================
00234 //* GetAxisType -------------------------------------------------------
00235 
00236 inline
00237 G4int G4VTwistSurface::GetAxisType(G4int areacode, G4int whichaxis) const
00238 {
00239    G4int axiscode = areacode & sAxisMask & whichaxis;
00240    
00241    if (axiscode == (sAxisX & sAxis0) ||
00242        axiscode == (sAxisX & sAxis1)) {
00243       return sAxisX;
00244    } else if (axiscode == (sAxisY & sAxis0) ||
00245               axiscode == (sAxisY & sAxis1)) {
00246       return sAxisY;
00247    } else if (axiscode == (sAxisZ & sAxis0) ||
00248               axiscode == (sAxisZ & sAxis1)) {
00249       return sAxisZ;
00250    } else if (axiscode == (sAxisRho & sAxis0) ||
00251               axiscode == (sAxisRho & sAxis1)) {
00252       return sAxisRho;
00253    } else if (axiscode == (sAxisPhi & sAxis0) ||
00254               axiscode == (sAxisPhi & sAxis1)) {
00255       return sAxisPhi;
00256    } else {
00257       std::ostringstream message;
00258       message << "Configuration not supported." << G4endl
00259               << "        areacode = " << areacode;
00260       G4Exception("G4VTwistSurface::GetAxisType()","GeomSolids0001",
00261                   FatalException, message);
00262    }
00263    return 1;
00264 }
00265 
00266 //=====================================================================
00267 //* ComputeGlobalPoint ------------------------------------------------
00268 
00269 inline
00270 G4ThreeVector G4VTwistSurface::ComputeGlobalPoint(const G4ThreeVector &lp) const
00271 {
00272    return fRot * G4ThreeVector(lp) + fTrans;
00273 }
00274 
00275 //=====================================================================
00276 //* ComputeGlobalPoint ------------------------------------------------
00277 
00278 inline
00279 G4ThreeVector G4VTwistSurface::ComputeLocalPoint(const G4ThreeVector &gp) const
00280 {
00281    return fRot.inverse() * ( G4ThreeVector(gp) - fTrans ) ;
00282 }
00283 
00284 //=====================================================================
00285 //* ComputeGlobalDirection --------------------------------------------
00286 
00287 inline
00288 G4ThreeVector G4VTwistSurface::ComputeGlobalDirection(const G4ThreeVector &lp) const
00289 {
00290    return fRot * G4ThreeVector(lp); 
00291 }
00292 
00293 //=====================================================================
00294 //* ComputeLocalDirection ---------------------------------------------
00295 
00296 inline
00297 G4ThreeVector G4VTwistSurface::ComputeLocalDirection(const G4ThreeVector &gp) const
00298 {
00299    return fRot.inverse() * G4ThreeVector(gp);
00300 }
00301 
00302 //=====================================================================
00303 //* SetNeighbours -----------------------------------------------------
00304 
00305 inline
00306 void G4VTwistSurface::SetNeighbours(G4VTwistSurface* axis0min, G4VTwistSurface* axis1min, 
00307                                G4VTwistSurface* axis0max, G4VTwistSurface* axis1max)
00308 {
00309    fNeighbours[0] = axis0min;
00310    fNeighbours[1] = axis1min;
00311    fNeighbours[2] = axis0max;
00312    fNeighbours[3] = axis1max;
00313 }
00314 
00315 //=====================================================================
00316 //* GetNeighbours -----------------------------------------------------
00317 
00318 inline
00319 G4int G4VTwistSurface::GetNeighbours(G4int areacode, G4VTwistSurface** surfaces) 
00320 {
00321 
00322   int sAxis0Min = sAxis0 & sAxisMin ;
00323   int sAxis1Min = sAxis1 & sAxisMin ;
00324   int sAxis0Max = sAxis0 & sAxisMax ;
00325   int sAxis1Max = sAxis1 & sAxisMax ;
00326 
00327    G4int i = 0;
00328    
00329   if ( (areacode & sAxis0Min ) == sAxis0Min ) {
00330     surfaces[i] = fNeighbours[0] ;
00331     i++ ;
00332   }
00333   
00334   if ( ( areacode & sAxis1Min ) == sAxis1Min ) {
00335      surfaces[i] = fNeighbours[1] ;
00336    i++ ;
00337     if ( i == 2 ) return i ;
00338   }
00339 
00340   if ( ( areacode & sAxis0Max ) == sAxis0Max ) {
00341     surfaces[i] = fNeighbours[2] ;
00342     i++ ;
00343     if ( i == 2 ) return i ;
00344   }
00345   
00346   if ( ( areacode & sAxis1Max ) == sAxis1Max ) {
00347     surfaces[i] = fNeighbours[3] ;
00348     i++ ;
00349     if ( i == 2 ) return i ;
00350   }
00351     
00352   return i ;
00353 }
00354 
00355 //=====================================================================
00356 //* GetCorner ---------------------------------------------------------
00357 
00358 inline
00359 G4ThreeVector G4VTwistSurface::GetCorner(G4int areacode) const
00360 {
00361    if (!(areacode & sCorner)){
00362       std::ostringstream message;
00363       message << "Area code must represent corner." << G4endl
00364               << "        areacode = " << areacode;
00365       G4Exception("G4VTwistSurface::GetCorner()","GeomSolids0002",
00366                   FatalException, message);
00367    }
00368    
00369    if ((areacode & sC0Min1Min) == sC0Min1Min) { 
00370       return fCorners[0];
00371    } else if ((areacode & sC0Max1Min) == sC0Max1Min) { 
00372       return fCorners[1];
00373    } else if ((areacode & sC0Max1Max) == sC0Max1Max) {
00374       return fCorners[2];
00375    } else if ((areacode & sC0Min1Max) == sC0Min1Max) { 
00376       return fCorners[3];
00377    } else {
00378       std::ostringstream message;
00379       message << "Configuration not supported." << G4endl
00380               << "        areacode = " << areacode;
00381       G4Exception("G4VTwistSurface::GetCorner()", "GeomSolids0001",
00382                   FatalException, message);
00383    }
00384    return fCorners[0];
00385 }

Generated on Mon May 27 17:50:23 2013 for Geant4 by  doxygen 1.4.7