# Shading area between tangent normal and x-axis

I was wondering if I could get some help filling in the area bounded between the tangent the normal and the x-axis (which is the triangle). I've read through quite a bit of material and threads but cannot manage to find out how to do it with the way I have currently set up my graphs.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{center}
\begin{tikzpicture}
\draw (3,{0.06*exp(3)+1}) circle[radius=2pt] node[right] {$(a,f(a))$};
\draw [<->] (-1,0) -- (7,0) node[right]{$x$};
\draw [<->] (0,-1) -- (0,5)node[above]{$y$};
\draw[domain=-1:4] [<->] plot (\x,{0.06*exp(\x)+1}) node[right] {$y = f(x)$};
\draw[domain=0.5:4] [<->] plot (\x, {0.06*exp(3)*(\x-3)+0.06*exp(3)+1}) node[right] {$\ell_T$};

\draw[domain=2:6.5] [<->] plot (\x, {-1/(0.06*exp(3))*(\x-3)+0.06*exp(3)+1}) node[right] {$\ell_N$};;
\end{tikzpicture}
\end{center}

\end{document}


This is what it looks like so far.

• Welcome to TeX.SE! Apr 22 at 17:10
• Please always extend your code to a full compilable small document. Apr 22 at 18:10

You can make use of the intersections library (and also let TikZ calculate the position of (a, f(a)) on its own):

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{intersections, backgrounds}

\begin{document}
\begin{tikzpicture}

\draw[<->, name path=x-axis] (-1,0) -- (7,0)
node[right]{$x$};
\draw[<->] (0,-1) -- (0,5)
node[above]{$y$};
\draw[domain=-1:4, <->]
plot (\x,{0.06*exp(\x)+1})
node[right] {$y = f(x)$};
\draw[domain=0.5:4, <->, name path=tangent]
plot (\x, {0.06*exp(3)*(\x-3)+0.06*exp(3)+1})
node[right] {$\ell_T$};
\draw[domain=2:6.5, <->, name path=normal]
plot (\x, {-1/(0.06*exp(3))*(\x-3)+0.06*exp(3)+1})
node[right] {$\ell_N$};

\path[name intersections={of=normal and tangent}]
(intersection-1) coordinate (a);
\path[name intersections={of=normal and x-axis}]
(intersection-1) coordinate (b);
\path[name intersections={of=tangent and x-axis}]
(intersection-1) coordinate (c);

node[right] {$(a,f(a))$};

\begin{scope}[on background layer]
\fill[red!10] (a) -- (b) -- (c) -- cycle;
\end{scope}

\end{tikzpicture}
\end{document}


You could also make use of the fillbetween library that comes with the pgfplots package (maybe a bit overkill here, but useful in more complicated settings where one boundary is a plot for example):

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{fillbetween, backgrounds}

\begin{document}
\begin{tikzpicture}

node[right] {$(a,f(a))$};
\draw[<->, name path=x-axis] (-1,0) -- (7,0)
node[right]{$x$};
\draw[<->] (0,-1) -- (0,5)
node[above]{$y$};
\draw[domain=-1:4, <->]
plot (\x,{0.06*exp(\x)+1})
node[right] {$y = f(x)$};
\draw[domain=0.5:4, <->, name path=tangent]
plot (\x, {0.06*exp(3)*(\x-3)+0.06*exp(3)+1})
node[right] {$\ell_T$};
\draw[domain=2:6.5, <->, name path=normal]
plot (\x, {-1/(0.06*exp(3))*(\x-3)+0.06*exp(3)+1})
node[right] {$\ell_N$};

\path[
name path=temp,
intersection segments={
of=normal and tangent,
sequence={L2 -- R1}
}
] -- cycle;

\begin{scope}[on background layer]
\fill[
red!10,
intersection segments={
of=temp and x-axis,
sequence={L1 -- R2}
}
] -- cycle;
\end{scope}

\end{tikzpicture}
\end{document}


Both result in the the same output: