tikz를 사용한 복잡한 3D 도면

tikz를 사용한 복잡한 3D 도면

나는 이미 를 사용하여 다음 그림을 제작했습니다 TikZ. 여기에 이미지 설명을 입력하세요 이를 위해 찾은 Sudoku 예제를 수정했습니다.여기다음과 같이:

\documentclass{standalone}

\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}

\begin{document}

\fontsize{5}{6}

\begin{tikzpicture}[>=stealth,every node/.style={minimum size=1cm},on grid]

\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5]
  \shade[right color=gray!10, left color=black!50] (0,0) rectangle +(3,3);
\end{scope}

\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]
  \shade[right color=gray!70,left color=gray!10] (3,-3) rectangle +(3,3);
\end{scope}

\begin{scope}[every node/.append style={yslant=0.5,xslant=-1},yslant=0.5,xslant=-1]
  \shade[bottom color=gray!10, top color=black!50] (6,3) rectangle +(-3,-3);
\end{scope}

\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5]
  \foreach \i in {.5,1.5,...,2.5}
  \foreach \j in {.5,1.5,...,2.5}
  {
  \node at (\i,\j) {$+$};
  }

  \foreach \i in {0,3}
  \foreach \j in {.5,1.5,...,2.5}
  {
  \node at (\i,\j) {$+$};
  }

  \foreach \i in {.5,1.5,...,2.5}
  \foreach \j in {0,3}
  {
  \node at (\i,\j) {$+$};
  }

  \foreach \i in {0,1,...,3}
  \foreach \j in {.5,1.5,...,2.5}
  {
  \node at (\i,\j) {$+$};
  }

  \draw (0,0) grid (3,3);
\end{scope}

\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]  
  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {-2.5,-1.5,...,-.5}
  {
  \node at (\i,\j) {$+$};
  }

  \foreach \i in {3,6}
  \foreach \j in {-2.5,-1.5,...,-.5}
  {
  \node at (\i,\j) {$+$};
  }

  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {-3,0}
  {
  \node at (\i,\j) {$+$};
  }

  \draw (3,-3) grid (6,0);
\end{scope}

\begin{scope}[every node/.append style={yslant=0.5,xslant=-1},yslant=0.5,xslant=-1]  
  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {0.5,1.5,...,2.5}
  {
  \node at (\i,\j) {$+$};
  }

  \foreach \i in {3,6}
  \foreach \j in {0.5,1.5,...,2.5}
  {
  \node at (\i,\j) {$+$};
  }

  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {0,3}
  {
  \node at (\i,\j) {$+$};
  }

  \draw (3,0) grid (6,3);
\end{scope}

\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5]
  \foreach \i in {.5,1.5,...,2.5}
  \foreach \j in {.5,1.5,...,2.5}
  {
  \draw[<-] (\i,\j) -- +(-.2,-.2);
  }

  \foreach \i in {0,3}
  \foreach \j in {.5,1.5,...,2.5}
  {
  \draw[red,<-] (\i,\j) -- +(-.2,-.2);
  }

  \foreach \i in {.5,1.5,...,2.5}
  \foreach \j in {0,3}
  {
  \draw[red,<-] (\i,\j) -- +(-.2,-.2);
  }

  \foreach \i in {0,1,...,3}
  \foreach \j in {.5,1.5,...,2.5}
  {
  \draw[red,->] (\i,\j) -- +(.2,0);
  }

  \foreach \i in {.5,1.5,...,2.5}
  \foreach \j in {0,1,...,3}
  {
  \draw[red,->] (\i,\j) -- +(0,.2);
  }  
\end{scope}

