如何用 TikZ 强调曲线之间的空间?

如何用 TikZ 强调曲线之间的空间?

这个问题继续我的其他decorations.pathreplacing。我使用 库中的括号解决了这个任务(第 31 至 42 行)TikZ。我的代码:

\documentclass{scrartcl}
\usepackage{stanli}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
  \begin{tikzpicture}
    %the points
    \point{begin}{0}{0};
    \point{middle}{2.5}{0};
    \point{end}{5}{0};
    %the beam
    \beam{2}{begin}{end};
    %the support
    \support{3}{begin}[-90];
    %the load
    \load{1}{middle}[90];
    \load{1}{end}[90];
    %the inscription of the load
    \notation{1}{middle}{$F_1$};
    \notation{1}{end}{$F_2$};
    %the deflection curves
    \foreach
      [evaluate = {\in = 180 - \angle * 2}] \angle in {20, 40}
    \draw
      [-, ultra thick] (begin) to [out = 0, in = \in] (-\angle : 5);
    %circular sector as helplines
    \draw
      [blue, dotted] (begin) -- (middle) arc (0 : -90 : 2.5) -- cycle
                     (begin) -- (end)    arc (0 : -90 : 5)   -- cycle;
    %the inscription of the deflection
    \draw
      [decorate, red, decoration = brace] (2.5, -.03)   -- (2.48, -.34)
      node[right, midway] {\scriptsize$w_{11}$};
    \draw
      [decorate, red, decoration = brace] (2.475, -.39) -- (2.38, -.75)
      node[right, midway] {\scriptsize$w_{12}$};
    \draw
      [decorate, red, decoration = brace] (5, -.03)     -- (4.71, -1.69)
      node[right, midway] {\scriptsize$w_{21}$};
    \draw
      [decorate, red, decoration = brace] (4.68, -1.73) -- (3.85, -3.21)
      node[right, midway] {\scriptsize$w_{22}$};
  \end{tikzpicture}
\end{document}

但我认为这是一个非常糟糕的解决方案,因为我总是重复几乎相同的代码片段和通过尝试和错误做出的点定义(括号的开始和结束位置)。最后,括号的标签应该按照括号显示的方向旋转。简而言之:如何以自动化和最佳的方式解决此任务。欢迎任何优化以及完全不同的解决方案!

提前感谢您的帮助和努力!

答案1

您已经有了坐标middleend,它们可以用于几个坐标。您可以coordinate (ang\angle)在绘制偏转线的路径末尾添加例如,以在那里添加命名坐标。要获取最后的坐标,您可以使用库intersections。最后,要旋转节点,您可以使用库let中的语法calc。在这里我把它包装在一个宏中。

代码输出

\documentclass{scrartcl}
\usepackage{stanli}
\usetikzlibrary{decorations.pathreplacing,intersections}
\newcommand\inscription[4][]{%
  \draw
   let
   \p1=(#2),\p2=(#3),\n1={atan2(\y2-\y1,\x2-\x1)+90}
   in
   [inscription,#1] (#2) -- (#3) node[rotate=\n1] {#4};
}

\begin{document}
  \begin{tikzpicture}[
      inscription/.style={
        decoration = {brace,raise=0.5pt}, % raise moves the brace in the direction it's pointing
        decorate,
        red,
        shorten >=0.8pt, % half the linewidth of ultra thick
        shorten <=0.8pt,
        every node/.style={midway,right,font=\scriptsize}
      },
      arcs/.style={blue,dotted}    
  ]

    %the points
    \point{begin}{0}{0};
    \point{middle}{2.5}{0};
    \point{end}{5}{0};
    %the beam
    \beam{2}{begin}{end};
    %the support
    \support{3}{begin}[-90];
    %the load
    \load{1}{middle}[90];
    \load{1}{end}[90];
    %the inscription of the load
    \notation{1}{middle}{$F_1$};
    \notation{1}{end}{$F_2$};
    %the deflection curves
    \foreach
      [evaluate = {\in = 180 - \angle * 2}] \angle in {20, 40}
    \draw
      [-, ultra thick,name path=defl\angle] (begin) to [out = 0, in = \in] (-\angle : 5) coordinate (ang\angle);
    %circular sector as helplines
    \draw  [arcs,name path=arc1] (begin) -- (middle) arc (0 : -90 : 2.5) -- cycle;
    \draw  [arcs]                (begin) -- (end)    arc (0 : -90 : 5)   -- cycle;
    % find intersections between inner sector and deflections
    \path [
           name intersections={of=defl20 and arc1,by={,D1}}, % first intersection is at "begin", so leave first name empty
           name intersections={of=defl40 and arc1,by={,D2}}];
    %the inscription of the deflection
    \inscription{middle}{D1}{$w_{11}$}
    \inscription{D1}{D2}{$w_{12}$}
    \inscription{end}{ang20}{$w_{21}$}
    \inscription{ang20}{ang40}{$w_{22}$}

  \end{tikzpicture}
\end{document}

相关内容