Index: trunk/MagicSoft/Mars/mbase/MMath.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 8137)
+++ trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 8178)
@@ -1,3 +1,5 @@
 /* ======================================================================== *\
+! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.30 2006-10-30 12:46:12 tbretz Exp $
+! --------------------------------------------------------------------------
 !
 ! *
@@ -32,4 +34,8 @@
 #include "MMath.h"
 
+#ifndef ROOT_TVector2
+#include <TVector2.h>
+#endif
+
 #ifndef ROOT_TVector3
 #include <TVector3.h>
@@ -505,4 +511,56 @@
 // --------------------------------------------------------------------------
 //
+// Calculate the intersection of two lines defined by (x1;y1) and (x2;x2)
+// Returns the intersection point.
+//
+// It is assumed that the lines intersect. If there is no intersection
+// TVector2() is returned (which is not destinguishable from
+// TVector2(0,0) if the intersection is at the coordinate source)
+//
+// Formula from: http://mathworld.wolfram.com/Line-LineIntersection.html
+//
+TVector2 MMath::GetIntersectionPoint(const TVector2 &x1, const TVector2 &y1, const TVector2 &x2, const TVector2 &y2)
+{
+    TMatrix d(2,2);
+    d[0][0] = x1.X()-y1.X();
+    d[0][1] = x2.X()-y2.X();
+    d[1][0] = x1.Y()-y1.Y();
+    d[1][1] = x2.Y()-y2.Y();
+
+    const Double_t denom = d.Determinant();
+    if (denom==0)
+        return TVector2();
+
+    TMatrix l1(2,2);
+    TMatrix l2(2,2);
+
+    l1[0][0] = x1.X();
+    l1[0][1] = y1.X();
+    l2[0][0] = x2.X();
+    l2[0][1] = y2.X();
+
+    l1[1][0] = x1.Y();
+    l1[1][1] = y1.Y();
+    l2[1][0] = x2.Y();
+    l2[1][1] = y2.Y();
+
+    TMatrix a(2,2);
+    a[0][0] = l1.Determinant();
+    a[0][1] = l2.Determinant();
+    a[1][0] = x1.X()-y1.X();
+    a[1][1] = x2.X()-y2.X();
+
+    const Double_t X = a.Determinant()/denom;
+
+    a[1][0] = x1.Y()-y1.Y();
+    a[1][1] = x2.Y()-y2.Y();
+
+    const Double_t Y = a.Determinant()/denom;
+
+    return TVector2(X, Y);
+}
+
+// --------------------------------------------------------------------------
+//
 // Solves: x^2 + ax + b = 0;
 // Return number of solutions returned as x1, x2
Index: trunk/MagicSoft/Mars/mbase/MMath.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MMath.h	(revision 8137)
+++ trunk/MagicSoft/Mars/mbase/MMath.h	(revision 8178)
@@ -6,4 +6,5 @@
 #endif
 
+class TVector2;
 class TVector3;
 class TArrayD;
@@ -47,4 +48,6 @@
     Double_t InterpolParabCos(const TVector3 &vx, const TVector3 &vy, Double_t x);
 
+    TVector2 GetIntersectionPoint(const TVector2 &x1, const TVector2 &y1, const TVector2 &x2, const TVector2 &y2);
+
     inline Int_t SolvePol1(Double_t c, Double_t d, Double_t &x1)
     {
