#include <G4LineSection.hh>
Public Member Functions | |
G4LineSection (const G4ThreeVector &PntA, const G4ThreeVector &PntB) | |
G4double | Dist (G4ThreeVector OtherPnt) const |
G4double | GetABdistanceSq () const |
Static Public Member Functions | |
static G4double | Distline (const G4ThreeVector &OtherPnt, const G4ThreeVector &LinePntA, const G4ThreeVector &LinePntB) |
Definition at line 47 of file G4LineSection.hh.
G4LineSection::G4LineSection | ( | const G4ThreeVector & | PntA, | |
const G4ThreeVector & | PntB | |||
) |
Definition at line 33 of file G4LineSection.cc.
00035 : EndpointA(PntA), 00036 VecAtoB(PntB-PntA) 00037 { 00038 fABdistanceSq = VecAtoB.mag2() ; 00039 /* 00040 G4double distABsquared = VecAtoB.mag2() ; 00041 if ( distABsquared == 0.0) 00042 { 00043 G4Exception("G4LineSection::G4LineSection()", "GeomField0002", 00044 FatalException, "Equal points in input (line->point) ?") ; 00045 } 00046 else 00047 { 00048 inverse_square_distAB=1.0 / distABsquared ; 00049 } 00050 */ 00051 }
G4double G4LineSection::Dist | ( | G4ThreeVector | OtherPnt | ) | const |
Definition at line 53 of file G4LineSection.cc.
Referenced by Distline().
00054 { 00055 G4double dist_sq; 00056 G4ThreeVector VecAZ; 00057 G4double sq_VecAZ, inner_prod, unit_projection ; 00058 00059 VecAZ= OtherPnt - EndpointA; 00060 sq_VecAZ = VecAZ.mag2(); 00061 00062 inner_prod= VecAtoB.dot( VecAZ ); 00063 00064 // Determine Projection(AZ on AB) / Length(AB) 00065 // 00066 if( fABdistanceSq != 0.0 ) 00067 { 00068 // unit_projection= inner_prod * InvsqDistAB(); 00069 unit_projection = inner_prod/fABdistanceSq; 00070 00071 if( (0. <= unit_projection ) && (unit_projection <= 1.0 ) ) 00072 { 00073 dist_sq= sq_VecAZ - unit_projection * inner_prod ; 00074 } 00075 else 00076 { 00077 // The perpendicular from the point to the line AB meets the line 00078 // in a point outside the line segment! 00079 00080 if( unit_projection < 0. ) // A is the closest point 00081 { 00082 dist_sq= sq_VecAZ; 00083 } 00084 else // B is the closest point 00085 { 00086 G4ThreeVector EndpointB = EndpointA + VecAtoB; 00087 G4ThreeVector VecBZ = OtherPnt - EndpointB; 00088 dist_sq = VecBZ.mag2(); 00089 } 00090 } 00091 } 00092 else 00093 { 00094 dist_sq = (OtherPnt - EndpointA).mag2() ; 00095 } 00096 if( dist_sq < 0.0 ) dist_sq = 0.0 ; 00097 00098 return std::sqrt(dist_sq) ; 00099 }
G4double G4LineSection::Distline | ( | const G4ThreeVector & | OtherPnt, | |
const G4ThreeVector & | LinePntA, | |||
const G4ThreeVector & | LinePntB | |||
) | [static] |
Definition at line 101 of file G4LineSection.cc.
References Dist().
Referenced by G4RKG3_Stepper::DistChord(), G4MagErrorStepper::DistChord(), G4ConstRK4::DistChord(), and G4CashKarpRKF45::DistChord().
00104 { 00105 G4LineSection LineAB( LinePntA, LinePntB ); // Line from A to B 00106 00107 return LineAB.Dist( OtherPnt ); 00108 }
G4double G4LineSection::GetABdistanceSq | ( | ) | const [inline] |