TikZ 및 특수 스타일 화살표로 여러 자동차를 그립니다.

TikZ 및 특수 스타일 화살표로 여러 자동차를 그립니다.

이 그림을 그리도록 안내해 주실 수 있나요?

여기에 이미지 설명을 입력하세요

나는 이 코드를 사용하여 여러 대의 자동차를 그렸습니다.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\tikzset{
    pics/my car/.style={
        code={
            \tikzset{my car/.cd, #1}
            \shade[my car/car color, shading angle={135},
                draw=black, rounded corners=1.2ex, very thick] 
                (1.5,.5) -- ++(0,1) -- ++(1,0.3) --  ++(3,0) -- ++(1,0) 
                    -- ++(0,-1.3) -- (1.5,.5) -- cycle;
            \draw[very thick, rounded corners=0.5ex, fill=black!20!blue!20!white, thick]
                (2.5,1.8) -- ++(1,0.7) -- ++(1.6,0) -- ++(0.6,-0.7) -- (2.5,1.8);
            \draw[thick] (4.2,1.8) -- (4.2,2.5);
            \draw[fill=gray!50, thick] 
                (2.75,.5) circle[radius=.5cm]
                (5.5,.5) circle[radius=.5cm];
            \draw[fill=gray!80, semithick] 
                (2.75,.5) circle[radius=.4cm]
                (5.5,.5) circle[radius=.4cm];
            \coordinate (-front) at (1.5,1);
            \coordinate (-back) at (6.5,1);
            \coordinate (-top) at (4.25,2.5);
            \coordinate (-bottom) at (4.25,0);
        }
    },
    my car/car color/.style={
        top color=red, bottom color=white
    }
}

\begin{document}
\begin{tikzpicture}

\pic (car 1) at (0,0) {my car};    

\pic (car 2) at (10,0) {my car={car color/.append style={top color=blue}}};  

\pic (car 3) at (20,0) {my car={car color/.append style={top color=green}}};  

\pic (car 4) at (30,0) {my car={car color/.append style={top color=black}}};  

%\draw[<-, shorten <=5pt, shorten >=5pt, ultra thick] 
  %  (car 1-back) -- (car 2-front);

\draw[line width=5pt][<-, shorten <=5pt, shorten >=5pt] 
    (car 1-top) to[out=90, in=90] (car 2-top);
  \draw[line width=5pt][<-, shorten <=5pt, shorten >=5pt] 
  (car 2-top) to[out=90, in=90] (car 3-top);
   \draw[line width=5pt][<-, shorten <=5pt, shorten >=5pt] 
  (car 3-top) to[out=90, in=90] (car 4-top);

\end{tikzpicture}
\end{document}

답변1

업데이트

나는 tikz ducks 라이브러리를 사용했는데, 그 이유는 보시다시피 매우 그림처럼 다양한 결과와 무작위로 얻을 수 있는 명령이 있기 때문입니다. 문서를 보면 그 모든 것을 생성하기 위한 작성자의 모든 노력을 볼 수 있습니다. 아마도 언젠가 누군가가 TeX에 대한 사랑이나 무엇이든을 위해 차량 및 기타 것들과 비슷한 작업을 수행할 것입니다. 그러나 주로 MWE를 만들기 위해 코드를 복사하여 컴파일러에 붙여넣고 모든 패키지가 있으면 예 또는 예라는 결과가 나올 수 있으며 일부 경고가 표시됩니다.

물론 FZH가 제안한 것처럼 쉬운 방법은 그가 인용한 예처럼 외부 파일을 포함하는 것입니다. 그러나 보기 좋게 보이려면 특정 세부 사항을 처리해야 하기 때문에 우선 해당 파일이 노드에 있을 것이므로 앵커 포인트가 중요합니다. 그런 다음 모든 이미지가 동일한 축척에 있으므로 특정 너비로 ​​정의할 수 있습니다. 이를 위해 인터넷에서 무료 벡터 파일을 검색하고 inkscape에서 편집하고 필요한 것을 분리한 다음 캔버스를 잘라내는 것이 좋습니다. 최소 벡터 크기, pdf, png 또는 jpg로 내보내기; pdf는 벡터를 유지하기 때문에 더 좋습니다.

다음을 컴파일하려면 여기에서 4개의 PDF를 다운로드해야 합니다.링크, CAR-1.pdf, CAR-2.pdf, .. 등 더 많은 파일이 있지만 무료로 사용할 수 있습니다. 사본의 복사본이기 때문에 내가 가져온 원본 svg도 있습니다... 다음 저장 tex 파일이 있는 동일한 디렉토리에 저장하세요. 보시다시피 컴파일러가 찾을 수 있도록 해당 파일 이름을 원하는 것으로 바꿀 수 있습니다.

결과:

여기에 이미지 설명을 입력하세요

코드: (컴파일하려면 동일한 main.tex 디렉토리에 4개의 외부 파일이 필요합니다)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,backgrounds,decorations.markings}

