tikz - pgfplot で行列計算を使用する

tikz - pgfplot で行列計算を使用する

pgfplots で行列計算マクロを使用しようとしましたが、コンパイル時にハングしてしまいます。

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\def\M{{2, 1, 1},% 
    {1, 2, 1},%
    {1, 1, 2}}%
\pgfmathdeclarefunction{F}{3}{%
    \begingroup%
    \pgfmathsetmacro{\X}{{\M}[0][0]*#1+{\M}[0][1]*#2+{\M}[0][2]*#3}%
    \pgfmathsetmacro{\Y}{{\M}[1][0]*#1+{\M}[1][1]*#2+{\M}[1][2]*#3}%
    \pgfmathsetmacro{\Z}{{\M}[2][0]*#1+{\M}[2][1]*#2+{\M}[2][2]*#3}%
    \edef\pgfmathresult{(\X,\Y,\Z)}%
    \pgfmathsmuggle\pgfmathresult\endgroup%
}%
\newcommand{\T}[3]{
    \pgfmathparse{F(#1,#2,#3)}\pgfmathresult
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3[surf] coordinates {
    \T{0}{0}{50} % <- output coordinates
    \T{0}{50}{0}
    \T{50}{0}{0} };
\end{axis}
\end{tikzpicture}
\end{document}

pgfplots でこのような計算を行う正しい方法は何ですか?

私は次のように使用することを好みます: \T(0,0,50) ですが、それが可能かどうかはわかりません。

答え1

少し異なるものを提供する必要があります\addplot。たとえば、これは機能します:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\def\M{{2, 1, 1},% 
    {1, 2, 1},%
    {1, 1, 2}}%
\pgfmathdeclarefunction{F}{3}{%
    \begingroup%
    \pgfmathsetmacro{\X}{{\M}[0][0]*#1+{\M}[0][1]*#2+{\M}[0][2]*#3}%
    \pgfmathsetmacro{\Y}{{\M}[1][0]*#1+{\M}[1][1]*#2+{\M}[1][2]*#3}%
    \pgfmathsetmacro{\Z}{{\M}[2][0]*#1+{\M}[2][1]*#2+{\M}[2][2]*#3}%
    \edef\pgfmathresult{(\X,\Y,\Z)}%
    \pgfmathsmuggle\pgfmathresult\endgroup%
}%
\newcommand{\T}[3]{
    \pgfmathparse{F(#1,#2,#3)}\pgfmathresult
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\edef\mylst{"0,0,50","0,50,0","50,0,0"}
\pgfplotsforeachungrouped \XX in {0,1,2}
{
\pgfmathparse{{\mylst}[\XX]}
\pgfmathparse{F(\pgfmathresult)}
\ifnum\XX=0
\edef\mycoords{\pgfmathresult}
\else
\edef\mycoords{\mycoords \pgfmathresult}
\fi}
\addplot3[surf] coordinates {\mycoords};
\end{axis}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

もちろん、それは表面ではありません。

関連情報