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}

여기에 이미지 설명을 입력하세요

물론 표면은 아닙니다.

관련 정보