[831] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
[850] | 27 | // $Id: G4Line.icc,v 1.10 2008/03/13 14:18:57 gcosmo Exp $ |
---|
[1058] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
[831] | 29 | // |
---|
| 30 | // -------------------------------------------------------------------- |
---|
| 31 | // GEANT 4 inline definitions file |
---|
| 32 | // |
---|
| 33 | // G4Line.icc |
---|
| 34 | // |
---|
| 35 | // Implementation of inline methods of G4Line |
---|
| 36 | // -------------------------------------------------------------------- |
---|
| 37 | |
---|
| 38 | inline |
---|
| 39 | G4double G4Line::GetPMax() const |
---|
| 40 | { |
---|
| 41 | return -1; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | inline |
---|
| 45 | G4Point3D G4Line::GetPoint(G4double param) const |
---|
| 46 | { |
---|
| 47 | return G4Point3D( pnt+param*dir ); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | inline |
---|
| 51 | G4double G4Line::GetPPoint(const G4Point3D& pt) const |
---|
| 52 | { |
---|
| 53 | return (pt-pnt)*invDir; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | //////////////////////////////////////////////////////////////////////////// |
---|
| 57 | |
---|
| 58 | inline |
---|
| 59 | void G4Line::Init(const G4Point3D& pnt0, const G4Vector3D& dir0) |
---|
| 60 | { |
---|
| 61 | pnt= pnt0; |
---|
| 62 | dir= dir0; |
---|
| 63 | invDir= dir*(1/dir.mag2()); |
---|
| 64 | v= dir.unit(); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | inline |
---|
| 68 | G4Point3D G4Line::GetPnt() const |
---|
| 69 | { |
---|
| 70 | return pnt; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | inline |
---|
| 74 | G4Vector3D G4Line::GetDir() const |
---|
| 75 | { |
---|
| 76 | return dir; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /////////////////////////////////////////////////////////////////////////// |
---|
| 80 | |
---|
| 81 | inline |
---|
| 82 | void G4Line::InitBounded() |
---|
| 83 | { |
---|
| 84 | bBox.Init(GetStart(), GetEnd()); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | /////////////////////////////////////////////////////////////////////////// |
---|
| 88 | |
---|
| 89 | #include "G4CurveRayIntersection.hh" |
---|
| 90 | |
---|
| 91 | /* |
---|
| 92 | inline |
---|
| 93 | void G4Line::IntersectRay2D(const G4Ray& ray, |
---|
| 94 | G4CurveRayIntersection& is) |
---|
| 95 | { |
---|
| 96 | is.Init(*this, ray); |
---|
| 97 | G4CurveRayIntersection isTmp(*this, ray); |
---|
| 98 | |
---|
| 99 | const G4Point3D& s= ray.GetStart(); |
---|
| 100 | const G4Vector3D& d= ray.GetDir(); |
---|
| 101 | |
---|
| 102 | G4double num= (s.x()-pnt.x())*v.y()-(s.y()-pnt.y())*v.x(); |
---|
| 103 | G4double denom= d.y()*v.x()-d.x()*v.y(); |
---|
| 104 | |
---|
| 105 | if (denom < kAngTolerance) { |
---|
| 106 | if (num < kCarTolerance) { |
---|
| 107 | |
---|
| 108 | // identical lines |
---|
| 109 | isTmp.ResetDistance(kCarTolerance); |
---|
| 110 | is.Update(isTmp); |
---|
| 111 | isTmp.Reset(GetPStart(), GetStart()); |
---|
| 112 | is.UpdateWithPointOnCurve(isTmp); |
---|
| 113 | isTmp.Reset(GetPEnd(), GetEnd()); |
---|
| 114 | is.UpdateWithPointOnCurve(isTmp); |
---|
| 115 | |
---|
| 116 | } else { |
---|
| 117 | |
---|
| 118 | // parallel lines |
---|
| 119 | |
---|
| 120 | } |
---|
| 121 | } else { |
---|
| 122 | |
---|
| 123 | // properly intersecting lines |
---|
| 124 | isTmp.ResetDistance(num/denom); |
---|
| 125 | is.Update(isTmp); |
---|
| 126 | |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | */ |
---|
| 130 | |
---|
| 131 | inline |
---|
| 132 | G4int G4Line::IntersectRay2D(const G4Ray& ray) |
---|
| 133 | { |
---|
| 134 | const G4Point3D& s= ray.GetStart(); |
---|
| 135 | const G4Vector3D& d= ray.GetDir(); |
---|
| 136 | |
---|
| 137 | G4double num1= (pnt.x()-s.x())*d.y()-(pnt.y()-s.y())*d.x(); |
---|
| 138 | G4double num2= (pnt.x()-s.x())*dir.y()-(pnt.y()-s.y())*dir.x(); |
---|
| 139 | G4double denom= d.x()*dir.y()-d.y()*dir.x(); |
---|
| 140 | |
---|
| 141 | G4int nbinter = 0; |
---|
| 142 | |
---|
| 143 | if (std::fabs(denom) < kCarTolerance) |
---|
| 144 | { |
---|
| 145 | if (std::fabs(num1) < kCarTolerance) |
---|
| 146 | { |
---|
| 147 | // identical lines |
---|
| 148 | } |
---|
| 149 | else |
---|
| 150 | { |
---|
| 151 | // parallel lines |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
| 156 | // properly intersecting lines |
---|
| 157 | G4double u = num1/denom; |
---|
| 158 | G4double t = num2/denom; |
---|
| 159 | |
---|
| 160 | if( (u > -kCarTolerance/2) && (u < kCarTolerance/2) ) |
---|
| 161 | u = 0; |
---|
| 162 | |
---|
| 163 | if( (t > -kCarTolerance/2) && (t < kCarTolerance/2) ) |
---|
| 164 | t = 0; |
---|
| 165 | |
---|
| 166 | // test the validity of the results |
---|
| 167 | if(t>=0 && u>=0 && u<=1) |
---|
| 168 | { |
---|
| 169 | // test if the point is on the line |
---|
| 170 | if( t==0 || u==0 ) |
---|
| 171 | return 999; |
---|
| 172 | else |
---|
| 173 | nbinter = 1; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | return nbinter; |
---|
| 178 | } |
---|