Import Geant4 10.4.0 source tree
This commit is contained in:
@@ -89,6 +89,43 @@ inline bool inside(const std::pair<T,T>& a_P,const std::vector< std::pair<T,T> >
|
||||
return ((wn!=0)?true:false);
|
||||
}
|
||||
|
||||
template <class VEC2>
|
||||
inline bool intersect(const VEC2& P1,const VEC2& Q1,const VEC2& P2,const VEC2& Q2,VEC2& a_out) {
|
||||
// (P1,Q1) first line, (P2,Q2) second line and a_out intersection.
|
||||
// return false if no intersection. (For exa, parallel lines).
|
||||
|
||||
// P1+(Q1-P1)*r = P2+(Q2-P2)*s
|
||||
// (Q1-P1)*r - (Q2-P2)*s = P2-P1
|
||||
// r*(Q1-P1).v0 - s*(Q2-P2).v0 = (P2-P1).v0 //x
|
||||
// r*(Q1-P1).v1 - s*(Q2-P2).v1 = (P2-P1).v1 //y
|
||||
|
||||
// a*r + b*s = c
|
||||
// d*r + e*s = f
|
||||
|
||||
// r = (c*e-f*b)/(a*e-d*b)
|
||||
// s = (a*f-d*c)/(a*e-d*b)
|
||||
|
||||
typedef typename VEC2::elem_t T;
|
||||
VEC2 A = Q1-P1;
|
||||
VEC2 B = P2-Q2;
|
||||
VEC2 C = P2-P1;
|
||||
|
||||
T a = A.v0();
|
||||
T b = B.v0();
|
||||
T c = C.v0();
|
||||
T d = A.v1();
|
||||
T e = B.v1();
|
||||
T f = C.v1();
|
||||
|
||||
T det = a*e-d*b;
|
||||
if(det==T()) return false;
|
||||
|
||||
T r = (c*e-f*b)/det;
|
||||
|
||||
a_out = P1+A*r;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user