맞춤 장식이 포함된 맞춤 선 스타일

맞춤 장식이 포함된 맞춤 선 스타일

다음과 같은 3D 파이프의 플랜지 버전을 만들고 싶습니다.원래 게시물에 있던 사진. 내 "무차별 대입" 시도는 다음과 같습니다.

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture} 
\definecolor{LPtgrey}{rgb}{.7,.7,.7}
\def\pipesize{1cm}
\def\flangesize{1.75*\pipesize}
\def\ft{0.2} % for flange thickness
\def\fg{0.02} % for flange gap
\def\xx{0.5} % length of middle of bend to inside edge of flange, ie, same as bend radius
\pgfsetcornersarced{\pgfpoint{0.5cm}{0.5cm}}
%pipe
\draw[color=LPtgrey!80!black, line width=\pipesize*0.4] (2,0)--(2,6)--(5,6)--(7,4)--(9,4);%
\draw[color=LPtgrey, line width=\pipesize*0.38] (2,0)--(2,6)--(5,6)--(7,4)--(9,4);%
\draw[color=LPtgrey!85, line width=\pipesize*0.35] (2,0)--(2,6)--(5,6)--(7,4)--(9,4);%
\draw[color=LPtgrey!70, line width=\pipesize*0.32] (2,0)--(2,6)--(5,6)--(7,4)--(9,4);%
\draw[color=LPtgrey!55, line width=\pipesize*0.29] (2,0)--(2,6)--(5,6)--(7,4)--(9,4);%
\draw[color=LPtgrey!45, line width=\pipesize*0.25] (2,0)--(2,6)--(5,6)--(7,4)--(9,4);%
\draw[color=LPtgrey!35, line width=\pipesize*0.20] (2,0)--(2,6)--(5,6)--(7,4)--(9,4);%
%flange 1
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (2,0)--(2,0+\ft);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (2,0)--(2,0+\ft);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (2,0)--(2,0+\ft);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (2,0)--(2,0+\ft);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (2,0)--(2,0+\ft);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (2,0)--(2,0+\ft);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (2,0)--(2,0+\ft);%
%flange 2
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (2,6-\xx-\ft-\fg-\ft)--(2,6-\xx-\ft-\fg);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (2,6-\xx-\ft-\fg-\ft)--(2,6-\xx-\ft-\fg);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (2,6-\xx-\ft-\fg-\ft)--(2,6-\xx-\ft-\fg);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (2,6-\xx-\ft-\fg-\ft)--(2,6-\xx-\ft-\fg);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (2,6-\xx-\ft-\fg-\ft)--(2,6-\xx-\ft-\fg);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (2,6-\xx-\ft-\fg-\ft)--(2,6-\xx-\ft-\fg);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (2,6-\xx-\ft-\fg-\ft)--(2,6-\xx-\ft-\fg);%
%flange 3
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (2,6-\xx-\ft)--(2,6-\xx);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (2,6-\xx-\ft)--(2,6-\xx);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (2,6-\xx-\ft)--(2,6-\xx);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (2,6-\xx-\ft)--(2,6-\xx);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (2,6-\xx-\ft)--(2,6-\xx);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (2,6-\xx-\ft)--(2,6-\xx);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (2,6-\xx-\ft)--(2,6-\xx);%
%flange 4
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (2+\xx,6)--(2+\xx+\ft,6);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (2+\xx,6)--(2+\xx+\ft,6);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (2+\xx,6)--(2+\xx+\ft,6);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (2+\xx,6)--(2+\xx+\ft,6);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (2+\xx,6)--(2+\xx+\ft,6);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (2+\xx,6)--(2+\xx+\ft,6);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (2+\xx,6)--(2+\xx+\ft,6);%
%flange 5
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (2+\xx+\ft+\fg,6)--(2+\xx+\ft+\fg+\ft,6);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (2+\xx+\ft+\fg,6)--(2+\xx+\ft+\fg+\ft,6);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (2+\xx+\ft+\fg,6)--(2+\xx+\ft+\fg+\ft,6);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (2+\xx+\ft+\fg,6)--(2+\xx+\ft+\fg+\ft,6);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (2+\xx+\ft+\fg,6)--(2+\xx+\ft+\fg+\ft,6);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (2+\xx+\ft+\fg,6)--(2+\xx+\ft+\fg+\ft,6);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (2+\xx+\ft+\fg,6)--(2+\xx+\ft+\fg+\ft,6);%
%flange 6
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (5-\xx-\ft-\fg-\ft,6)--(5-\xx-\ft-\fg,6);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (5-\xx-\ft-\fg-\ft,6)--(5-\xx-\ft-\fg,6);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (5-\xx-\ft-\fg-\ft,6)--(5-\xx-\ft-\fg,6);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (5-\xx-\ft-\fg-\ft,6)--(5-\xx-\ft-\fg,6);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (5-\xx-\ft-\fg-\ft,6)--(5-\xx-\ft-\fg,6);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (5-\xx-\ft-\fg-\ft,6)--(5-\xx-\ft-\fg,6);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (5-\xx-\ft-\fg-\ft,6)--(5-\xx-\ft-\fg,6);%
%flange 7
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (5-\xx-\ft,6)--(5-\xx,6);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (5-\xx-\ft,6)--(5-\xx,6);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (5-\xx-\ft,6)--(5-\xx,6);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (5-\xx-\ft,6)--(5-\xx,6);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (5-\xx-\ft,6)--(5-\xx,6);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (5-\xx-\ft,6)--(5-\xx,6);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (5-\xx-\ft,6)--(5-\xx,6);%
%flange 8
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (5+\xx,6-\xx)--(5+\xx+\ft,6-\xx-\ft);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (5+\xx,6-\xx)--(5+\xx+\ft,6-\xx-\ft);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (5+\xx,6-\xx)--(5+\xx+\ft,6-\xx-\ft);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (5+\xx,6-\xx)--(5+\xx+\ft,6-\xx-\ft);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (5+\xx,6-\xx)--(5+\xx+\ft,6-\xx-\ft);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (5+\xx,6-\xx)--(5+\xx+\ft,6-\xx-\ft);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (5+\xx,6-\xx)--(5+\xx+\ft,6-\xx-\ft);%
%flange 9
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (5+\xx+\ft+\fg,6-\xx-\ft-\fg)--(5+\xx+\ft+\fg+\ft,6-\xx-\ft-\fg-\ft);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (5+\xx+\ft+\fg,6-\xx-\ft-\fg)--(5+\xx+\ft+\fg+\ft,6-\xx-\ft-\fg-\ft);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (5+\xx+\ft+\fg,6-\xx-\ft-\fg)--(5+\xx+\ft+\fg+\ft,6-\xx-\ft-\fg-\ft);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (5+\xx+\ft+\fg,6-\xx-\ft-\fg)--(5+\xx+\ft+\fg+\ft,6-\xx-\ft-\fg-\ft);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (5+\xx+\ft+\fg,6-\xx-\ft-\fg)--(5+\xx+\ft+\fg+\ft,6-\xx-\ft-\fg-\ft);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (5+\xx+\ft+\fg,6-\xx-\ft-\fg)--(5+\xx+\ft+\fg+\ft,6-\xx-\ft-\fg-\ft);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (5+\xx+\ft+\fg,6-\xx-\ft-\fg)--(5+\xx+\ft+\fg+\ft,6-\xx-\ft-\fg-\ft);%
%flange 10
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (7-\xx-\ft-\fg-\ft,4+\xx+\ft+\fg+\ft)--(7-\xx-\ft-\fg,4+\xx+\ft+\fg);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (7-\xx-\ft-\fg-\ft,4+\xx+\ft+\fg+\ft)--(7-\xx-\ft-\fg,4+\xx+\ft+\fg);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (7-\xx-\ft-\fg-\ft,4+\xx+\ft+\fg+\ft)--(7-\xx-\ft-\fg,4+\xx+\ft+\fg);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (7-\xx-\ft-\fg-\ft,4+\xx+\ft+\fg+\ft)--(7-\xx-\ft-\fg,4+\xx+\ft+\fg);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (7-\xx-\ft-\fg-\ft,4+\xx+\ft+\fg+\ft)--(7-\xx-\ft-\fg,4+\xx+\ft+\fg);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (7-\xx-\ft-\fg-\ft,4+\xx+\ft+\fg+\ft)--(7-\xx-\ft-\fg,4+\xx+\ft+\fg);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (7-\xx-\ft-\fg-\ft,4+\xx+\ft+\fg+\ft)--(7-\xx-\ft-\fg,4+\xx+\ft+\fg);%
%flange 11
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (7-\xx-\ft,4+\xx+\ft)--(7-\xx,4+\xx);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (7-\xx-\ft,4+\xx+\ft)--(7-\xx,4+\xx);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (7-\xx-\ft,4+\xx+\ft)--(7-\xx,4+\xx);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (7-\xx-\ft,4+\xx+\ft)--(7-\xx,4+\xx);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (7-\xx-\ft,4+\xx+\ft)--(7-\xx,4+\xx);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (7-\xx-\ft,4+\xx+\ft)--(7-\xx,4+\xx);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (7-\xx-\ft,4+\xx+\ft)--(7-\xx,4+\xx);%
%flange 12
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (7+\xx,4)--(7+\xx+\ft,4);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (7+\xx,4)--(7+\xx+\ft,4);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (7+\xx,4)--(7+\xx+\ft,4);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (7+\xx,4)--(7+\xx+\ft,4);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (7+\xx,4)--(7+\xx+\ft,4);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (7+\xx,4)--(7+\xx+\ft,4);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (7+\xx,4)--(7+\xx+\ft,4);%
%flange 13
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (7+\xx+\ft+\fg,4)--(7+\xx+\ft+\fg+\ft,4);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (7+\xx+\ft+\fg,4)--(7+\xx+\ft+\fg+\ft,4);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (7+\xx+\ft+\fg,4)--(7+\xx+\ft+\fg+\ft,4);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (7+\xx+\ft+\fg,4)--(7+\xx+\ft+\fg+\ft,4);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (7+\xx+\ft+\fg,4)--(7+\xx+\ft+\fg+\ft,4);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (7+\xx+\ft+\fg,4)--(7+\xx+\ft+\fg+\ft,4);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (7+\xx+\ft+\fg,4)--(7+\xx+\ft+\fg+\ft,4);%
%flange 14
\draw[color=LPtgrey!80!black, line width=\flangesize*0.4] (9-\ft,4)--(9,4);%
\draw[color=LPtgrey, line width=\flangesize*0.38] (9-\ft,4)--(9,4);%
\draw[color=LPtgrey!85, line width=\flangesize*0.35] (9-\ft,4)--(9,4);%
\draw[color=LPtgrey!70, line width=\flangesize*0.32] (9-\ft,4)--(9,4);%
\draw[color=LPtgrey!55, line width=\flangesize*0.29] (9-\ft,4)--(9,4);%
\draw[color=LPtgrey!45, line width=\flangesize*0.25] (9-\ft,4)--(9,4);%
\draw[color=LPtgrey!35, line width=\flangesize*0.20] (9-\ft,4)--(9,4);%
\end{tikzpicture}
\end{document}

