동일한 tikzpicture 내의 여러 이미지를 그리는 경우 좌표를 올바르게 변환하는 방법은 무엇입니까?

동일한 tikzpicture 내의 여러 이미지를 그리는 경우 좌표를 올바르게 변환하는 방법은 무엇입니까?

수행원TikZ로 이미지 그리기, 나는 그림을 그리는 데 성공한 사례를 많이 보았습니다.TikZ.

tikzpicture그러나 지금은 다음과 같은 환경이 있습니다.여러 개의그래픽이 있고 그 각각에 그림을 그리고 싶습니다. 그러나 제공되는 솔루션은 다음과 같습니다.TikZ로 이미지 그리기(0, 0) 중심의 그림에만 작동합니다. 두 번째 그림에 그리려고 하면 좌표가 예상대로 작동하지 않기 때문입니다.

\documentclass[final, 12pt]{standalone}
\usepackage{tikz}
\newcommand{\helplines}[0]{
\draw[help lines,semithick,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
}
\begin{document}%
\begin{tikzpicture}%
\node[anchor=south west,inner sep=0] (image1) at (0, 0)
    {\rule{3cm}{3cm}};
\begin{scope}[x={(image1.south east)},y={(image1.north west)}]
 % draw stuff
 %\helplines
\end{scope}
\node[anchor=south west,inner sep=0] (image2) at (image1.south east)
    {\rule{3cm}{3cm}};
\begin{scope}[x={(image2.south east)},y={(image2.north west)}]
 \helplines
 % draw more stuff, but coordinates do not map as desired
\end{scope}
\end{tikzpicture}
\end{document}

결과:

원하는 효과가 아님

그림의 왼쪽 하단에 원점이 있고 오른쪽 상단에 점 (1, 1)이 있는 변환된 좌표계를 원합니다. 이는 (0, 0)에 있는 그림에는 작동하지만 바로 오른쪽에 있는 이미지에는 작동하지 않습니다. 왜 안 됩니까? 원하는 효과를 얻으려면 어떻게 해야 합니까?

답변1

이는 단위 벡터의 크기를 조정 x=... , y=....하지만 두 번째 이미지의 인수가 직교 벡터가 아니기 때문입니다. 왜냐하면 다른 곳에 있고 좌표 유형이 아니기 image2때문입니다 . 대신에 0이 아닌 항목을 가진 벡터입니다. 이것이 바로 좌표가 수평/수직이 아닌 대각선인 이유입니다.(x0,0)(0,y0)

동일한 작업을 수행하려면 해당 x또는 y구성 요소를 0으로 설정해야 합니다. 예

\documentclass[final, 12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\helplines}[0]{
\draw[help lines,semithick,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {\tiny .\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {\tiny .\y}; }
}
\begin{document}%
\begin{tikzpicture}%
\node[anchor=south west,inner sep=0] (image1) at (0, 0)
    {\color{red}\rule{3cm}{3cm}};
\begin{scope}[x={(image1.south east)},y={(image1.north west)}]
 % draw stuff
 \helplines
\end{scope}
\node[anchor=south west,inner sep=0] (image2) at (image1.south east)
    {\color{blue}\rule{3cm}{3cm}};
\begin{scope}[
x={($(image2.north east)-(image2.north west)$)},
y={($(image2.north west)-(image2.south west)$)},
shift={(image2.south west)}]
 \helplines
 \end{scope}
\end{tikzpicture}
\end{document}

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

여기서는 라이브러리를 사용하여 calc이미지의 너비와 높이를 얻었습니다. 그러나 모든 것이 로컬에서 동일하게 정의되도록 범위에 이미지를 포함하면 이러한 모든 문제를 피할 수 있습니다. 그런 다음 해당 범위를 이동합니다. 예:

\documentclass[tikz]{standalone}
\newcommand{\helplines}[0]{
\draw[help lines,semithick,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {\tiny .\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east]  at (0,\y/10) {\tiny .\y}; }
}
\begin{document}%
\begin{tikzpicture}%
\node[anchor=south west,inner sep=0] (image1) at (0, 0)
    {\color{red}\rule{3cm}{3cm}};
\begin{scope}[x={(image1.south east)},y={(image1.north west)}]
 % draw stuff
 \helplines
\end{scope}

\begin{scope}[shift={(image1.south east)}] % Shift the scope

    \node[anchor=south west,inner sep=0] (image2) at (0,0) %still at the origin of this scope
        {\color{blue}\rule{3cm}{3cm}};
    \begin{scope}[x={(image2.south east)},y={(image2.north west)}]
     \helplines
    \end{scope}

\end{scope}
\end{tikzpicture}
\end{document}

이는 동일한 출력을 제공합니다.

관련 정보