\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]  
  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {-2.5,-1.5,...,-.5}
  {
  \draw[->] (\i,\j) -- +(.2,-.2);
  }

  \foreach \i in {3,6}
  \foreach \j in {-2.5,-1.5,...,-.5}
  {
  \draw[red,->] (\i,\j) -- +(.2,-.2);
  }

  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {-3,0}
  {
  \draw[red,->] (\i,\j) -- +(.2,-.2);
  }

  \foreach \i in {3,4,...,6}
  \foreach \j in {-2.5,-1.5,...,-.5}
  {
  \draw[red,->] (\i,\j) -- +(.2,0);
  }

  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {-3,-2,...,0}
  {
  \draw[red,->] (\i,\j) -- +(0,.2);
  }  
\end{scope}

\begin{scope}[every node/.append style={yslant=0.5,xslant=-1},yslant=0.5,xslant=-1]  
  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {0.5,1.5,...,2.5}
  {
  \draw[->] (\i,\j) -- +(.2,.2);
  }

  \foreach \i in {3,6}
  \foreach \j in {0.5,1.5,...,2.5}
  {
  \draw[red,->] (\i,\j) -- +(.2,.2);
  }

  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {0,3}
  {
  \draw[red,->] (\i,\j) -- +(.2,.2);
  }

  \foreach \i in {3,4,...,6}
  \foreach \j in {0.5,1.5,...,2.5}
  {
  \draw[red,->] (\i,\j) -- +(.2,0);
  }

  \foreach \i in {3.5,4.5,...,5.5}
  \foreach \j in {0,1,...,3}
  {
  \draw[red,->] (\i,\j) -- +(0,-.2);
  }
\end{scope}
\end{tikzpicture}

\end{document}

서로 올바르게 오버레이되는 레이어를 얻으려면 동일한 scope여러 환경을 사용해야 했습니다 .yslantslant

그럼에도 불구하고 뷰를 쉽게 변경할 수 없기 때문에 사진이 그다지 마음에 들지 않습니다. TikZ(또는 보다 일반적으로 LaTeX)에서 이러한 그림을 그리는 더 효과적인 방법이 있습니까? 나는 그러한 그림에 범례, 레이블, 기타 텍스트 항목을 삽입해야 하기 때문에 TikZ를 사용하고 싶습니다(예: MATLAB과 같은 외부 프로그램을 사용하여 그림을 생성하지 않음). 게다가 나는 pgfplots이것이 답이라고 생각하지만 확실하지 않습니다.

편집하다:완전한 답은 충분히 이해하는 사람에게서 나올 수 있다고 생각합니다.이 답변@톰 봄바딜님.

답변1

지금까지 나는 pgfplots를 사용하여 그런 것을 그릴 수 있었습니다:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
   \begin{axis}[
       xmin=0,
       xmax=1,
       ymin=0,
       ymax=1,
       zmin=0,
       zmax=1,
       axis equal,
       ticks=none,
       hide axis,
     ]
%lower face, drawn first as it will be hidden
     \addplot3[black,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0,
       quiver/w=0.1,
       -{stealth[]},
       samples=3,
       domain=0.16666:0.8333,
     ]{0};
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0.1,
       quiver/v=0,
       quiver/w=0,
       -stealth,
       samples=4,
       domain y=0.16666:0.8333,
       samples y=3,
       domain=0:1,
     ]{0};
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=-0.1,
       quiver/w=0,
       stealth-,
       samples=3,
       domain=0.16666:0.8333,
       samples y=4,
       domain y=0:1,
     ]{0};
%hidden right face, drawn first as it will be hidden
     \addplot3[black,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0,
       quiver/w=0.1,
       -{stealth[]},
       samples=3,
       domain=0.16666:0.8333,
     ](x,1,y);
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0.1,
       quiver/v=0,
       quiver/w=0,
       -stealth,
       samples=4,
       domain y=0.16666:0.8333,
       samples y=3,
       domain=0:1,
     ](x,1,y);
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0,
       quiver/w=0.1,
       -stealth,
       samples=3,
       domain=0.16666:0.8333,
       samples y=4,
       domain y=0:1,
     ](x,1,y);
