tikz - Matrixberechnung mit pgfplot verwenden

tikz - Matrixberechnung mit pgfplot verwenden

Ich versuche, ein Matrixberechnungsmakro in pgfplots zu verwenden, aber es bleibt beim Kompilieren hängen!

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

Wie führt man eine solche Berechnung in pgfplots richtig durch?

Ich verwende es lieber so: \T(0,0,50), bin mir aber nicht sicher, ob das möglich ist!

Antwort1

Sie müssen \addplotetwas anderes bereitstellen. So funktioniert es beispielsweise:

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

Bildbeschreibung hier eingeben

Es ist natürlich keine Oberfläche.

verwandte Informationen