\begin{document}
    \begin{tikzpicture}[%Here you can define some tikz picture enviroment options
        font=\sf\scriptsize,%set al fonts of this environment \sf=serif family, and size of text
        Arrow/.style 2 args= {%Custom style arrow named Arrow, that has 2 arguments
            draw=#1,%Option draw=color, #1 is the first argument
            >={Triangle[angle=120:.5cm 0.3,scale length=0.5*#2,scale width=0.3*#2]},%It uses arrows meta arrow personalization, check visual tikz normal definition is ->
            line width=#2*1.2mm
            },
        ArrowColor/.store in=\ArrowColor,ArrowColor=black,%Some variable to use in other styles below
        ArCorr/.store in=\ArCorr,ArCorr=1.5, %Some variable to use in other styles below
        Thickness/.store in=\Thickness,Thickness=4pt,%Some variable to use in other styles below
        W/.store in=\W,W=5mm,%Some variable to use in other styles below
        Arrow2/.style={%custom style arrow using decoratins markings.
            draw=none,
            postaction={
                decorate,
                decoration={
                    markings,
                    mark= at position 0 %this draw will be the first mark at the start of the path
                    with {%Mark drawing definition
                        \begin{scope}[yscale=#1]%All is in scope to mirror it using the default argument #1, using as Arrow2=-1 or 1
                            \pgfmathparse{int(\pgfdecoratedpathlength/4)}%Obtain the leght of the path
                            \edef\H{\pgfmathresult/15}%Then adjuts to mach the size of coordinates to the lenght of the path.
                            \fill[fill=\ArrowColor]
                            (0,0)
                            to [out=90-15, in=180] (\H,\W/1.5) coordinate (b)
                            -- ++(\Thickness,0) -- ++(0,-1pt) 
                            to [out=180, in=90-15] (\Thickness,0)
                            -- (0,0);
                        \end{scope}
                    }
                }
            },
            postaction={
                decorate,
                decoration={
                    markings,
                    mark=at position 1 %this draw will be the last mark at the end of the path
                    with {
                        \begin{scope}[yscale=#1]%idem
                            \pgfmathparse{int(\pgfdecoratedpathlength/4)}%idem
                            \edef\H{\pgfmathresult/15}%idem
                            \fill[fill=\ArrowColor]
                            (b) %uses previos coodinate to draw in the marck
                            to [out=0, in=90+20] (\Thickness/2,\Thickness*\ArCorr/1.5)
                            -- (\Thickness*\ArCorr,\Thickness*\ArCorr/1.5)
                            -- (0,0)
                            -- (-\Thickness*\ArCorr,\Thickness*\ArCorr/1.5)
                            -- (-\Thickness/2,\Thickness*\ArCorr/1.5)
                            to [out=90+20, in=0] ($(b)+(0,-1pt)$)
                            -- (b);
                        \end{scope}
                    }
                }
            }
        }
        ]
        
        %Creating a weel for all cars
        \def\Weel#1{%\Weel{position}
            \draw[fill=white,shift={(#1)}](0,0)circle (0.3);
            \draw[fill=black!80, even odd rule,shift={(#1)}](0,0) circle (.3) circle (0.2);
            \draw[fill,shift={(#1)}](0,0) circle (0.08);
            \foreach \i in {1,...,12}{\draw[fill,shift={(#1)}](30*\i:0.1)--(30*\i:0.2)--+(90+30*\i:0.02);}        
        }
        
        % drawing the Cars from external archives, you may include vectors (svg for example) if you convert them to pdf format.
        \draw(0,0) node[anchor=-90](CAR-1){\includegraphics[width=3cm]{CAR-1.pdf}}; %\draw(position) node [node options](node_name){\includegraphics[graphic options]{imagefile}}
        \draw($(CAR-1.-90)+(4.5,0)$) node[anchor=-90](CAR-2){\includegraphics[width=3cm]{CAR-2.pdf}};
        \draw($(CAR-2.-90)+(4.5,0)$) node[anchor=-90](CAR-3){\includegraphics[width=3cm]{CAR-3.pdf}};
        \draw($(CAR-3.-90)+(4.5,0)$) node[anchor=-90](CAR-4){\includegraphics[width=3cm]{CAR-4.pdf}};
        \draw($(CAR-4.-90)+(3,0)$) node[scale=3]{$\dots$};
        \draw($(CAR-4.-90)+(6,1)$) node[scale=2.5, draw, thick](L){\scriptsize Leader};
        \Weel{$(L)+(-0.8,-0.7)$}
        \Weel{$(L)+(0.8,-0.7)$} 
        \draw($(CAR-2)+(0,4)$) node[scale=2.5, draw, thick](C){\scriptsize Controller l};
        
        %Drawing some Arrows
        \draw[Arrow={cyan!40!blue}{1.2},->](CAR-1.120) |- ($(C)+(-1,2)$) -| (C.150);% |:vertical -:horizontal
        \draw[Arrow={cyan!40!blue}{1.2},->](CAR-2.120) coordinate (temp) -- (C.-90-|temp);% node_coord intersectión perpendicular tipe (-| or |-)
        \draw[Arrow={cyan!40!blue}{1.2},->]($(L.90)+(0,0.5em)$) |- ($(C)+(1,2)$) -| (C.120);
        \draw[Arrow={cyan!40!blue}{1.2},->](CAR-4.120) |- ($(C)+(1,1.5)$) -| (C.60);
        \draw[Arrow={cyan!40!blue}{1.2},->](CAR-3.120) |- ($(C)+(1,1)$) -| (C.30);
        %Drawing some repetitive things
        \foreach \txbehind/\Car [count=\j from 1]in {
            i+1/CAR-1,
            node\quad i/CAR-2,
            i-1/CAR-3,
            i-2/CAR-4,
            0/L%<-necessary
        }{
            \path($(CAR-1.-90)+(0,-0.2)$)coordinate (temp) -- (temp-|\Car.-90) node []{$\txbehind$};
            \ifnum\j<5\draw[Arrow={cyan!40!blue}{1},->]($(\Car.90)+(0,1)$) -- ++(0,-1)node [pos=0.1, anchor=-180]{$U_{\txbehind}$};\fi
            \ifnum\j<4{}\draw[Arrow={red}{1},->](\Car.15) -- ++(0.75,0)node [midway, anchor=90]{$V_{\txbehind}$};\fi
        }
        
        \draw[Arrow2=-1,ArrowColor=black,Thickness=2mm,W=1.5cm,ArCorr=1.5] (CAR-2.140) -- (CAR-1.40);
        \draw(b)++(0,0.7em) node {$\tilde{U}_{i+1}$}; %notice that b node is defined in the marking style
        \draw[Arrow2=-1,ArrowColor=black,Thickness=2mm,W=1.5cm,ArCorr=1.5] (CAR-3.140) -- (CAR-2.40);
        \draw(b)++(0,0.7em) node {$\tilde{U}_i$}; %the b position is rewritten by the previous instruction
        \draw[Arrow2=-1,ArrowColor=black,Thickness=2mm,W=1.5cm,ArCorr=1.5] (CAR-4.140) -- (CAR-3.40);
        \draw(b)++(0,0.7em) node {$\tilde{U}_{i-1}$};%ditto
        \draw[dashed,green!50!black](CAR-2.south east)--++(0,-1) coordinate (temp1);
        \draw[dashed,green!50!black](CAR-3.south west)--++(0,-1) coordinate (temp2);%
        \draw[Arrow={green!50!black}{1},<->]($(temp1)+(0,1.5em)$)coordinate (temp) -- (temp -| temp2) node [midway, anchor=90]{$d_{i}$};
        
    \end{tikzpicture}
\end{document}

원래의

글쎄, 때로는 사회적으로 사람들을 더 효과적으로 움직여서 사람들이 이것이 전형적인 "나를 위해 하세요" 사례라고 생각하지 않도록 해야 하는 경우가 있습니다. 따라서 특정 사례에 초점을 맞춘 질문을 만들고 격리하려고 노력해야 합니다. 물론이죠. 따라서 검색을 하더라도 적용할 수 있는 코드 조각을 찾을 수 있습니다. 아직 많이 이해하지 못한다면 그리 쉽지는 않을 것입니다. 하지만 음..., 제가 할 수 있는 코드가 있었기 때문에 여기에 해결책을 제시합니다. 최소한 화살표 문제는 완료됩니다.

파란색 화살표:멋지고 복잡한 순서도 그리는 방법(테이블과 순서도 결합)

검정색 곡선 화살표:Helix 코드에 화살표 추가

결과:

여기에 이미지 설명을 입력하세요

MWE:

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,ducks,decorations.markings}

\begin{document}
    \begin{tikzpicture}[
        >=Triangle,
        font=\sf\scriptsize,
        Arrow/.style 2 args= {draw=#1,-{Triangle[angle=120:.5cm 0.3,scale length=0.5*#2,scale width=0.3*#2]},line width=#2*1.2mm},
        CoilColor/.store in=\coilcolor,CoilColor=black,
        ArCorr/.store in=\ArCorr,ArCorr=1.5,
        Thickness/.store in=\Thickness,Thickness=4pt,
        W/.store in=\W,W=5mm,
        Arrow2/.style={
            draw=none,
            postaction={
                decorate,
                decoration={
                    markings,
                    mark= at position 0
                    with {
                        \begin{scope}[yscale=#1]
                            \pgfmathparse{int(\pgfdecoratedpathlength/4)}
                            \edef\H{\pgfmathresult/15}
                            \fill[fill=\coilcolor!50!black]
                            (0,0)
                            to [out=90-15, in=180] (\H,\W/1.5) coordinate (b)
                            -- ++(\Thickness,0) -- ++(0,-1pt) coordinate (c)
                            to [out=180, in=90-15] (\Thickness,0)
                            -- (0,0);
                        \end{scope}
                    }
                }
            },
            postaction={
                decorate,
                decoration={
                    markings,
                    mark=at position 1
                    with {
                        \begin{scope}[yscale=#1]
                            \pgfmathparse{int(\pgfdecoratedpathlength/4)}
                            \edef\H{\pgfmathresult/15}
                            \fill[fill=\coilcolor]
                            (b)
                            to [out=0, in=90+20] (\Thickness/2,\Thickness*\ArCorr/1.5)
                            -- (\Thickness*\ArCorr,\Thickness*\ArCorr/1.5)
                            -- (0,0)
                            -- (-\Thickness*\ArCorr,\Thickness*\ArCorr/1.5)
                            -- (-\Thickness/2,\Thickness*\ArCorr/1.5)
                            to [out=90+20, in=0] ($(b)+(0,-1pt)$)
                            -- (b);
                        \end{scope}
                    }
                }
            }
        }
        ]
        %Creating a weel for all cars
        \def\Weel#1{%\Weel{position}
            \draw[fill=white,shift={(#1)}](0,0)circle (0.3);
            \draw[fill=black!80, even odd rule,shift={(#1)}](0,0) circle (.3) circle (0.2);
            \draw[fill,shift={(#1)}](0,0) circle (0.08);
            \foreach \i in {1,...,12}{\draw[fill,shift={(#1)}](30*\i:0.1)--(30*\i:0.2)--+(90+30*\i:0.02);}        
        }
        
        \def\DuckCar#1#2#3#4[#5]{ %\OrigCAr{position}{orientation~restrcited~values~1~or~-1}{rotation}{color}[ID]
            \begin{scope}[shift={(#1)},xscale=#2,rotate=#3]
                \draw(0,0) coordinate (#5);
                \draw(0,2.2) node[minimum width=5em](#5-top){};%<--Added a point on top named nodename-top
                \shuffleducks\duck[\randomhead,scale=0.8,xshift=-3em,yshift=0.5em];
                \Weel{0.6,0.3}
                \Weel{-0.6,0.3}
                \ifnum#2=-1{\draw(0,0)++(0,2em)node[draw, rounded corners, rotate=-#3, font=\sf\tiny]{#5};}\fi
                \ifnum#2=1{\draw(0,0)++(0,2em)node[draw, rounded corners, rotate=#3, font=\sf\tiny]{#5};}\fi               
            \end{scope}
        }
        
        % drawing the Cars 
        \DuckCar{0,0}{-1}{0}{}[CAR-1]
        \DuckCar{$(CAR-1)+(4,0)$}{-1}{0}{}[CAR-2]
        \DuckCar{$(CAR-2)+(4,0)$}{-1}{0}{}[CAR-3]
        \DuckCar{$(CAR-3)+(4,0)$}{-1}{0}{}[CAR-4]
        \draw($(CAR-4)+(3,0)$) node[scale=3]{$\dots$};
        \draw($(CAR-4)+(6,1)$) node[scale=2.5, draw, thick](L){\scriptsize Leader};
        \Weel{$(L)+(-0.8,-0.7)$}
        \Weel{$(L)+(0.8,-0.7)$}
        
        \draw($(CAR-2)+(0,4)$) node[scale=2.5, draw, thick](C){\scriptsize Controller l};
        
        %Drawing some Arrows
        \draw[Arrow={cyan!40!blue}{1.2}](CAR-1-top.150) |- ($(C)+(-1,2)$) -| (C.150);
        \draw[Arrow={cyan!40!blue}{1.2}](CAR-2-top.150) coordinate (temp) -- (C.-90-|temp);
        \draw[Arrow={cyan!40!blue}{1.2}]($(L.90)+(0,0.5em)$) |- ($(C)+(1,2)$) -| (C.120);
        \draw[Arrow={cyan!40!blue}{1.2}](CAR-4-top.150) |- ($(C)+(1,1.5)$) -| (C.60);
        \draw[Arrow={cyan!40!blue}{1.2}](CAR-3-top.150) |- ($(C)+(1,1)$) -| (C.30);
        %Drawing some repetitive things
        \foreach \txbehind/\Car [count=\j from 1]in {
            i+1/CAR-1,
            node\quad i/CAR-2,
            i-1/CAR-3,
            i-2/CAR-4,
            0/L%
        }{
            \path($(CAR-1)+(0,-0.5)$)coordinate (temp) -- (temp-|\Car.-90) node []{$\txbehind$};
            \ifnum\j<5\draw[Arrow={cyan!40!blue}{1}]($(\Car-top.30)+(0,1)$) -- ++(0,-1)node [midway, anchor=-180]{$U_{\txbehind}$};\fi
            \ifnum\j<4{}\draw[Arrow={red}{1}]($(\Car)+(1.25,0.5)$) -- ++(0.75,0)node [midway, anchor=90]{$V_{\txbehind}$};\fi
        }
    
        \draw[Arrow2=-1,CoilColor=black,Thickness=2mm,W=1.5cm,ArCorr=1.5] ($(CAR-2)+(-0.4,1.5)$) -- ($(CAR-1)+(0.8,1.5)$);
        \draw(b)++(0,0.7em) node {$\tilde{U}_{i+1}$};
        \draw[Arrow2=-1,CoilColor=black,Thickness=2mm,W=1.5cm,ArCorr=1.5] ($(CAR-3)+(-0.4,1.5)$) -- ($(CAR-2)+(0.8,1.5)$);
        \draw(b)++(0,0.7em) node {$\tilde{U}_i$};
        \draw[Arrow2=-1,CoilColor=black,Thickness=2mm,W=1.5cm,ArCorr=1.5] ($(CAR-4)+(-0.4,1.5)$) -- ($(CAR-3)+(0.8,1.5)$);
        \draw(b)++(0,0.7em) node {$\tilde{U}_{i-1}$};
                
    \end{tikzpicture}
\end{document}

관련 정보