@@ -101,9 +101,11 @@ TVector3 GetParabolicVectorIntersection(const TVector3& pos, const TVector3& dir
101101 if (a != 0 ) {
102102 Double_t root1 = (-half_b - TMath::Sqrt (half_b * half_b - a * c)) / a;
103103 Double_t root2 = (-half_b + TMath::Sqrt (half_b * half_b - a * c)) / a;
104- if (pos.Z () + root1 * dir.Z () < 0 ) {
104+ Double_t int1 = pos.Z () + root1 * dir.Z ();
105+ Double_t int2 = pos.Z () + root2 * dir.Z ();
106+ if (int1 < 0 and int2 < 0 and int1 > int2) {
105107 return pos + root1 * dir;
106- } else if (pos. Z () + root2 * dir. Z () < 0 ) {
108+ } else if (int1 < 0 and int2 < 0 and int1 < int2 ) {
107109 return pos + root2 * dir;
108110 }
109111 return pos;
@@ -131,12 +133,13 @@ TVector3 GetHyperbolicVectorIntersection(const TVector3& pos, const TVector3& di
131133 Double_t c = pos.X () * pos.X () + pos.Y () * pos.Y () - R3 * R3 + e * pos.Z () - g * pos.Z () * pos.Z ();
132134 Double_t root1 = (-half_b - TMath::Sqrt (half_b * half_b - a * c)) / a;
133135 Double_t root2 = (-half_b + TMath::Sqrt (half_b * half_b - a * c)) / a;
134- if (pos.Z () + root1 * dir.Z () > 0 ) {
136+ Double_t int1 = pos.Z () + root1 * dir.Z ();
137+ Double_t int2 = pos.Z () + root2 * dir.Z ();
138+ if (int1 > 0 and int2 > 0 and int1 < int2) {
135139 return pos + root1 * dir;
136- } else if (pos. Z () + root2 * dir. Z () > 0 ) {
140+ } else if (int1 > 0 and int2 > 0 and int1 > int2 ) {
137141 return pos + root2 * dir;
138142 }
139-
140143 return pos;
141144}
142145
0 commit comments