%hidden left face, drawn first as it will be hidden
     \addplot3[black,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0,
       quiver/w=0.1,
       -{stealth[]},
       samples=3,
       domain=0.16666:0.8333,
     ](0,x,y);
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=-0.1,
       quiver/w=0,
       stealth-,
       samples=4,
       domain y=0.16666:0.8333,
       samples y=3,
       domain=0:1,
     ](0,x,y);
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0,
       quiver/w=0.1,
       -stealth,
       samples=3,
       domain=0.16666:0.8333,
       samples y=4,
       domain y=0:1,
     ](0,x,y);
      % faces
     \addplot3[surf,
       color=black!40,
       faceted color=black!80,
     domain=0:1,
   domain y=0:1,
   samples=4,
   samples y=4,
 ]
     (x,0,y);
     \addplot3[surf,
       color=black!40,
       faceted color=black!80,
     domain=0:1,
   domain y=0:1,
   samples=4,
   samples y=4,
 ]
     {1};
     \addplot3[surf,
       color=black!40,
       faceted color=black!80,
     domain=0:1,
   domain y=0:1,
   samples=4,
   samples y=4,
 ]
     (1,x,y);
     %upper face
     \addplot3[black,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0,
       quiver/w=0.1,
       -{stealth[]},
       samples=3,
       domain=0.16666:0.8333,
     ]{1};
    \addplot3[mark=x,
      only marks,
       samples=3,
       domain=0.16666:0.8333,
     ]{1};
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0.1,
       quiver/v=0,
       quiver/w=0,
       -stealth,
       samples=4,
       domain y=0.16666:0.8333,
       samples y=3,
       domain=0:1,
     ]{1};
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0.1,
       quiver/w=0,
       -stealth,
       samples=3,
       domain=0.16666:0.8333,
       samples y=4,
       domain y=0:1,
     ]{1};
     %left face
    \addplot3[black,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=-0.1,
       quiver/w=0,
       {stealth[]}-,
       samples=3,
       domain=0.16666:0.8333,
     ](x,0,y);
    \addplot3[mark=x,
      only marks,
       samples=3,
       domain=0.16666:0.8333,
     ](x,0,y);
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0.1,
       quiver/v=0,
       quiver/w=0,
       -stealth,
       samples=4,
       domain y=0.16666:0.8333,
       samples y=3,
       domain=0:1,
     ](x,0,y); 
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0,
       quiver/w=0.1,
       -stealth,
       samples=3,
       domain=0.16666:0.8333,
       samples y=4,
       domain y=0:1,
     ](x,0,y);
   %right face
    \addplot3[black,/pgfplots/quiver,
       quiver/u=0.1,
       quiver/v=0,
       quiver/w=0,
       -{stealth[]},
       samples=3,
       domain=0.16666:0.8333,
     ](1,x,y);
    \addplot3[mark=x,
      only marks,
       samples=3,
       domain=0.16666:0.8333,
     ](1,x,y);
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0.1,
       quiver/w=0,
       -stealth,
       samples=4,
       domain y=0.16666:0.8333,
       samples y=3,
       domain=0:1,
     ](1,x,y); 
     \addplot3[red,/pgfplots/quiver,
       quiver/u=0,
       quiver/v=0,
       quiver/w=0.1,
       -stealth,
       samples=3,
       domain=0.16666:0.8333,
       samples y=4,
       domain y=0:1,
     ](1,x,y);
 \end{axis}
\end{tikzpicture}
\end{document}

이는 다음 그림으로 이어집니다.

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

여전히 몇 가지 차이점이 있지만(마커가 정렬되지 않고 음영이 없음) 관리가 가능합니다. 더 복잡한 것은 엉망인 코드를 최적화하는 것입니다^^

그리고 얼굴의 순서를 어떻게 관리해야 좋은 순서대로 숨길 수 있는지 모르겠습니다.

관련 정보