tikz - Weitere Parameter zum Makro hinzufügen funktioniert nicht

tikz - Weitere Parameter zum Makro hinzufügen funktioniert nicht

beziehen aufDasAlso, ich möchte eine weitere Matrix hinzufügen, um einen weiteren Würfel zu zeichnen, also möchte ich den Code ändern, aber Parameter verwenden, um die RGB-Koordinate einzurichten (matCC in matPC ändern und als Parameter verwenden). Ich ändere es wie unten, aber die Kompilierung schlägt fehl!

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

Der Kompilierungsfehler:

File ended while scanning use of \pgfkeys@code.

Antwort1

Dies ist eine Version, die funktioniert. Damit es funktioniert,

  • entfernte ein zusätzliches ), dh wurde durch ohne nach code args={(#1,#2,#3),#4)}ersetzt , undcode args={(#1,#2,#3),#4})#4
  • eingehüllt #4in "...", dh \pgfmathparse{RGBvec(#1,#2,#3,#4)}wurde \pgfmathparse{RGBvec(#1,#2,#3,"#4")}.

Ergebnis:

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

Bildbeschreibung hier eingeben

verwandte Informationen