I want to draw a graph that contains the following elements:
- A downward-sloping curve in the northeast quadrant of a 2d Cartesian plane;
- a line tangent to an arbitrary point on this curve; and
- the tangent line extends to touch (but not cross) the x and y axes.
I managed to get points 1 and 2 done, but 3 cannot be done without a lot of manual adjustments.
Question
Is there a more efficient way to extend the tangent line (the blue line in my MWE) to both axes? I was thinking, e.g. perhaps the vertical intercept could be determined through some version of the (tangent point -| 0,0) syntax?
MWE
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
tangent/.style={ % https://tex.stackexchange.com/a/25940/18228
decoration={
markings,% switch on markings
mark=
at position #1
with
{
\coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
\coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
\coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
}
},
postaction=decorate
},
use tangent/.style={
shift=(tangent point-#1),
x=(tangent unit vector-#1),
y=(tangent orthogonal unit vector-#1)
},
use tangent/.default=1
]
\draw[very thick,tangent=.4](.5,4)to[bend right=35](5.5,.5);
\draw[use tangent,blue](-2,0)--(2,0); % Better way to draw this line?
\draw[<->](0,5)node[left]{$y$}--(0,0)--(7,0)node[below]{$x$};
\end{tikzpicture}
\end{document}



