Tikz:使用从宏返回的坐标

Tikz:使用从宏返回的坐标

如何使用从宏返回的坐标(例如,使用移位)?请参阅以下 MWE。我尝试更改所涉及分隔符的定义位置(在宏内或宏外),但总是出现错误。

\documentclass{standalone}

\usepackage{tikz,tikz-3dplot}

\newcommand{\coordsToVec}[3]{(${e#1}*(e1)+{e#2}*(e2)+{e#3}*(e3)$)}

\begin{document}

  \begin{tikzpicture}
    \tdplotsetmaincoords{0}{60}
    \begin{scope}[tdplot_main_coords]
      \coordinate (e1) at (1,0,0);
      \coordinate (e2) at (0,1,0);
      \coordinate (e3) at (0,0,1);
      \begin{scope}[shift={(${1}*(e1)+{0}*(e2)+{0}*(e3)$)}] % WORKS
      \end{scope}
      \begin{scope}[shift={\coordsToVec{1}{0}{0}}] % DOES NOT WORK
      \end{scope}
    \end{scope}
  \end{tikzpicture}

\end{document}

答案1

你可以shift to vec用 3 个参数定义样式:

\documentclass{standalone}
\usepackage{tikz,tikz-3dplot}

\tikzset{
  shift to vec/.style n args={3}{
    shift={(${#1}*(e1)+{#2}*(e2)+{#3}*(e3)$)},
  },
}

\begin{document}
  \begin{tikzpicture}
    \tdplotsetmaincoords{0}{60}
    \begin{scope}[tdplot_main_coords]
      \coordinate (e1) at (1,0,0);
      \coordinate (e2) at (0,1,0);
      \coordinate (e3) at (0,0,1);
      \begin{scope}[shift={(${1}*(e1)+{0}*(e2)+{0}*(e3)$)}] % WORKS
      \end{scope}
      \begin{scope}[shift to vec={1}{0}{0}] % WORKS
      \end{scope}
    \end{scope}
  \end{tikzpicture}
\end{document}

相关内容