问题

问题

我想绘制一个包含以下元素的图形:

  1. 二维笛卡尔平面东北象限中一条向下倾斜的曲线;
  2. 与该曲线上任意一点相切的线;以及
  3. 切线延伸至接触(但不穿过) x 轴和 y 轴。

我设法完成了第 1 点和第 2 点,但是第 3 点需要大量的手动调整才能完成。

问题

有没有更有效的方法将切线(我的 MWE 中的蓝线)延伸到两个轴?我在想,例如,也许可以通过某种版本的语法来确定垂直截距(tangent point -| 0,0)

平均能量损失

\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}

输出

在此处输入图片描述

答案1

有一个几乎微不足道的可能性:将切线延长一些适当的量然后剪掉它。

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,calc}
\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);
\begin{scope}[overlay]
\clip(0,0) rectangle (10,10);
\draw[use tangent,blue](-3,0)--(3,0); % Better way to draw this line?
\end{scope}
\draw[<->](0,5)node[left]{$y$}--(0,0)--(7,0)node[below]{$x$};

\end{tikzpicture}
\end{document}

在此处输入图片描述

当然,还会有更精致、更优雅的解决方案。;-)

您甚至不需要交点就可以找到与轴的交点。

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,calc}
\begin{document}
\tikzset{mark tangent intersections with axes/.code={
\path let \p1=(tangent point-#1), 
\p2=($(tangent unit vector-#1)-(tangent point-#1)$)
in
({\x1-\y1*\x2/\y2},0) coordinate (x-intersection-#1) 
(0,{\y1-\x1*\y2/\x2}) coordinate (y-intersection-#1);},
mark tangent intersections with axes/.default=1
}
\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[mark tangent intersections with axes,blue] 
(x-intersection-1) -- (y-intersection-1);
\draw[<->](0,5)node[left]{$y$}--(0,0)--(7,0)node[below]{$x$};

\end{tikzpicture}
\end{document}

在此处输入图片描述

如果有多个切线,请使用\draw[mark tangent intersections with axes=2,...等,相应的交点将被称为等(x-intersection-2)(y-intersection-2)请注意,如果切线是水平或垂直的,此代码将失败,交点也是如此。如果您想使其更加万无一失,可以添加 if 语句来检查\y2\x2是否为零。

答案2

另一种解决方案是使用tzplot包裹:

在此处输入图片描述

使用\clip

\documentclass[tikz]{standalone}
    
\usepackage{tzplot}

\begin{document}

\begin{tikzpicture}
\tzhelplines(7,6)
\tzaxes(7,6){$x$}[b]{$y$}[l]
\tzto[thick,bend right=35]"IC"(.5,4)(5.5,.5)
\clip (0,0) rectangle (5,5);  % clip
\settztangentlayer{main}      % main layer
\tztangentat[blue]{IC}{2}[0:4.5]
\end{tikzpicture}

\end{document}

查找并使用轴上的坐标:

\documentclass[tikz]{standalone}
    
\usepackage{tzplot}

\begin{document}

\begin{tikzpicture}
\tzhelplines(7,6)
\tzaxes*(7,6){$x$}[b]{$y$}[l]
\tzto[thick,bend right=35]"IC"(.5,4)(5.5,.5)
% find points on axes
\settztangentlayer{main}
\tztangentat[draw=none]"tan"{IC}{2}[0:4.1]
\tzvXpointat{tan}{0}(A)
\tzhXpointat{tan}{0}(B)
% draw line
\tzline[blue](A)(B)   
\end{tikzpicture}

\end{document}

相关内容