tikz를 사용하여 .pic에 화살표 및 라벨 위치 지정

tikz를 사용하여 .pic에 화살표 및 라벨 위치 지정

비슷한 종류의 그림이 반복적으로 포함되어 있는 도형을 그리려고 합니다. 따라서 다음과 같은 방법 .pic으로 제공을 사용하고 있습니다 .tikz

\documentclass[tikz, border=2px]{standalone}
\usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

% define colors and other constants
\colorlet{line color}{black!30}
\def\line thickness{1pt}

% define primitive shapes for the drawing
\tikzset{
line/.style={
    -, draw=line color, line width=\line thickness},
z plus joint/.pic={
    \draw[black, line width=\line thickness, fill=gray!50]  (0,0)
          circle (0.5);
    \draw[black, line width=\line thickness, fill=white]  (0,0) circle (0.3);
    \draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}] 
          (270:0.4) arc (270:150:0.4);
    \draw[latex-,blue, shorten <=2pt] (-0.5, 0.5) -- ++ (-0.5, 0.5) 
          node[above=2pt, black]{#1};
         },
z minus joint/.pic={
    \pic[yscale=-1, rotate=180] {z plus joint=#1};},
}


\begin{document}
\begin{tikzpicture}[node distance=2cm]
    \path[line] (0, 0) pic {z plus joint=1} --
                (2, 0) pic {z minus joint=3} --
                (4, 0) pic {z minus joint=2} --
                (4, 2) pic {z plus joint=4} --
                (4, 4) pic {z minus joint=6};
\end{tikzpicture}
\end{document}

생성된 그림은 아래를 참조하세요.

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

화살표에는 다음 두 가지 유형의 방향이 필요합니다.

  • 왼쪽 제목 화살표
  • 오른쪽 제목 화살표

화살표의 방향을 결정할 수 있는 추가 인수를 그림에 제공할 수 있는 방법을 찾고 있습니다.예를 들어 다음 의사 코드를 참조하세요.

\begin{tikzpicture}[node distance=2cm]
    \path[line] (0, 0) pic {z plus joint={1}{right}} --
                (2, 0) pic {z minus joint={3}{right}} --
                (4, 0) pic {z minus joint={2}{left}} --
                (4, 2) pic {z plus joint={4}{left}} --
                (4, 4) pic {z minus joint={6}{left}};
\end{tikzpicture}

추신: 방향에는 두 가지 가능한 값, 즉 left및 가 있으므로 다음과 같이 right가질 수 있습니다.leftdefault

답변1

이 같은? -1왼쪽과 1오른쪽.

\documentclass[tikz, border=2px]{standalone}
\usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

% define colors and other constants
\colorlet{line color}{black!30}
\def\line thickness{1pt}

% define primitive shapes for the drawing
\tikzset{
line/.style={
    -, draw=line color, line width=\line thickness},    
pics/z plus joint/.style n args={2}{code={
    \draw[black, line width=\line thickness, fill=gray!50]  (0,0)
          circle (0.5);
    \draw[black, line width=\line thickness, fill=white]  (0,0) circle (0.3);
    \draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}] 
          (270:0.4) arc (270:150:0.4);
    \draw[latex-,blue, shorten <=2pt] (0.5*#2, 0.5) -- ++ (0.5*#2, 0.5) 
          node[above=2pt, black]{#1};
         }},
pics/z minus joint/.style n args={2}{code={
    \pic[yscale=-1, rotate=180] {z plus joint={#1}{-1*#2}};}},
}


\begin{document}
\begin{tikzpicture}[node distance=2cm]
    \path[line] (0, 0) pic {z plus joint={1}{1}}
     --         (2, 0) pic {z minus joint={3}{1}} --
                (4, 0) pic {z minus joint={2}{-1}} --
                (4, 2) pic {z plus joint={4}{-1}} --
                (4, 4) pic {z minus joint={6}{-1}}
                ;
\end{tikzpicture}
\end{document}

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

관련 정보