TIKZ 인수에서 특정 체인을 캡처하는 방법

TIKZ 인수에서 특정 체인을 캡처하는 방법

저는 다양한 종류의 3D 좌표를 그리는 매크로를 만들었습니다(여기서는 sistemaTd & sistemaT2). tikz에 포함된 시스템을 사용할 때 Y축의 범례가 잘못된 위치에 있습니다.

다양한 파일에서 수백 번 사용해봤기 \eixo때문에 인수 개수를 변경하지 않고 방법을 찾고 싶습니다.

나는 정의에 다음과 같은 것이 필요하다고 생각합니다 \eixo.

IF #2 contains the chain "sistema" DO pos="below" ELSE pos="right" ENDIF

이것은 예입니다:

\documentclass{article}

\usepackage{tikz}
\usepackage{ifthen}
\tikzset{sistemaTd/.style={y={(1 cm,0 cm)},z={(0 cm, 1 cm)},x={(-0.5 cm, -0.5 cm)}}}
\tikzset{sistemaTe/.style={x={(0 cm,1 cm)},y={(1 cm, 0 cm)},z={(-0.5 cm, -0.5 cm)}}}
%eixo{dim}{color, etc} Ejemplo: \texttt{eixo}{black!80,sistemaTd,-latex...}
\newcommand{\eixo}[2]{
    \begin{scope}[->,#2]
        \draw (0,0,0) -- (#1,0,0) node[right]{$X$};
        \draw (0,0,0) -- (0,#1,0) node[below]{$Y$}; %node[below]{$Y$}
        \draw (0,0,0) -- (0,0,#1) node[right]{$Z$};
    \end{scope}
}
\begin{document}
    \begin{tikzpicture}
        \eixo{3}{gray,sistemaTd}
        \begin{scope}[xshift=5.5cm]
            \eixo{3}{gray,sistemaTe}
        \end{scope}
        \begin{scope}[xshift=11cm]
            \eixo{3}{gray} %note the legend of Y axis
        \end{scope}     
    \end{tikzpicture}
\end{document}

답변1

여기서는 string-separator를 listofitems검색하는 데 사용합니다 . 그것을 찾으면(목록 길이가 1보다 큰 것으로 입증됨) 지정자를 사용하고 , 그렇지 않으면 를 사용합니다 .#2sistemabelowright

\documentclass{article}

\usepackage{tikz}
\usepackage{ifthen,listofitems}
\tikzset{sistemaTd/.style={y={(1 cm,0 cm)},z={(0 cm, 1 cm)},x={(-0.5 cm, -0.5 cm)}}}
\tikzset{sistemaTe/.style={x={(0 cm,1 cm)},y={(1 cm, 0 cm)},z={(-0.5 cm, -0.5 cm)}}}
%eixo{dim}{color, etc} Ejemplo: \texttt{eixo}{black!80,sistemaTd,-latex...}
\newcommand{\eixo}[2]{
    \begin{scope}[->,#2]
        \draw (0,0,0) -- (#1,0,0) node[right]{$X$};
  \setsepchar{sistema}%
  \readlist\argtwo{#2}%
  \ifnum\listlen\argtwo[]>1\relax
        \draw (0,0,0) -- (0,#1,0) node[below]{$Y$};
  \else
        \draw (0,0,0) -- (0,#1,0) node[right]{$Y$};
  \fi
        \draw (0,0,0) -- (0,0,#1) node[right]{$Z$};
    \end{scope}
}
\begin{document}
    \begin{tikzpicture}
        \eixo{3}{gray,sistemaTd}
        \begin{scope}[xshift=5.5cm]
            \eixo{3}{gray,sistemaTe}
        \end{scope}
        \begin{scope}[xshift=11cm]
            \eixo{3}{gray} %note the legend of Y axis
        \end{scope}     
    \end{tikzpicture}
\end{document}

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

문제를 올바르게 이해한 경우 X 레이블 위치도 조정하는 버전은 다음과 같습니다.

\documentclass{article}

\usepackage{tikz}
\usepackage{ifthen,listofitems}
\tikzset{sistemaTd/.style={y={(1 cm,0 cm)},z={(0 cm, 1 cm)},x={(-0.5 cm, -0.5 cm)}}}
\tikzset{sistemaTe/.style={x={(0 cm,1 cm)},y={(1 cm, 0 cm)},z={(-0.5 cm, -0.5 cm)}}}
%eixo{dim}{color, etc} Ejemplo: \texttt{eixo}{black!80,sistemaTd,-latex...}
\newcommand{\eixo}[2]{
    \begin{scope}[->,#2]
  \setsepchar{sistema}%
  \readlist\argtwo{#2}%
  \ifnum\listlen\argtwo[]>1\relax
        \draw (0,0,0) -- (#1,0,0) node[right]{$X$};
        \draw (0,0,0) -- (0,#1,0) node[below]{$Y$}; 
  \else
        \draw (0,0,0) -- (#1,0,0) node[below]{$X$};
        \draw (0,0,0) -- (0,#1,0) node[right]{$Y$};
  \fi
        \draw (0,0,0) -- (0,0,#1) node[right]{$Z$};
    \end{scope}
}
\begin{document}
    \begin{tikzpicture}
        \eixo{3}{gray,sistemaTd}
        \begin{scope}[xshift=5.5cm]
            \eixo{3}{gray,sistemaTe}
        \end{scope}
        \begin{scope}[xshift=11cm]
            \eixo{3}{gray} %note the legend of Y axis
        \end{scope}     
    \end{tikzpicture}
\end{document}

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

답변2

calc축이 수평인지 수직인지 그 자리에서 확인( )하여 해당 정보에 따라 라벨을 부착할 수 있습니다 . 이렇게 하면 좌표계를 더 추가하거나 정의를 변경해도 계속 작동합니다.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc}
\tikzset{sistemaTd/.style={y={(1 cm,0 cm)},z={(0 cm, 1 cm)},x={(-0.5 cm, -0.5 cm)}}}
\tikzset{sistemaTe/.style={x={(0 cm,1 cm)},y={(1 cm, 0 cm)},z={(-0.5 cm, -0.5 cm)}}}
%eixo{dim}{color, etc} Ejemplo: \texttt{eixo}{black!80,sistemaTd,-latex...}
\newcommand{\eixo}[2]{
    \begin{scope}[->,#2]
        \draw (0,0,0) -- (#1,0,0) 
        let \p1=($(#1,0,0)-(0,0,0)$),\n1={abs(sin(atan2(\y1,\x1))))} in
        \ifdim\n1<0.4pt [below] \else [right] \fi node  {$X$};
        \draw (0,0,0) -- (0,#1,0) let \p1=($(0,#1,0)-(0,0,0)$),\n1={abs(sin(atan2(\y1,\x1))))} in
        \ifdim\n1<0.4pt [below] \else [right] \fi node {$Y$}; 
        \draw (0,0,0) -- (0,0,#1) let \p1=($(0,0,#1)-(0,0,0)$),\n1={abs(sin(atan2(\y1,\x1))))} in
        \ifdim\n1<0.4pt [below] \else [right] \fi node{$Z$};
    \end{scope}
}
\begin{document}
    \begin{tikzpicture}
        \eixo{3}{gray,sistemaTd}
        \begin{scope}[xshift=5.5cm]
            \eixo{3}{gray,sistemaTe}
        \end{scope}
        \begin{scope}[xshift=11cm]
            \eixo{3}{gray} %note the legend of Y axis
        \end{scope}     
    \end{tikzpicture}
\end{document}

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

관련 정보