# TMultiGraph

Is there a way to find the common point for say two graphs, in a TMultiGraph ? I can’t find a function for it. Maybe I overlooked…

Nothing predefined exists. You should do the loop to compare the points yourself.

What if the intersection is not one of the points in the graphs ? Say, between two points that were defined in the array ?

The equation of all the lines segment between each point of each graph should be find and then the possible intersections computed.

The Eval function of TGraph may be useful for a quick hack. It can also interpolate using splines.
root.cern.ch/root/html522/TGraph … Graph:Eval
the source of this function may also help implementing a clever method.

example of a very primitive (and very slow) “algorithm” to search for intersection between 2 graphs using linear interpolation.

``````double previous=0;
double stepsize=0.01;
double xStart=0;
double xEnd=1;
for (double x=xStart; x<xEnd; x+=stepsize)
{
double diff = graph1->Eval(x)-graph2->Eval(x);
if ((diff <= 0 && previous > 0) || (diff >= 0 && previous < 0) || diff==0) cout << "intersection at "<< x << endl;
previous = diff;
}``````

if performance is important don’t use this (it constantly binary searches for the same points and reinterpolates).
It’s faster to act directly on the graphpoints in similar way and directly calculate the crossing of the interpolation functions.