178 lines
4.5 KiB
Plaintext
178 lines
4.5 KiB
Plaintext
//
|
|
// ********************************************************************
|
|
// * License and Disclaimer *
|
|
// * *
|
|
// * The Geant4 software is copyright of the Copyright Holders of *
|
|
// * the Geant4 Collaboration. It is provided under the terms and *
|
|
// * conditions of the Geant4 Software License, included in the file *
|
|
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
|
// * include a list of copyright holders. *
|
|
// * *
|
|
// * 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. Please see the license in the file LICENSE and URL above *
|
|
// * for the full disclaimer and the limitation of liability. *
|
|
// * *
|
|
// * This code implementation is the result of the scientific and *
|
|
// * technical work of the GEANT4 collaboration. *
|
|
// * By using, copying, modifying or distributing the software (or *
|
|
// * any work based on the software) you agree to acknowledge its *
|
|
// * use in resulting scientific publications, and indicate your *
|
|
// * acceptance of all terms of the Geant4 Software license. *
|
|
// ********************************************************************
|
|
//
|
|
//
|
|
// $Id$
|
|
//
|
|
// --------------------------------------------------------------------
|
|
// GEANT 4 inline definitions file
|
|
//
|
|
// G4Line.icc
|
|
//
|
|
// Implementation of inline methods of G4Line
|
|
// --------------------------------------------------------------------
|
|
|
|
inline
|
|
G4double G4Line::GetPMax() const
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
inline
|
|
G4Point3D G4Line::GetPoint(G4double param) const
|
|
{
|
|
return G4Point3D( pnt+param*dir );
|
|
}
|
|
|
|
inline
|
|
G4double G4Line::GetPPoint(const G4Point3D& pt) const
|
|
{
|
|
return (pt-pnt)*invDir;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
inline
|
|
void G4Line::Init(const G4Point3D& pnt0, const G4Vector3D& dir0)
|
|
{
|
|
pnt= pnt0;
|
|
dir= dir0;
|
|
invDir= dir*(1/dir.mag2());
|
|
v= dir.unit();
|
|
}
|
|
|
|
inline
|
|
G4Point3D G4Line::GetPnt() const
|
|
{
|
|
return pnt;
|
|
}
|
|
|
|
inline
|
|
G4Vector3D G4Line::GetDir() const
|
|
{
|
|
return dir;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
inline
|
|
void G4Line::InitBounded()
|
|
{
|
|
bBox.Init(GetStart(), GetEnd());
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "G4CurveRayIntersection.hh"
|
|
|
|
/*
|
|
inline
|
|
void G4Line::IntersectRay2D(const G4Ray& ray,
|
|
G4CurveRayIntersection& is)
|
|
{
|
|
is.Init(*this, ray);
|
|
G4CurveRayIntersection isTmp(*this, ray);
|
|
|
|
const G4Point3D& s= ray.GetStart();
|
|
const G4Vector3D& d= ray.GetDir();
|
|
|
|
G4double num= (s.x()-pnt.x())*v.y()-(s.y()-pnt.y())*v.x();
|
|
G4double denom= d.y()*v.x()-d.x()*v.y();
|
|
|
|
if (denom < kAngTolerance) {
|
|
if (num < kCarTolerance) {
|
|
|
|
// identical lines
|
|
isTmp.ResetDistance(kCarTolerance);
|
|
is.Update(isTmp);
|
|
isTmp.Reset(GetPStart(), GetStart());
|
|
is.UpdateWithPointOnCurve(isTmp);
|
|
isTmp.Reset(GetPEnd(), GetEnd());
|
|
is.UpdateWithPointOnCurve(isTmp);
|
|
|
|
} else {
|
|
|
|
// parallel lines
|
|
|
|
}
|
|
} else {
|
|
|
|
// properly intersecting lines
|
|
isTmp.ResetDistance(num/denom);
|
|
is.Update(isTmp);
|
|
|
|
}
|
|
}
|
|
*/
|
|
|
|
inline
|
|
G4int G4Line::IntersectRay2D(const G4Ray& ray)
|
|
{
|
|
const G4Point3D& st= ray.GetStart();
|
|
const G4Vector3D& d= ray.GetDir();
|
|
|
|
G4double num1= (pnt.x()-st.x())*d.y()-(pnt.y()-st.y())*d.x();
|
|
G4double num2= (pnt.x()-st.x())*dir.y()-(pnt.y()-st.y())*dir.x();
|
|
G4double denom= d.x()*dir.y()-d.y()*dir.x();
|
|
|
|
G4int nbinter = 0;
|
|
|
|
if (std::fabs(denom) < kCarTolerance)
|
|
{
|
|
if (std::fabs(num1) < kCarTolerance)
|
|
{
|
|
// identical lines
|
|
}
|
|
else
|
|
{
|
|
// parallel lines
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// properly intersecting lines
|
|
G4double u = num1/denom;
|
|
G4double t = num2/denom;
|
|
|
|
if( (u > -kCarTolerance/2) && (u < kCarTolerance/2) )
|
|
u = 0;
|
|
|
|
if( (t > -kCarTolerance/2) && (t < kCarTolerance/2) )
|
|
t = 0;
|
|
|
|
// test the validity of the results
|
|
if(t>=0 && u>=0 && u<=1)
|
|
{
|
|
// test if the point is on the line
|
|
if( t==0 || u==0 )
|
|
return 999;
|
|
else
|
|
nbinter = 1;
|
|
}
|
|
}
|
|
|
|
return nbinter;
|
|
}
|