Possibility to get a slope and a y-intercept of a TLine

Hi,

lately I’ve been using TLines a lot, and I think it will be very useful to have member functions returning the m and b when my line is expressed in the form of y=m*x+b. This can be done using the following rather trivial code:

m = (myLine->GetY1() - myLine->GetY2())/(myLine->GetX1() - myLine->GetX2());
b = (myLine->GetX1() * myLine->GetY2() - myLine->GetX2() * myLine->GetY1())/(myLine->GetX1() - myLine->GetX2());

Many thanks in advance for considering this suggestion!

Thanks for the suggestion!

Sure we can add it. Do you have a suggestion for the function name and UI ?

Hi Olivier,

I was thinking Double_t GetSlope() and Double_t GetYIntercept() for m and b, respectively.

Thanks!

1 Like

Sure, I’ll do that. I’ll let you know.

(Note that there will be a problem for vertical lines x = constant)

1 Like

It is here: Implement TLIne::GetSlope and TLine::GetYIntercept by couet · Pull Request #18868 · root-project/root · GitHub

Awesome, thanks a million!

1 Like

@yus
The PR is merged. It took a bit longer than expected because some tests needed to be changed.