Files
geant4/source/geometry/solids/BREPS/include/G4Hyperbola.icc
T
2016-06-08 16:57:27 +02:00

187 lines
5.1 KiB
Plaintext

//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4Hyperbola.icc,v 1.7 2001/07/11 09:59:35 gunter Exp $
// GEANT4 tag $Name: geant4-05-00 $
//
// --------------------------------------------------------------------
// GEANT 4 inline definitions file
//
// G4Hyperbola.icc
//
// Implementation of inline methods of G4Hyperbola
// --------------------------------------------------------------------
inline
void G4Hyperbola::Init(G4Axis2Placement3D position0,
G4double semiAxis0, G4double semiImagAxis0)
{
position= position0;
semiAxis= semiAxis0;
semiImagAxis= semiImagAxis0;
ratioAxisImagAxis= semiAxis/semiImagAxis;
// needed only for 2D hyperbolas
toUnitHyperbola = G4Scale3D(1/semiAxis, 1/semiImagAxis, 0)
* position.GetToPlacementCoordinates();
forTangent= semiAxis*semiAxis/(semiImagAxis*semiImagAxis);
}
inline
G4double G4Hyperbola::GetSemiAxis() const
{
return semiAxis;
}
inline
G4double G4Hyperbola::GetSemiImagAxis() const
{
return semiImagAxis;
}
//////////////////////////////////////////////////////////////////////////////
inline
G4double G4Hyperbola::GetPMax() const
{
return -1;
}
inline
G4Point3D G4Hyperbola::GetPoint(G4double param) const
{
return G4Point3D( position.GetLocation()
+ semiAxis*cosh(param)*position.GetPX()
+ semiImagAxis*sinh(param)*position.GetPY() );
}
inline
G4double G4Hyperbola::GetPPoint(const G4Point3D& pt) const
{
G4Point3D ptLocal= position.GetToPlacementCoordinates()*pt;
G4double xval= ptLocal.y()/ptLocal.x()*ratioAxisImagAxis;
return 0.5*log((1+xval)/(1-xval)); // atanh(xval)
}
/////////////////////////////////////////////////////////////////////////////
/*
#include "G4CurveRayIntersection.hh"
inline
void G4Hyperbola::IntersectRay2D(const G4Ray& ray,
G4CurveRayIntersection& is)
{
is.Init(*this, ray);
// similar to G4Ellipse::IntersectRay2D
// 2D operations would be faster
G4Point3D s= toUnitHyperbola*ray.GetStart();
G4Vector3D d= toUnitHyperbola*ray.GetDir();
// solve (s+i*t)^2 = 1 for i (the distance)
G4double sd= s.x()*d.x()-s.y()*d.y();
G4double dd= d.x()*d.x()-d.y()*d.y(); // can be 0
G4double ss= s.x()*s.x()-s.y()*s.y();
if (abs(dd) < kCarTolerance*kCarTolerance) {
// coeff of i^2 == 0
G4double i= (1-ss)/(2*sd);
G4CurveRayIntersection isTmp(*this, ray);
isTmp.ResetDistance(i);
is.Update(isTmp);
return;
}
G4double discr= sd*sd-dd*(ss-1);
if (discr >= 0) {
// 2 intersections (maybe 1, but this case is rare)
G4double sqrtdiscr= sqrt(discr);
// find the smallest positive i
G4double i= -sd-sqrtdiscr;
if (i<kCarTolerance) {
i= -sd+sqrtdiscr;
if (i<kCarTolerance) {
return;
}
}
i/= dd;
G4CurveRayIntersection isTmp(*this, ray);
isTmp.ResetDistance(i);
is.Update(isTmp);
}
}
*/
inline
G4int G4Hyperbola::IntersectRay2D(const G4Ray& ray)
{
// NOT VERIFIED
// similar to G4Ellipse::IntersectRay2D
// 2D operations would be faster
G4Point3D s= toUnitHyperbola*ray.GetStart();
G4Vector3D d= toUnitHyperbola*ray.GetDir();
// solve (s+i*t)^2 = 1 for i (the distance)
G4double sd= s.x()*d.x()-s.y()*d.y();
G4double dd= d.x()*d.x()-d.y()*d.y(); // can be 0
G4double ss= s.x()*s.x()-s.y()*s.y();
if (abs(dd) < kCarTolerance*kCarTolerance) {
// coeff of i^2 == 0
return 0;
}
G4int nbinter = 0;
G4double discr= sd*sd-dd*(ss-1);
if (discr >= 0)
{
// 2 intersections (maybe 1, but this case is rare)
G4double sqrtdiscr= sqrt(discr);
// find the smallest positive i
G4double i= -sd-sqrtdiscr;
if (i > kCarTolerance)
nbinter++;
i= -sd+sqrtdiscr;
if (i<kCarTolerance)
nbinter++;
}
return nbinter;
}