绘制反相摆系统

绘制反相摆系统

与问题相关绘制钟摆系统 我尝试通过模仿弹簧的拉伸来绘制摆锤处于相反相位的情况(输出中的最后一个图)。

代码如下:

\documentclass{article}
\usepackage{tikz}

\usepackage{tikz}
\usetikzlibrary{
   angles,
   quotes,
   arrows.meta,
   decorations.markings,
   decorations.pathmorphing,
   decorations.pathreplacing,
   calc,
   patterns,
   positioning
   }
\tikzset{
      spring/.style={thick,decorate,decoration={aspect=0.5, segment length=#1, amplitude=3mm,zigzag}},
      springgg/.style={thick,decorate,decoration={aspect=0.5, segment length=#1, amplitude=2mm,zigzag}},
      blank/.style={draw=none,fill=none,pos=0.5},
      ground/.style={fill,pattern=north east lines,draw=none,minimum width=0.5cm,minimum height=0.3cm},
      damper/.style={thick,
         decoration={markings, mark connection node=dmp,
           mark=at position 0.5 with
          {
            \node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=10pt,minimum height=3pt,draw=none] {};
            \draw [thick] ($(dmp.north east)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
            \draw [thick] ($(dmp.north)+(0,-3pt)$) -- ($(dmp.north)+(0,3pt)$);
          }
          }, decorate
      },
     box/.style={draw,thick,minimum width=1cm, minimum height=1cm},
     dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
     extended line/.style={shorten >=-#1,shorten <=-#1},
     extended line/.default=0cm,
     bob/.style={draw,fill=gray!40,circle,minimum size=6pt,inner sep=6pt}
    }

\begin{document}

\begin{figure}[htbp]
\centering
\begin{tikzpicture}

\begin{scope}
\node (wall) [ground, minimum width=4cm] {};
\draw (wall.south east) -- (wall.south west);

    \coordinate (pivot1) at (-1,-0.16);
    \draw[thick,-] (pivot1) -- ++ (0,-4)
      node (bob1) [bob]{$$}
      coordinate [midway] (resort1);

    \coordinate (pivot2) at (1,-0.16);
    \draw[thick,-] (pivot2) -- ++ (0,-4)
      node (bob2) [bob]{$$}
      coordinate [midway] (resort2);

   \coordinate (topspring) at ($(resort1) + (0.2cm,0)$);
   \coordinate (bottomspring) at ($(resort2) - (0.2cm,0)$); 

   \draw [decoration={aspect=0.3, pre length=0.3cm, post length=0.3cm, segment length=3mm, amplitude=3mm,zigzag},thick,decorate] (resort1)--(resort2);

   \draw[decorate,decoration={brace,amplitude=.35cm}] (pivot2) -- node[right=3mm] {$l$} (resort2);
   \draw[decorate,decoration={brace,mirror,amplitude=.35cm}] (pivot1) to node[left=3mm] {$L$} (bob1);
\end{scope}

\begin{scope}[xshift=4.5cm]
\node (wall) [ground, minimum width=4cm] {};
\draw (wall.south east) -- (wall.south west);

\useasboundingbox (wall.north west) rectangle ([yshift=-4cm]wall.east);

\pgfmathsetmacro{\myAngle}{30}

    \coordinate (pivot1) at (-1,-0.16);
    \draw[thick] (pivot1) -- ++ (270+\myAngle:4cm)
      node (bob1) [bob]{$$}
      coordinate [midway] (spring1);

    \coordinate (c1) at (pivot1|-spring1);

    \pic [draw, -,font=\small,"$\theta_1$", angle eccentricity=1.5] {angle = c1--pivot1--bob1};

    \coordinate (pivot2) at (1,-0.16);
    \draw[thick] (pivot2) -- ++(270+\myAngle:4cm)
      node (bob2) [bob]{$$}
      coordinate [midway] (spring2);
    \coordinate (c2) at (pivot2|-spring2);

    \pic [draw, font=\small, "$\theta_2$", angle eccentricity=1.5] {angle = c2--pivot2--bob2};
   
   \coordinate (topspring) at ($(spring1) + (0.2cm,0)$);
   \coordinate (bottomspring) at ($(spring2) - (0.2cm,0)$);

    \draw [decoration={aspect=0.3, pre length=0.3cm, post length=0.3cm, segment length=3mm, amplitude=3mm,zigzag},thick,decorate] (spring1)--(spring2);

    \draw [thick, densely dotted] (pivot1) |- (spring1);
    \draw [thick, densely dotted] (pivot2) |- (spring2);

    \draw[decorate,decoration={brace,mirror,amplitude=.25cm}] (c1) -- node[below=2mm] {$x$} (spring1);
    \draw[decorate,decoration={brace,mirror,amplitude=.25cm}] (c2) -- node[below=2mm] {$y$} (spring2);

    \draw[decorate,decoration={brace,amplitude=.35cm}] (pivot1) -- node[blank,right=3mm,yshift=2mm] {$l$} (spring1);
    \draw[decorate,decoration={brace,amplitude=.35cm}] (pivot2) -- node[blank,right=3mm,yshift=2mm] {$L$}(bob2) ;
\end{scope}
\end{tikzpicture}
\end{figure}

\begin{figure}[htbp]
\centering
\begin{tikzpicture}

\node (wall) [ground, minimum width=4cm] {};
\draw (wall.south east) -- (wall.south west);

\pgfmathsetmacro{\myAngle}{30}

 \coordinate (pivot1) at (-1,-0.16);
    \draw[thick] (pivot1) -- ++ (270+\myAngle-60:4cm)
      node (bob1) [bob]{$$}
      coordinate [midway] (arc1);

    \coordinate (c1) at (pivot1|-arc1);

    \pic [draw, -,font=\small,"$\theta_1$", angle eccentricity=1.5] {angle = bob1--pivot1--c1};

    \coordinate (pivot2) at (1,-0.16);
    \draw[thick] (pivot2) -- ++(270+\myAngle:4cm)
      node (bob2) [bob]{$$}
      coordinate [midway] (arc2);
    \coordinate (c2) at (pivot2|-arc2);

    \pic [draw, font=\small, "$\theta_2$", angle eccentricity=1.5] {angle = c2--pivot2--bob2};
    
   \draw [decoration={aspect=0.3, pre length=0.3cm, post length=0.3cm, segment length=7mm, amplitude=2mm,zigzag},thick,decorate] (arc1)--(arc2);

   \draw [thick, densely dotted] (pivot1) |- (arc1);
   \draw [thick, densely dotted] (pivot2) |- (arc2);

   \draw[decorate,decoration={brace,amplitude=.25cm}] (c1) -- node[below=2mm] {$x$} (arc1);
   \draw[decorate,decoration={brace,mirror,amplitude=.25cm}] (c2) -- node[below=2mm] {$y$} (arc2);
   \draw[decorate,decoration={brace,mirror,amplitude=.35cm}] (pivot1) -- node[blank,left=3mm,yshift=2mm] {$l$} (arc1);
   \draw[decorate,decoration={brace,amplitude=.35cm}] (pivot2) -- node[blank,right=3mm,yshift=2mm] {$L$}(bob2);

\end{tikzpicture}
\end{figure}
\end{document} 

输出为: 在此处输入图片描述

问题在于,即使弹簧定义中的pre length和都等于,连接弹簧左右两端到弹簧与琴弦连接点的线段的长度也是不同的。post length0.3cm

我怎样才能使这些片段的长度相等?

答案1

似乎会发生这样的情况:如果锯齿形的可用距离不是段长度一半的整数倍,则柱子长度会延长以适应剩余空间。例如,如果您将 改为segment length6 毫米而不是 7 毫米,看起来会更好。

但是,可以使用库let .. in的语法来计算适当的段长度calc(参见第 14.15 节Let 操作在 TikZ 手册中):

   \draw 
     let 
      \p1=(arc1),\p2=(arc2), % now \x1 is the x-coord of arc1 and \x2 that of arc2
      \n1={veclen(\x2-\x1,\y2-\y1)-2*0.3cm}, % calculate distance available for the zigzags
      \n2={\n1/5.5} % calculate the segment lengths, distance available over number of zigzags (here 5.5)
      in
   [decoration={pre length=0.3cm, post length=0.3cm, segment length=\n2, amplitude=2mm,zigzag},thick,decorate] (arc1)--(arc2);

可能还有更优雅的方法来实现这一点,但这个方法应该可行。(对于这种情况,您可以计算\n1\x2-\x1-2*0.3cm,该veclen方法也适用于非水平弹簧。)

放到一个更简洁的完整示例中,带有箭头的红线|表示距离和 0.3 厘米arc1arc2顺便说一句,我认为该aspect选项对zigzag装饰没有任何作用,因此您实际上可以将其删除。

在此处输入图片描述

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{
   decorations.pathmorphing,
   calc,
   }
\begin{document}
\begin{tikzpicture}

\pgfmathsetmacro{\myAngle}{30}

 \coordinate (pivot1) at (-1,-0.16);
    \draw[thick] (pivot1) -- ++ (270+\myAngle-60:4cm) coordinate [midway] (arc1);

  \coordinate (pivot2) at (1,-0.16);
    \draw[thick] (pivot2) -- ++(270+\myAngle:4cm)  coordinate [midway] (arc2);
    
   \draw 
     let 
      \p1=(arc1),\p2=(arc2), % now \x1 is the x-coord of arc1 and \x2 that of arc2
      \n1={veclen(\x2-\x1,\y2-\y1)-2*0.3cm}, % calculate distance available for the zigzags
      \n2={\n1/5.5} % calculate the segment lengths, distance available over number of zigzags (here 5.5)
      in
   [decoration={pre length=0.3cm, post length=0.3cm, segment length=\n2, amplitude=2mm,zigzag},thick,decorate] (arc1)--(arc2);

% the following two lines just to indicate that the post and pre length are the same
\draw [red,thick, -|] (arc1) -- +(0.3cm,0);
\draw [red,thick, -|] (arc2) -- +(-0.3cm,0);
\end{tikzpicture}
\end{document} 

相关内容