# How can I write equation of a line on the above side of the line or anywhere on the line in the given figure

How can I write equation of a line on the above side of the line or anywhere on the line in the given figure say along the side of the line AB or BC.

\begin{tikzpicture}
\tikzset{dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1}}
\draw (0,5)-- (0,0)node(o){O} --(5,0);
\draw [name path=P1] (2,0)node(d){D(30,0)} -- (0,4)node(a){A};
\draw [name path=P2] (4,0)node(c){C(50,0)} -- (0,2)node(e){E(0,50)};
\path [name intersections={of=P1 and P2,by=b}];
\node [dot=B{(20,30)} ]  at (b) {};

\begin{pgfonlayer}{bg}    % select background
\path [fill=green!50] (o.center) -- (d.center) -- (b) -- (e.center) -- cycle;
\end{pgfonlayer}

\end{tikzpicture}


As you asked questions regarding the same graph on multiple occasions by now (hence, automating the insertion of the equations at specific points should not be necessary), I advise to use "brute force" to insert the equations and add them via nodes. Just add

\node at (2,2.5) (eq1) {$y_1 = m_1x+b_1$};
\node at (3.5,0.75) (eq2) {$y_2 = m_2x+b_2$};


to your code and you should achieve something like the following. This solution is not really elegant but it does the job.

• Thanks a lot it works... Commented Mar 17, 2020 at 10:07

you can use node[right=distance pt, pos=y]{caption} end of each line or curve where 0<y<1.

\begin{tikzpicture}
\tikzset{dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1}}
\draw (0,5)-- (0,0)node(o){O} --(5,0);
\draw [name path=P1] (2,0)node(d){D(30,0)} -- (0,4)node(a){A}node[right, pos=.8]{$y_1 = m_1x+b_1$};
\draw [name path=P2] (4,0)node(c){C(50,0)} -- (0,2)node(e){E(0,50)}node[right=8pt, pos=.4]{$y_2 = m_2x+b_2$};
\path [name intersections={of=P1 and P2,by=b}];
\node [dot=B{(20,30)} ]  at (b) {};

% \begin{pgfonlayer}{bg}    % select background
% \path [fill=green!50] (o.center) -- (d.center) -- (b) -- (e.center) -- cycle;
% \end{pgfonlayer}

\end{tikzpicture}


Again, as I mentioned at your previous question, I would label shapes corners outside of shape. Based on mentioned answer, I suggest solution based on answer which is presented in the following MWE:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds,
intersections,
positioning}

\begin{document}
\begin{tikzpicture}[auto=right,
dot/.style = {circle, fill, inner sep=1pt},
every edge/.style = {draw, shorten >=-12mm},
every label/.style = {inner sep=1.5pt}
]
\coordinate[label=below left:O]         (o);
\coordinate[label=below:D,right=2 of o] (d);
\coordinate[label=below:C,right=2 of d] (c);
\coordinate[label=left: E,above=2 of o] (e);
\coordinate[label=left: A,above=2 of e] (a);
%
\draw[name path=DA] (d) -- (a) node[pos=0.75] {$y_2=m_2+b_2$};
\draw[name path=CE] (c) -- (e) node[pos=0.45] {$y_1=m_1+b_1$};
\path [name intersections={of=DA and CE,by=b}] (b) node[dot, label=above right:B] {};
%
\draw   (o) edge (c)    (o) edge (a);
\scoped [on background layer]   \fill[green] (o) --(d) -- (b) -- (e);
\end{tikzpicture}
\end{document}