G4Hyperbola.cc

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$
00028 //
00029 // ----------------------------------------------------------------------
00030 // GEANT 4 class source file
00031 //
00032 // G4Hyperbola.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4Hyperbola.hh"
00037 #include "G4PhysicalConstants.hh"
00038 #include "G4CurvePoint.hh"
00039 #include "G4GeometryTolerance.hh"
00040 
00041 G4Hyperbola::G4Hyperbola()
00042   : semiAxis(0.), semiImagAxis(0.), ratioAxisImagAxis(0.), forTangent(0.)
00043 {
00044 }
00045 
00046 G4Hyperbola::~G4Hyperbola()
00047 {
00048 }
00049 
00050 G4Hyperbola::G4Hyperbola(const G4Hyperbola& right)
00051   : G4Conic(), Focus1(right.Focus1), Focus2(right.Focus2),
00052     ProjFocus1(right.ProjFocus1), ProjFocus2(right.ProjFocus2),
00053     semiAxis(right.semiAxis), semiImagAxis(right.semiImagAxis),
00054     ratioAxisImagAxis(right.ratioAxisImagAxis),
00055     toUnitHyperbola(right.toUnitHyperbola), forTangent(right.forTangent)
00056 {
00057   pShift    = right.pShift;
00058   position  = right.position;
00059   bBox      = right.bBox;
00060   start     = right.start;
00061   end       = right.end;
00062   pStart    = right.pStart;
00063   pEnd      = right.pEnd;
00064   pRange    = right.pRange;
00065   bounded   = right.bounded;
00066   sameSense = right.sameSense;
00067 }
00068 
00069 G4Hyperbola& G4Hyperbola::operator=(const G4Hyperbola& right)
00070 {
00071   if (&right == this) return *this;
00072 
00073   Focus1 = right.Focus1;
00074   Focus2 = right.Focus2;
00075   ProjFocus1   = right.ProjFocus1;
00076   ProjFocus2   = right.ProjFocus2;
00077   semiAxis     = right.semiAxis;
00078   semiImagAxis = right.semiImagAxis;
00079   ratioAxisImagAxis = right.ratioAxisImagAxis;
00080   toUnitHyperbola   = right.toUnitHyperbola;
00081   forTangent        = right.forTangent;
00082   pShift    = right.pShift;
00083   position  = right.position;
00084   bBox      = right.bBox;
00085   start     = right.start;
00086   end       = right.end;
00087   pStart    = right.pStart;
00088   pEnd      = right.pEnd;
00089   pRange    = right.pRange;
00090   bounded   = right.bounded;
00091   sameSense = right.sameSense;
00092 
00093   return *this;
00094 }
00095 
00096 G4Curve* G4Hyperbola::Project(const G4Transform3D& tr)
00097 {
00098   G4Exception("G4Hyperbola::Project()", "GeomSolids0001",
00099               FatalException, "Sorry, not yet implemented.");
00100 
00101   G4Point3D newLocation= tr*position.GetLocation();
00102   newLocation.setZ(0);
00103   G4double axisZ= (tr*position.GetPZ()).unit().z();
00104 
00105   if (std::abs(axisZ)<G4GeometryTolerance::GetInstance()->GetAngularTolerance()) 
00106   {
00107     return 0;
00108   }
00109 
00110   G4Vector3D newAxis(0, 0, axisZ>0? +1: -1);
00111 
00112   // get the parameter of an endpoint of an axis
00113   // (this is a point the distance of which from the center is extreme)
00114   G4Vector3D xPrime = tr*position.GetPX();
00115   xPrime.setZ(0);
00116   
00117   G4Vector3D yPrime = tr*position.GetPY();
00118   yPrime.setZ(0);
00119   
00120   G4Vector3D a = G4Vector3D( semiAxis*xPrime );
00121   G4Vector3D b = G4Vector3D( semiImagAxis*yPrime );
00122 
00123   G4double xval = -2*a*b/(a.mag2()+b.mag2());
00124   
00125   G4double u= (0.5*std::log((1+xval)/(1-xval)))/2;  // atanh(xval)/2
00126 
00127   // get the coordinate axis directions and the semiaxis lengths
00128   G4Vector3D sAxis= G4Vector3D( a*std::cosh(u)+b*std::sinh(u) );
00129   
00131   G4Vector3D sImagAxis= G4Vector3D( a*std::cosh(u+pi/2)+b*std::sinh(u+pi/2) );
00132   
00134   G4double   newSemiAxis     = sAxis.mag();
00135   G4double   newSemiImagAxis = sImagAxis.mag();
00136   G4Vector3D newRefDirection = sAxis;
00137 
00138   // create the new hyperbola
00139   G4Axis2Placement3D newPosition;
00140   newPosition.Init(newRefDirection, newAxis, newLocation);
00141 
00142   G4Hyperbola* r= new G4Hyperbola;
00143   r->Init(newPosition, newSemiAxis, newSemiImagAxis);
00144 
00145   // introduce the shift in the parametrization
00146   // maybe the Sign must be changed?
00147   r->SetPShift(u);
00148   
00149   // set the bounds when necessary
00150   if (IsBounded()) 
00151     r->SetBounds(GetPStart(), GetPEnd());
00152   
00153   return r;
00154 }
00155 
00156 
00157 void G4Hyperbola::InitBounded()
00158 {
00159   // the bbox must include the start and endpoints as well as the
00160   // extreme points if they lie on the curve
00161   bBox.Init(GetStart(), GetEnd());
00162 
00163   // the parameter values
00164   // belonging to the points with an extreme x, y and z coordinate
00165   for (G4int i=0; i<3; i++) 
00166   {
00167     G4double x_i= position.GetPX()(i);
00168     
00169     if (std::abs(x_i) <= 
00170         G4GeometryTolerance::GetInstance()->GetAngularTolerance()) 
00171     {
00172       G4double tanhu= - (semiImagAxis*position.GetPY()(i)) / (semiAxis*x_i);
00173       
00174       if (std::abs(tanhu)<=1) 
00175       {
00176         G4double u= 0.5*std::log((1+tanhu)/(1-tanhu));  // atanh(tanhu)
00177         if (IsPOn(u))
00178           bBox.Extend(GetPoint(u));
00179       }
00180     }
00181   }
00182 }
00183 
00184 G4bool G4Hyperbola::Tangent(G4CurvePoint& cp, G4Vector3D& v)
00185 {
00186   // The tangent is computed from the 3D point representation
00187   // for all conics. An alternaive implementation (based on
00188   // the parametric point) might be worthwhile adding
00189   // for efficiency.
00190   
00191   const G4Axis2Placement3D& pos= *(GetPosition());
00192   G4Point3D p= pos.GetToPlacementCoordinates() * cp.GetPoint();
00193   
00194   v= forTangent*p.y()*pos.GetPX() + p.x()*pos.GetPY();
00195   
00196   return true;
00197 }

Generated on Mon May 27 17:48:32 2013 for Geant4 by  doxygen 1.4.7