tikz - 매크로에 더 많은 매개변수를 추가하면 작동하지 않습니다.

tikz - 매크로에 더 많은 매개변수를 추가하면 작동하지 않습니다.

인용하다이것그래서 다른 큐빅을 그리기 위해 행렬을 하나 더 추가하고 싶기 때문에 코드를 변경하고 싶지만 매개변수를 사용하여 RGB 좌표를 설정합니다(matCC를 matPC로 변경하고 매개변수로 사용). 아래와 같이 변경했는데 컴파일 실패!

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\def\matPC{{0.257, 0.504, 0.098},% 
    {-0.148, -0.291, 0.439},%
    {0.439, -0.368,0.071}}%
\pgfmathdeclarefunction{RGBvec}{4}{% r,g,b,mat
    \begingroup%
    \pgfmathsetmacro{\myY}{16+{#4}[0][0]*#1+{#4}[0][1]*#2+{#4}[0][2]*#3}%
    \pgfmathsetmacro{\myCb}{128+{#4}[1][0]*#1+{#4}[1][1]*#2+{#4}[1][2]*#3}%
    \pgfmathsetmacro{\myCr}{128+{#4}[2][0]*#1+{#4}[2][1]*#2+{#4}[2][2]*#3}%
    \edef\pgfmathresult{\myCr,\myCb,\myY}%
    \pgfmathsmuggle\pgfmathresult\endgroup%
}%

\begin{document}
    \tdplotsetmaincoords{70}{110}
    \begin{tikzpicture}[bullet/.style={circle,inner
        sep=2pt,fill},line cap=round,line join=round,
    RGB coordinate/.code args={(#1,#2,#3),#4)}{\pgfmathparse{RGBvec(#1,#2,#3,#4)}%
        \tikzset{insert path={(\pgfmathresult)}}},font=\sffamily,thick]
    \begin{scope}[tdplot_main_coords,scale=1/40]
    \draw[-stealth] (0,0,0) coordinate (O) -- (280,0,0) coordinate[label=below:Cr] (Cr);
    \draw[-stealth]  (O) -- (0,280,0) coordinate[label=below:Cb] (Cb);
    \draw[-stealth]  (O) -- (0,0,280) coordinate[label=left:Y] (Y);
    \path [RGB coordinate={(255,255,255),\matPC}] node[bullet,draw,fill=white] (white){}
    [RGB coordinate={(0,0,0),\matPC}] node[bullet] (black){}
    [RGB coordinate={(255,0,0),\matPC}] node[bullet,red] (red){}
    [RGB coordinate={(0,255,0),\matPC}] node[bullet,green] (green){}
    [RGB coordinate={(0,0,255),\matPC}] node[bullet,blue] (blue){}
    [RGB coordinate={(255,0,255),\matPC}] node[bullet,magenta] (magenta){}
    [RGB coordinate={(255,255,0),\matPC}] node[bullet,yellow] (yellow){}
    [RGB coordinate={(0,255,255),\matPC}] node[bullet,cyan] (cyan){};
    \draw (red) -- (black) -- (blue) -- (magenta) -- (red) -- (yellow) 
    -- (green) edge (black) -- (cyan) edge (blue) -- (white)  edge (magenta) -- (yellow); 
    \draw[thin] (255,0,0) node[left]{255} -- (255,255,0) -- (0,255,0) node[above]{255}
    (0,0,255) node[left]{255} -- (255,0,255) edge (255,0,0)
    -- (255,255,255)  edge (255,255,0) -- (0,255,255)  edge (0,255,0)
    -- cycle ;
    \end{scope}  
    \end{tikzpicture}
\end{document}

컴파일 오류:

File ended while scanning use of \pgfkeys@code.

답변1

이것은 작동하는 버전입니다. 나는 그것을 작동시키기 위해

  • extra 를 제거했습니다 ). 즉, after 없이 code args={(#1,#2,#3),#4)}대체되었습니다 .code args={(#1,#2,#3),#4})#4
  • #4에 싸여 "...", 즉 \pgfmathparse{RGBvec(#1,#2,#3,#4)}가 되었습니다 \pgfmathparse{RGBvec(#1,#2,#3,"#4")}.

결과:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\def\matPC{{0.257, 0.504, 0.098},% 
    {-0.148, -0.291, 0.439},%
    {0.439, -0.368,0.071}}%
\pgfmathdeclarefunction{RGBvec}{4}{% r,g,b,mat
    \begingroup%
    \pgfmathsetmacro{\myY}{16+{#4}[0][0]*#1+{#4}[0][1]*#2+{#4}[0][2]*#3}%
    \pgfmathsetmacro{\myCb}{128+{#4}[1][0]*#1+{#4}[1][1]*#2+{#4}[1][2]*#3}%
    \pgfmathsetmacro{\myCr}{128+{#4}[2][0]*#1+{#4}[2][1]*#2+{#4}[2][2]*#3}%
    \edef\pgfmathresult{\myCr,\myCb,\myY}%
    \pgfmathsmuggle\pgfmathresult\endgroup%
}%

\begin{document}
    \tdplotsetmaincoords{70}{110}
    \begin{tikzpicture}[bullet/.style={circle,inner
        sep=2pt,fill},line cap=round,line join=round,
    RGB coordinate/.code args={(#1,#2,#3),#4}{\pgfmathparse{RGBvec(#1,#2,#3,"#4")}%
        \tikzset{insert path={(\pgfmathresult)}}},font=\sffamily,thick]
    \begin{scope}[tdplot_main_coords,scale=1/40]
    \draw[-stealth] (0,0,0) coordinate (O) -- (280,0,0) coordinate[label=below:Cr] (Cr);
    \draw[-stealth]  (O) -- (0,280,0) coordinate[label=below:Cb] (Cb);
    \draw[-stealth]  (O) -- (0,0,280) coordinate[label=left:Y] (Y);
    \path [RGB coordinate={(255,255,255),\matPC}] node[bullet,draw,fill=white] (white){}
    [RGB coordinate={(0,0,0),\matPC}] node[bullet] (black){}
    [RGB coordinate={(255,0,0),\matPC}] node[bullet,red] (red){}
    [RGB coordinate={(0,255,0),\matPC}] node[bullet,green] (green){}
    [RGB coordinate={(0,0,255),\matPC}] node[bullet,blue] (blue){}
    [RGB coordinate={(255,0,255),\matPC}] node[bullet,magenta] (magenta){}
    [RGB coordinate={(255,255,0),\matPC}] node[bullet,yellow] (yellow){}
    [RGB coordinate={(0,255,255),\matPC}] node[bullet,cyan] (cyan){};
    \draw (red) -- (black) -- (blue) -- (magenta) -- (red) -- (yellow) 
    -- (green) edge (black) -- (cyan) edge (blue) -- (white)  edge (magenta) -- (yellow); 
    \draw[thin] (255,0,0) node[left]{255} -- (255,255,0) -- (0,255,0) node[above]{255}
    (0,0,255) node[left]{255} -- (255,0,255) edge (255,0,0)
    -- (255,255,255)  edge (255,255,0) -- (0,255,255)  edge (0,255,0)
    -- cycle ;
    \end{scope}  
    \end{tikzpicture}
\end{document}

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

관련 정보