결과는 괜찮습니다.

플랜지 파이프

90도 회전에서는 무차별 대입이 가능하지만 45도 각도에서는 플랜지가 너무 두꺼워집니다. 다른 각도에서는 플랜지 위치를 계산하기 위해 너무 많은 삼각법이 필요합니다.

  1. 5개의 겹치는 선을 조합한 "선 스타일"을 정의하는 방법이 있어야 합니다(방법은 모르겠습니다).

  2. 원하는 결과를 얻으려면 각 선(또는 폴리선의 각 노드)을 종료하는 사용자 정의 장식을 정의하는 방법이 있어야 합니다. 장식이 선과 같은 각도로 회전할까요?

이상적으로는 다음과 같은 코드를 사용하고 싶습니다.

\draw[pipe,style=flange,diameter=3cm](2,0)--(2,6)--(5,6);

플랜지 배치와 관련된 모든 수학이 처리됩니다. 나는 가까운 장래에 많은 파이프 다이어그램을 그릴 것이며 이를 더 쉽게 만들어주는 유용한 코드에 감사하겠습니다.

답변1

여기서는 두 가지 접근 방식을 보여줍니다. 둘 다 서로 다른 선 너비와 색상을 가진 키를 반복적으로 사용하여 preaction파이프(및 플랜지)를 그립니다. 첫 번째 접근 방식은 markings장식을 사용하여 postaction플랜지를 배치합니다. 두 번째는 show path construction장식을 사용하여 세그먼트의 시작과 끝 부분에 플랜지를 배치 lineto합니다 curveto.

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.markings,decorations.pathreplacing,calc}
\makeatletter
\tikzset{every pipe/.code={%
  \pgfmathloop
  \ifnum\pgfmathcounter>20
  \else
    \pgfmathsetmacro\i{\pgfmathcounter}%
    \pgfmathsetmacro\j{80-\pgfmathcounter*3}%
    \tikzset{preaction/.expanded={line width=(\pipewidth)*(1-\i*\i/500),
        draw=black!50!white!\j!white}}%
  \repeatpgfmathloop
},
every flange/.style 2 args={insert path={
  let \p1=(#1), \p2=(#2),\n1={atan2(\y2-\y1, \x2-\x1)} in
    [shift={(\p1)}, rotate=\n1, pipe width={(\pipewidth)*4/3}, every pipe] 
      (0.01,0) -- (0.2,0)
}},
flanges/.style={postaction={%
  /utils/exec={
    \@for\pos:=#1\do{%
      \tikzset{decoration/.expanded={markings,
        mark=at position \pos\space with {
          \noexpand\path [pipe width=\pipewidth*4/3, every pipe] (0.01,0) -- (0.2,0);
    }}}}}, 
  decorate}},
pipe width/.code=\pgfmathsetlengthmacro\pipewidth{#1},
pipes/.style={
  every pipe,
  postaction={decoration={show path construction,
    lineto code={
      \path [every flange={\tikzinputsegmentfirst}{\tikzinputsegmentlast}];
      \path [every flange={\tikzinputsegmentlast}{\tikzinputsegmentfirst}];
    },
    curveto code={
      \path [every flange={\tikzinputsegmentfirst}{\tikzinputsegmentsupporta}];
      \path [every flange={\tikzinputsegmentlast}{\tikzinputsegmentsupportb}];
    }
}, decorate}},
pipe/.style={
  every pipe,
  flanges={0, 1}
}}
\begin{document}
\begin{tikzpicture}[line join=round, pipe width=0.5cm]
\path [pipes] (0,4) -- (0,1) arc (180:330:1) (-1,3) -- (1,3);
\path [pipes] (3,-1/3) -- (3,2);
\path [pipes] (4,-1/3) -- (4,4);
\path [pipe]  (11/2,3) -- (4,5/4) -- (11/2,0);
\path [pipe]  (13/2,5/2) -- (8,5/2) -- (13/2,0) -- (8,0);
\path [pipes] (4,2) ellipse [x radius=6, y radius=4];
\end{tikzpicture}
\end{document}

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

관련 정보