Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4LineSection Class Reference

G4LineSection is a utility class that calculates the distance of a point from a line section. More...

#include <G4LineSection.hh>

Public Member Functions

 G4LineSection (const G4ThreeVector &PntA, const G4ThreeVector &PntB)
 ~G4LineSection ()=default
G4double Dist (const G4ThreeVector &OtherPnt) const
G4double GetABdistanceSq () const

Static Public Member Functions

static G4double Distline (const G4ThreeVector &OtherPnt, const G4ThreeVector &LinePntA, const G4ThreeVector &LinePntB)

Detailed Description

G4LineSection is a utility class that calculates the distance of a point from a line section.

Definition at line 47 of file G4LineSection.hh.

Constructor & Destructor Documentation

◆ G4LineSection()

G4LineSection::G4LineSection ( const G4ThreeVector & PntA,
const G4ThreeVector & PntB )

Constructor for G4LineSection.

Parameters
[in]PntACoordinates of point A defining the line.
[in]PntBCoordinates of point B defining the line.

Definition at line 33 of file G4LineSection.cc.

35 : EndpointA(PntA), VecAtoB(PntB-PntA)
36{
37 fABdistanceSq = VecAtoB.mag2();
38}

Referenced by Distline().

◆ ~G4LineSection()

G4LineSection::~G4LineSection ( )
default

Default Destructor.

Member Function Documentation

◆ Dist()

G4double G4LineSection::Dist ( const G4ThreeVector & OtherPnt) const

Returns the distance of point 'OtherPnt' from the line.

Definition at line 40 of file G4LineSection.cc.

41{
42 G4double dist_sq;
43 G4ThreeVector VecAZ;
44 G4double sq_VecAZ, inner_prod, unit_projection ;
45
46 VecAZ= OtherPnt - EndpointA;
47 sq_VecAZ = VecAZ.mag2();
48
49 inner_prod= VecAtoB.dot( VecAZ );
50
51 // Determine Projection(AZ on AB) / Length(AB)
52 //
53 if( fABdistanceSq != 0.0 )
54 {
55 // unit_projection= inner_prod * InvsqDistAB();
56 unit_projection = inner_prod/fABdistanceSq;
57
58 if( (0. <= unit_projection ) && (unit_projection <= 1.0 ) )
59 {
60 dist_sq= sq_VecAZ - unit_projection * inner_prod ;
61 }
62 else
63 {
64 // The perpendicular from the point to the line AB meets the line
65 // in a point outside the line segment!
66
67 if( unit_projection < 0. ) // A is the closest point
68 {
69 dist_sq= sq_VecAZ;
70 }
71 else // B is the closest point
72 {
73 G4ThreeVector EndpointB = EndpointA + VecAtoB;
74 G4ThreeVector VecBZ = OtherPnt - EndpointB;
75 dist_sq = VecBZ.mag2();
76 }
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 }
87
88 return std::sqrt(dist_sq) ;
89}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
double mag2() const

Referenced by Distline().

◆ Distline()

◆ GetABdistanceSq()

G4double G4LineSection::GetABdistanceSq ( ) const
inline

Returns the distance squared.

Definition at line 90 of file G4LineSection.hh.

91{
92 return fABdistanceSq;
93}

The documentation for this class was generated from the following files: