Geant4 Cross Reference |
>> 1 // This code implementation is the intellectual property of >> 2 // the GEANT4 collaboration. 1 // 3 // 2 // ******************************************* << 4 // By copying, distributing or modifying the Program (or any work 3 // * License and Disclaimer << 5 // based on the Program) you indicate your acceptance of this statement, 4 // * << 6 // and all its terms. 5 // * The Geant4 software is copyright of th << 6 // * the Geant4 Collaboration. It is provided << 7 // * conditions of the Geant4 Software License << 8 // * LICENSE and available at http://cern.ch/ << 9 // * include a list of copyright holders. << 10 // * << 11 // * Neither the authors of this software syst << 12 // * institutes,nor the agencies providing fin << 13 // * work make any representation or warran << 14 // * regarding this software system or assum << 15 // * use. Please see the license in the file << 16 // * for the full disclaimer and the limitatio << 17 // * << 18 // * This code implementation is the result << 19 // * technical work of the GEANT4 collaboratio << 20 // * By using, copying, modifying or distri << 21 // * any work based on the software) you ag << 22 // * use in resulting scientific publicati << 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* << 25 // 7 // 26 // G4LineSection implementation << 8 // $Id: G4LineSection.cc,v 1.1.10.1 1999/12/07 20:48:05 gunter Exp $ >> 9 // GEANT4 tag $Name: geant4-01-00 $ 27 // 10 // 28 // Created: J.Apostolakis, 1999 << 11 // typedef double G4double; 29 // ------------------------------------------- << 30 << 31 #include "G4LineSection.hh" 12 #include "G4LineSection.hh" 32 13 33 G4LineSection::G4LineSection( const G4ThreeVec 14 G4LineSection::G4LineSection( const G4ThreeVector& PntA, 34 const G4ThreeVec << 15 const G4ThreeVector& PntB ) 35 : EndpointA(PntA), VecAtoB(PntB-PntA) << 36 { 16 { 37 fABdistanceSq = VecAtoB.mag2(); << 17 EndpointA= PntA; >> 18 VecAtoB=PntB-PntA; >> 19 >> 20 inverse_square_distAB=1.0 / VecAtoB.mag2(); 38 } 21 } 39 22 40 G4double G4LineSection::Dist( const G4ThreeVec << 23 G4double G4LineSection::Dist( G4ThreeVector OtherPnt ) const 41 { 24 { 42 G4double dist_sq; 25 G4double dist_sq; 43 G4ThreeVector VecAZ; 26 G4ThreeVector VecAZ; 44 G4double sq_VecAZ, inner_prod, unit_projecti 27 G4double sq_VecAZ, inner_prod, unit_projection ; 45 28 46 VecAZ= OtherPnt - EndpointA; 29 VecAZ= OtherPnt - EndpointA; 47 sq_VecAZ = VecAZ.mag2(); 30 sq_VecAZ = VecAZ.mag2(); 48 31 49 inner_prod= VecAtoB.dot( VecAZ ); 32 inner_prod= VecAtoB.dot( VecAZ ); 50 33 51 // Determine Projection(AZ on AB) / Length 34 // Determine Projection(AZ on AB) / Length(AB) 52 // 35 // 53 if( fABdistanceSq != 0.0 ) << 36 unit_projection= inner_prod * InvsqDistAB(); 54 { << 37 55 // unit_projection= inner_prod * InvsqDis << 38 if( (0. <= unit_projection ) && (unit_projection <= 1.0 ) ) 56 unit_projection = inner_prod/fABdistanceSq << 39 dist_sq= sq_VecAZ - unit_projection * inner_prod; 57 << 40 else{ 58 if( (0. <= unit_projection ) && (unit_proj << 59 { << 60 dist_sq= sq_VecAZ - unit_projection * i << 61 } << 62 else << 63 { << 64 // The perpendicular from the point to t 41 // The perpendicular from the point to the line AB meets the line 65 // in a point outside the line segment! 42 // in a point outside the line segment! 66 << 43 // 67 if( unit_projection < 0. ) // A is the c << 44 if( unit_projection < 0. ) { 68 { << 45 // A is the closest point 69 dist_sq= sq_VecAZ; 46 dist_sq= sq_VecAZ; 70 } << 47 }else{ 71 else // B is the c << 48 // B is the closest point 72 { << 49 G4ThreeVector EndpointB = EndpointA + VecAtoB; 73 G4ThreeVector EndpointB = EndpointA << 74 G4ThreeVector VecBZ = OtherPnt - 50 G4ThreeVector VecBZ = OtherPnt - EndpointB; 75 dist_sq = VecBZ.mag2(); 51 dist_sq = VecBZ.mag2(); 76 } << 52 } 77 } << 78 } << 79 else << 80 { << 81 dist_sq = (OtherPnt - EndpointA).mag2() ; << 82 } << 83 if( dist_sq < 0.0 ) << 84 { << 85 dist_sq = 0.0 ; << 86 } 53 } 87 54 88 return std::sqrt(dist_sq) ; << 55 return sqrt(dist_sq); 89 } 56 } >> 57 >> 58 G4double G4LineSection::Distline( const G4ThreeVector& OtherPnt, >> 59 const G4ThreeVector& LinePntA, >> 60 const G4ThreeVector& LinePntB ) >> 61 { >> 62 G4LineSection LineAB( LinePntA, LinePntB ); // Line from A to B >> 63 >> 64 return LineAB.Dist( OtherPnt ); >> 65 } >> 66 >> 67 90 68