0

This code shows a cube with a horizontal plane inside of it. how I can make this plane vertical?

\documentclass{standalone}

\usepackage{tikz} \usetikzlibrary{calc} \usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}

    \foreach \n/\x/\l/\p in{
        1/{(0, 4)}/{$1$}/left,
        2/{(4, 4)}/{$2$}/south west,
        3/{(0, 0)}/{$3$}/below,
        4/{(4, 0)}/{$4$}/below,
        5/{(0.8, 4.8)}/{$5$}/above,
        6/{(4.8, 4.8)}/{$6$}/above,
        7/{(.8, 1)}/{$7$}/south east,
        8/{(4.8, 1)}/{$8$}/right
    }{
        \node[inner sep=2pt,circle,draw,fill,label={\p:\l}] (\n) at \x {};
    }
    \draw (1) -- (2) -- (4) -- (3) -- cycle;
    \draw (1) -- (2) -- (6) -- (5) -- cycle;
    \draw (2) -- (4) -- (8) -- (6) -- cycle;
    \draw (3) -- (1) -- (5);
    \draw[dashed] (5) -- (7) -- (3);
    \draw[dashed] (7) -- (8);

    \draw[pattern=north west lines] ($(1)!0.5!(3)$) -- ($(5)!0.5!(7)$) -- ($(6)!0.5!(8)$) -- ($(2)!0.5!(4)$) -- cycle;

    \node (a1) at ($(3)!0.5!(4) - (0,0.5)$) {$1\rightarrow3$};
    \node (a2) at ($(a1) - (0,0.5)$) {$5\rightarrow7$};
    \node (a3) at ($(a2) - (0,0.5)$) {$6\rightarrow8$};
    \node (a4) at ($(a3) - (0,0.5)$) {$2\rightarrow4$};

\end{tikzpicture}

\end{document}

sherek_66
  • 161
  • Say this question follows this one: how to graph plane symmetry of a cube? – AndréC Aug 03 '20 at 10:15
  • 1
    As I said in the comment to my answer, you have to change the points used in the line \draw[pattern=north west lines] ($(1)!0.5!(3)$) -- ($(5)!0.5!(7)$) -- ($(6)!0.5!(8)$) -- ($(2)!0.5!(4)$) -- cycle;. This means that you change 1/3;5/7;6/8;2/4 either to 1/2;3/4;7/8;5/6 or to 1/5;2/6;4/8;3/7. – KersouMan Aug 03 '20 at 10:21
  • 5
  • @KersouMan how I should change it to be vertical? – sherek_66 Aug 03 '20 at 18:57
  • 1
    \draw[pattern=north west lines] ($(1)!0.5!(2)$) -- ($(3)!0.5!(4)$) -- ($(7)!0.5!(8)$) -- ($(5)!0.5!(6)$) -- cycle; or \draw[pattern=north west lines] ($(1)!0.5!(5)$) -- ($(2)!0.5!(6)$) -- ($(4)!0.5!(8)$) -- ($(3)!0.5!(7)$) -- cycle; depending on which plane you want. – KersouMan Aug 03 '20 at 19:03
  • great. thanks. what is a logic behind that? is there any tutorial that I can read? for example what I should do for diagonal plane? – sherek_66 Aug 03 '20 at 19:07
  • 1
    Before using any package, you should read the documentation. TikZ documentation can be found there. The logic is just that, for example, ($(1)!0.5!(2)$) is the point located midway between coordinates (1) and (2). Then you compute the other points that you need and you join them with --. The cycle is here to close the path by joining the last point in the list to the first point in the list. For diagonal plane, you just join the vertices you want by using (1) -- (4) -- (8) -- (6) -- cycle as a list of coordinates for example. – KersouMan Aug 03 '20 at 19:12
  • 1
    However, I really encourage you to read PGF manual which contains several complete and detailed examples in the first chapters. – KersouMan Aug 03 '20 at 19:14
  • 1
    A side note from the answer to this question, you will need to use (1.center) -- (4.center) -- (8.center) -- (6.center) -- cycle for cycle to work correctly. – KersouMan Aug 03 '20 at 19:29

0 Answers0