TikZ 中传送带的改进

TikZ 中传送带的改进

考虑以下 MWE:

\documentclass[border=5pt,tikz]{standalone}
\begin{document}
    \foreach \n in {0,-10,...,-720}
    {
        \begin{tikzpicture}
            \useasboundingbox (-3,-3) rectangle (10,4);
                \draw[thick] (0,0) circle(1);
                %               \draw (0,0) -- (\n:1) node[fill=black,circle,inner sep=1pt] {} -- (-.5,{sin(\n)+2.5}) node[draw,rectangle,fill=white,minimum width=.5cm,minimum height=.7cm] {};
                \draw (-3,2.5) -- (-.5,{sin(\n)+2.5}) -- (\n:1) node[fill=black,circle,inner sep=1pt] {} -- (0,0);
                \foreach \x in {0,30,...,330}
                {
                    \draw (0,0) -- (\x+\n:1);
                }
                    \begin{scope}[xshift=2.5cm]
                        \foreach \y in {0,1.5,...,6}
                        {
                            %               \draw (\y,0) circle(.5);
                            %               \foreach \x in {0,30,...,330}
                            %               {
                            %                   \draw (\y,0) -- ([xshift=\y cm]\x+\n:.5);
                            %               }
                            \foreach \x in {0,40,...,320}
                            {
                                \fill (\y,0) -- ([xshift=\y cm]\x+\n:.5) arc(\x+\n:\x+\n+20:.5) -- cycle;
                            }
                            \fill (\y,0) circle(.4);
                        }
                        \draw[thick] (0,.5) -- (6,.5) arc(90:-90:.5) -- (0,-.5) arc(-90:-270:.5);
                    \end{scope}
                \draw[rotate=-60,thick] (0,.25) arc(90:270:.25) --+ (2.5,0) arc(-90:90:.25) -- cycle;
                \pgfmathsetmacro\xshift{cos(60)*2.5}
                \pgfmathsetmacro\yshift{-sin(60)*2.5}
                    \draw[xshift=\xshift cm,yshift=\yshift cm,rotate=60,thick] (0,.25) arc(90:270:.25) --+ (2.5,0) arc(-90:90:.25) -- cycle;
                \draw[thick,shift={({cos(60)*2.5},{-sin(60)*2.5})}] (0,0) circle(.25);
                \draw[fill=white,thick] (0,0) circle(.25);
                \foreach \x in {0,40,...,320}
                {
                    \draw (0,0) -- (\x+\n:.25);
                }
                \begin{scope}[shift={({cos(60)*2.5},{-sin(60)*2.5})}]
                    \foreach \x in {0,40,...,320}
                    {
                        \draw (0,0) -- (\x+\n:.25);
                    }
                \end{scope}
                \pgfmathsetmacro\shift{2*cos(60)*2.5}
                \pgfmathsetmacro\anothershift{-5.5*(\n/720)}
                    \fill[xshift=\shift cm,xshift=\anothershift cm,yshift=.5cm,rounded corners,red] (0,0) rectangle (.5,.3);
            \end{tikzpicture}
    }
\end{document}

输出如下:

截屏

我的问题是:如何更好地绘制旋转整个机制的杠杆,即如何保持实际长度,因为该部分是硬编码的,我正在寻找更精确的解决方案。

答案1

连接臂的长度由 设定\lenA

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

    \foreach \n in {0,-10,...,-720}
    {
        \begin{tikzpicture}
            \useasboundingbox (-3,-3) rectangle (10,4);
                \draw[thick] (0,0) circle(1);
                %               \draw (0,0) -- (\n:1) node[fill=black,circle,inner sep=1pt] {} -- (-.5,{sin(\n)+2.5}) node[draw,rectangle,fill=white,minimum width=.5cm,minimum height=.7cm] {};
                \def\lenA{3}%
                \pgfmathsetmacro{\yB}{sin(\n)}%
                \pgfmathsetmacro{\xB}{cos(\n)}%
                \pgfmathsetmacro{\xA}{\xB-sqrt(\lenA*\lenA-\yB*\yB)}%
                \draw[blue] (\xA,0) -- (\xB,\yB);
                %\draw (-3,2.5) -- (-.5,{sin(\n)+2.5}) -- (\n:1) node[fill=black,circle,inner sep=1pt] {} -- (0,0);% levers
                \foreach \x in {0,30,...,330}% spokes
                {
                    \draw (0,0) -- (\x+\n:1);
                }
                    \begin{scope}[xshift=2.5cm]
                        \foreach \y in {0,1.5,...,6}
                        {
                            %               \draw (\y,0) circle(.5);
                            %               \foreach \x in {0,30,...,330}
                            %               {
                            %                   \draw (\y,0) -- ([xshift=\y cm]\x+\n:.5);
                            %               }
                            \foreach \x in {0,40,...,320}
                            {
                                \fill (\y,0) -- ([xshift=\y cm]\x+\n:.5) arc(\x+\n:\x+\n+20:.5) -- cycle;
                            }
                            \fill (\y,0) circle(.4);
                        }
                        \draw[thick] (0,.5) -- (6,.5) arc(90:-90:.5) -- (0,-.5) arc(-90:-270:.5);
                    \end{scope}
                \draw[rotate=-60,thick] (0,.25) arc(90:270:.25) --+ (2.5,0) arc(-90:90:.25) -- cycle;
                \pgfmathsetmacro\xshift{cos(60)*2.5}
                \pgfmathsetmacro\yshift{-sin(60)*2.5}
                    \draw[xshift=\xshift cm,yshift=\yshift cm,rotate=60,thick] (0,.25) arc(90:270:.25) --+ (2.5,0) arc(-90:90:.25) -- cycle;
                \draw[thick,shift={({cos(60)*2.5},{-sin(60)*2.5})}] (0,0) circle(.25);
                \draw[fill=white,thick] (0,0) circle(.25);
                \foreach \x in {0,40,...,320}
                {
                    \draw (0,0) -- (\x+\n:.25);
                }
                \begin{scope}[shift={({cos(60)*2.5},{-sin(60)*2.5})}]
                    \foreach \x in {0,40,...,320}
                    {
                        \draw (0,0) -- (\x+\n:.25);
                    }
                \end{scope}
                \pgfmathsetmacro\shift{2*cos(60)*2.5}
                \pgfmathsetmacro\anothershift{-5.5*(\n/720)}
                    \fill[xshift=\shift cm,xshift=\anothershift cm,yshift=.5cm,rounded corners,red] (0,0) rectangle (.5,.3);
            \end{tikzpicture}
    }
\end{document}

相关内容