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

**URL:** <https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [May 24, 2025, 7:44am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598 "2025-05-24T07:44:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 24, 2025, 7:44am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/1 "2025-05-24T07:44:11Z")

</div>

Hi,

lately I’ve been using `TLine`s 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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 25, 2025, 6:02am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/2 "2025-05-25T06:02:46Z")

</div>

Thanks for the suggestion!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 25, 2025, 9:05am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/3 "2025-05-25T09:05:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 25, 2025, 9:22am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/4 "2025-05-25T09:22:50Z")

</div>

Hi Olivier,

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

Thanks!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 26, 2025, 6:54am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/5 "2025-05-26T06:54:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [May 26, 2025, 7:28am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/6 "2025-05-26T07:28:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 26, 2025, 11:36am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/7 "2025-05-26T11:36:31Z")

</div>

> [@yus](#):
>
> ```auto
> m = (myLine->GetY1() - myLine->GetY2())/(myLine->GetX1() - myLine->GetX2());
> b = (myLine->GetX1() * myLine->GetY2() - myLine->GetX2() * myLine->GetY1())/(myLine->GetX1() - myLine->GetX2());
> 
> ```

It is here: [Implement TLIne::GetSlope and TLine::GetYIntercept by couet · Pull Request #18868 · root-project/root · GitHub](https://github.com/root-project/root/pull/18868)

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 26, 2025, 11:41am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/8 "2025-05-26T11:41:07Z")

</div>

Awesome, thanks a million!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 28, 2025, 7:35am UTC](https://root-forum.cern.ch/t/possibility-to-get-a-slope-and-a-y-intercept-of-a-tline/63598/9 "2025-05-28T07:35:36Z")

</div>

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