tikz - usa cálculo matricial con pgfplot

tikz - usa cálculo matricial con pgfplot

Intento usar una macro de cálculo matricial en pgfplots pero se bloquea al compilar.

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

¿Cuál es la forma correcta de realizar dichos cálculos en pgfplots?

Prefiero usarlo como: \T(0,0,50) ¡pero no estoy seguro de que sea posible!

Respuesta1

Necesitas proporcionar \addplotalgo ligeramente diferente. Por ejemplo, esto funciona:

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

ingrese la descripción de la imagen aquí

Por supuesto, no es una superficie.

información relacionada