如何在 tikz 中绘制与坐标轴上的 2 个点匹配的圆弧?

如何在 tikz 中绘制与坐标轴上的 2 个点匹配的圆弧?

我正在尝试绘制一个坐标轴来定义线性插值。

我期望的结果是:

预期结果

目前,我正在使用以下方法绘制它:

\begin{figure}
    \centering
    \begin{tikzpicture}
        \draw[thick] (0,0) -- (5,0) node[anchor=west] {x};
        \draw[thick] (0,0) -- (0,5) node[anchor=east] {y};
        \draw[thick] (0,0) -- (-0.2,0);
        \draw[thick] (0,0) -- (0,-0.2);

        \draw[thick,dashed,blue] (1,0) -- (1,1);
        \draw[thick,dashed,blue] (0,1) -- (1,1) node[circle,fill,inner sep=1pt](a){};

        \draw[thick,dashed,blue] (4,0) -- (4,4);
        \draw[thick,dashed,blue] (0,4) -- (4,4) node[circle,fill,inner sep=1pt](b){};
        
        \draw[thick,dashed,green] (2,0) -- (2,2);
        \draw[thick,dashed,green] (0,2) -- (2,2) node[circle,fill,inner sep=1pt](c){};

        \draw[thick,blue] (0.5,0.5) -- (4.5,4.5);
    \end{tikzpicture}
\end{figure}

结果是:

实际结果

显然它才完成了一半,目前我对贴标签或“设计”它不感兴趣。

所以,我的问题是:

我该如何绘制起寓意作用的红色圆弧?我可以用 手绘它arc,但在我看来,将蓝点与圆弧匹配是一件非常乏味的事情。有没有办法表明这种巧合?

答案1

在你等待 Tikz-help 时,这里有一个元帖子版本进行比较。正如@Zarko 在他的评论中提到的那样,从抛物线开始并定义抛物线上两点之间的线会更容易一些。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

    path xx, yy;
    xx = 5 left -- 200 right;
    yy = xx rotated 90;

    path parabola, line;
    parabola = (origin for x = 1 upto 20: -- (x, x * x) endfor)
        xscaled 10 yscaled 1/3 shifted (-10, 42);

    z1 = point 5 of parabola;
    z2 = point 17 of parabola;

    line = 1.2[z2, z1] -- 1.2[z1, z2];
    z3 = point 3/8 of line;

    drawoptions(withcolor 2/3 red);
    draw parabola;
    label.ulft("$y=f(x)$", point infinity of parabola);

    drawoptions(withcolor 1/4[1/2 blue, white]);
    draw line;
    label.rt("$y=r(x)$", point infinity of line);
    forsuffixes @=1,2:
        draw (x@, 0) -- z@ -- (0, y@) dashed evenly scaled 1/2;
        draw z@ withpen pencircle scaled 3;
        label.bot("$x_{" & decimal @ & "}$", (x@, 0)); 
        label.lft("$y_{" & decimal @ & "}$", (0, y@)); 
    endfor

    interim ahangle := 30;

    drawoptions(withcolor 1/4[1/2 green, white]);
    drawarrow (x3, 0) -- z3 shifted 2 down dashed evenly scaled 1/2;
    drawarrow z3 -- (0, y3) dashed evenly scaled 1/2;
    draw z3 withpen pencircle scaled 3;
    label.bot("$x$", (x3, 0));
    label.lft("$y$", (0, y3));

    drawoptions();
    drawarrow xx; label.rt("$x$", point 2 of xx);
    drawarrow yy; label.lft("$y$", point 1 of yy);

endfig;
\end{mplibcode}
\end{document}

您需要用 来编译它lualatex

相关内容