tikz: Agregar más parámetros a la macro no funciona

tikz: Agregar más parámetros a la macro no funciona

Referirse aesteEntonces, deseo agregar una matriz más para dibujar otro cúbico, así que deseo cambiar el código pero usar el parámetro para configurar la coordenada RGB (cambiar matCC a matPC y usarlo como parámetro). ¡Lo cambio como se muestra a continuación pero falla la compilación!

\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}

El error de compilación:

File ended while scanning use of \pgfkeys@code.

Respuesta1

Esta es una versión que funciona. Para que funcione, yo

  • se eliminó un extra ), es decir, code args={(#1,#2,#3),#4)}se reemplazó por code args={(#1,#2,#3),#4}sin )después #4, y
  • envuelto #4en "...", es decir, \pgfmathparse{RGBvec(#1,#2,#3,#4)}convertido en \pgfmathparse{RGBvec(#1,#2,#3,"#4")}.

Resultado:

\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}

ingrese la descripción de la imagen aquí

información relacionada