如何在 TikZ 中绘制两极之间的悬链线?

如何在 TikZ 中绘制两极之间的悬链线?

我想画出如下图所示的悬链线示意图 维基百科或者这里

在此处输入图片描述

我确实得到了一个起点,但我无法正确设置标签和箭头(l对于绳子,w进一步向上移动)或将圆圈内的箭头限制在其半径内并使其平滑地与绳子相切(蓝色)。

这是我的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{
    dimen/.style={
        <->,
        >=latex,
        thick,
        every rectangle node/.style={
            fill=white,
            midway,
            font=\sffamily,
            }
        },%
}
\begin{document}
    \begin{tikzpicture}[scale=1,thick,
    ]
\coordinate (A) at (0,0);
\coordinate (A') at (0,2);   
\coordinate (B) at (10,0);   
\coordinate (B') at (10,2);
\coordinate (C) at (5,.25);
\coordinate (center) at (5,5);


\draw [very thick] (A) -- (A')node{$y=0$}; 
\draw [very thick] (B) -- (B');
\draw [blue,] plot [smooth, tension=1] coordinates { (A') (C) (B')};                
\draw [dashed,color=gray](center) coordinate (center*) circle (4.5);
\draw [dimen,red!50](A')--(B') node{$w$};
\draw [dimen,red!50,dashed](C)--(5,2) node{$h$};
\draw[fill=brown,color=brown] (-1,-.1) -- (-1,0) -- (11,0) -- (11,-.1) -- cycle;
\draw [dimen](center) -- (10.5,5)node{$a$};
\end{tikzpicture}  
\end{document}

它看起来是这样的:

在此处输入图片描述

答案1

这是一个近似值,但似乎足够了。要使其更平坦,只需xscale增加值,反之亦然。

\documentclass[border=2pt,tikz]{standalone}
\begin{document}

\begin{tikzpicture}[> = latex, scale=1.5]
\path [fill=blue!10,xscale=1.3] (-1.78,1.5) rectangle (1.78,-1);
\draw [blue] (0,0) circle [radius = 1cm] (0,0) --node[above]{$a$} (1,0);

\begin{scope}[xscale=1.3]      
  \begin{scope}
    \path [clip] (-1.9,1.5) rectangle (1.9,-1.1);  
    \draw [thick] (0,3) circle [x radius = 1.9cm, y radius = 4cm];
  \end{scope}

  \draw [yshift=.5em,<->] (-1.78,1.5)node[below right=1ex]{$l$} --node[fill=white]{$w$} (1.78,1.5);
  \draw [xshift=-.5em,<->] (-1.78,1.5) --node[fill=white]{$h$} (-1.78,-1);
  \path (-1.78,-1)node[below=1ex]{$x=-{w\over2}$} (0,-1)node[below=1ex]{$x=0$} 
        (1.78,-1)node[below=1ex]{$x={w\over2}$} (1.78,-1)node[right]{$y=-h$} (1.78,1.5)node[right]{$y=0$};            
\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

以下是一个尝试元帖子包裹在luamplib包。使用 进行编译lualatex

在此处输入图片描述

我从后往前解决这个问题——我画了一个单位悬链线(使用标准参数图(x=t,y=cosh(t)),将其缩放到合适的大小,然后找到它的边界框,并先填充它。

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
    vardef cosh(expr t) = 1/2 (mexp(256t)+mexp(-256t)) enddef;

    vardef mark_dimen(expr a, b, s) = 
       save t; picture t;
       t = thelabel(s,1/2[a,b]);
       drawdblarrow a--b withcolor 2/3 red;
       unfill bbox t;
       draw t;
    enddef;

    beginfig(1);
        numeric a, w, h;
        a = 1cm;
        w = 6a;
        h = 8a;

        path cat; numeric m,s;
        m = 1; s = 1/16;
        cat = ((-m,cosh(-m)) for x=s-m step s until m+eps: .. (x,cosh(x)) endfor)
              shifted down xscaled 1/2w yscaled h;

        path box;
        box = (xpart point 0 of cat, 0) -- (xpart point infinity of cat, 0)
           -- point infinity of cat -- point 0 of cat -- cycle;

        fill box withcolor 7/8[blue,white];
        label.bot("$\strut x=0$", origin);
        label.bot("$\strut x=-w/2$", point 0 of box);
        label.bot("$\strut x=w/2$" , point 1 of box);
        label.urt("$y=-h$"  , point 1 of box);
        label.rt("$y=0$"   , point 2 of box);

        interim ahangle := 30;
        mark_dimen(point 0 of box shifted 10 left, point 3 of box shifted 10 left, "$h$");
        mark_dimen(point 3 of box shifted 10 up,   point 2 of box shifted 10 up,   "$w$");

        draw (0,a) -- fullcircle scaled 2a shifted (0,a) withcolor 2/3 blue;
        label.top("$a$", (1/2a,a));

        draw cat;

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

相关内容