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 inline definitions file 00031 // 00032 // G4Line.icc 00033 // 00034 // Implementation of inline methods of G4Line 00035 // -------------------------------------------------------------------- 00036 00037 inline 00038 G4double G4Line::GetPMax() const 00039 { 00040 return -1; 00041 } 00042 00043 inline 00044 G4Point3D G4Line::GetPoint(G4double param) const 00045 { 00046 return G4Point3D( pnt+param*dir ); 00047 } 00048 00049 inline 00050 G4double G4Line::GetPPoint(const G4Point3D& pt) const 00051 { 00052 return (pt-pnt)*invDir; 00053 } 00054 00056 00057 inline 00058 void G4Line::Init(const G4Point3D& pnt0, const G4Vector3D& dir0) 00059 { 00060 pnt= pnt0; 00061 dir= dir0; 00062 invDir= dir*(1/dir.mag2()); 00063 v= dir.unit(); 00064 } 00065 00066 inline 00067 G4Point3D G4Line::GetPnt() const 00068 { 00069 return pnt; 00070 } 00071 00072 inline 00073 G4Vector3D G4Line::GetDir() const 00074 { 00075 return dir; 00076 } 00077 00079 00080 inline 00081 void G4Line::InitBounded() 00082 { 00083 bBox.Init(GetStart(), GetEnd()); 00084 } 00085 00087 00088 #include "G4CurveRayIntersection.hh" 00089 00090 /* 00091 inline 00092 void G4Line::IntersectRay2D(const G4Ray& ray, 00093 G4CurveRayIntersection& is) 00094 { 00095 is.Init(*this, ray); 00096 G4CurveRayIntersection isTmp(*this, ray); 00097 00098 const G4Point3D& s= ray.GetStart(); 00099 const G4Vector3D& d= ray.GetDir(); 00100 00101 G4double num= (s.x()-pnt.x())*v.y()-(s.y()-pnt.y())*v.x(); 00102 G4double denom= d.y()*v.x()-d.x()*v.y(); 00103 00104 if (denom < kAngTolerance) { 00105 if (num < kCarTolerance) { 00106 00107 // identical lines 00108 isTmp.ResetDistance(kCarTolerance); 00109 is.Update(isTmp); 00110 isTmp.Reset(GetPStart(), GetStart()); 00111 is.UpdateWithPointOnCurve(isTmp); 00112 isTmp.Reset(GetPEnd(), GetEnd()); 00113 is.UpdateWithPointOnCurve(isTmp); 00114 00115 } else { 00116 00117 // parallel lines 00118 00119 } 00120 } else { 00121 00122 // properly intersecting lines 00123 isTmp.ResetDistance(num/denom); 00124 is.Update(isTmp); 00125 00126 } 00127 } 00128 */ 00129 00130 inline 00131 G4int G4Line::IntersectRay2D(const G4Ray& ray) 00132 { 00133 const G4Point3D& st= ray.GetStart(); 00134 const G4Vector3D& d= ray.GetDir(); 00135 00136 G4double num1= (pnt.x()-st.x())*d.y()-(pnt.y()-st.y())*d.x(); 00137 G4double num2= (pnt.x()-st.x())*dir.y()-(pnt.y()-st.y())*dir.x(); 00138 G4double denom= d.x()*dir.y()-d.y()*dir.x(); 00139 00140 G4int nbinter = 0; 00141 00142 if (std::fabs(denom) < kCarTolerance) 00143 { 00144 if (std::fabs(num1) < kCarTolerance) 00145 { 00146 // identical lines 00147 } 00148 else 00149 { 00150 // parallel lines 00151 } 00152 } 00153 else 00154 { 00155 // properly intersecting lines 00156 G4double u = num1/denom; 00157 G4double t = num2/denom; 00158 00159 if( (u > -kCarTolerance/2) && (u < kCarTolerance/2) ) 00160 u = 0; 00161 00162 if( (t > -kCarTolerance/2) && (t < kCarTolerance/2) ) 00163 t = 0; 00164 00165 // test the validity of the results 00166 if(t>=0 && u>=0 && u<=1) 00167 { 00168 // test if the point is on the line 00169 if( t==0 || u==0 ) 00170 return 999; 00171 else 00172 nbinter = 1; 00173 } 00174 } 00175 00176 return nbinter; 00177 }