Your options are not fine. When you write \draw[fill=black, ultra thick, red]
, as you can see fill=black
doesn't work. Your last option red
is used for drawing and filling. to fill with red and to draw with black, you need to write \draw[color=black,fill=red, ultra thick]
. Surface and line are red and the line width is important so you the result is not fine. Now in a first time, you can use \draw
and \fill
separately. The order is important because some options have some effects on the first drawings. There are other methods (ways) to create this picture but I give you the codes later. For the circles at each vertex is interesting to use variables instead of "raw" coordinates and you can use \foreach
. Comments are in the code.
Figure
My code update
I keep the code initial to show what is wrong and what is right
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\tikzset{vertex/.style={shape=circle, % style for a vertex
minimum size=3pt,
fill=black,
inner sep = 0pt}}
\begin{tikzpicture}[scale=4]
% define the points
\path (0,0) coordinate (A) (1,0) coordinate (B) % bottom
(1.5,0.5) coordinate (C) (0.5,0.5) coordinate (D)
(0,1) coordinate (E) (1,1) coordinate (F) % top add 1 for y
(1.5,1.5) coordinate (G) (0.5,1.5) coordinate (H)
($(A)!0.5!(C)$) coordinate (O) % middle of A--C
($(E)!0.5!(G)$) coordinate (P);%
\draw (A) -- (E) (B) -- (F) (C) -- (G) ; % lateral
\draw[gray,dashed] (D) -- (H) (D) -- (C) (D) -- (A) (D) -- (B) (A) -- (C);
\fill [blue!50,fill opacity=.5] (P) -- (O) -- (C) -- (G) -- cycle;
\fill [red!50, fill opacity=.5] (H) -- (D) -- (B) -- (F) -- cycle;
\fill [blue!50,fill opacity=.5] (A) -- (O) -- (P) -- (E) -- cycle;
\draw (A) -- (B) -- (C) (F) -- (H); % bottom
\draw (E) -- (F) -- (G) -- (H) -- (E) -- (G); % top
% vertex
\foreach \vertex in {A,...,C} {\node[vertex] at (\vertex) {};}
\foreach \vertex in {E,...,H} {\node[vertex] at (\vertex) {};}
\node[vertex,fill=gray] at (D) {};
\end{tikzpicture}
\end{document}
version 3D
I think it's the better way. With canvas is xy plane at z=0
, you are on a plan (xy).
I used some negative values to respect my first solution and to use the same code,. The code looks better with only positive values. To use other side, you just need to write for example canvas is xz plane at y=0
and you get a plan (lateral) axis are x and z. The result is exactly the same and you need no calculus but you need some orientation in space !
I added yellow color to show how to use other plans Be careful, I used canvas is yx plane
and not canvas is xy plane
.
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc,3d}
\begin{document}
\thispagestyle{empty}
\tikzset{vertex/.style={shape=circle, % style for a vertex
minimum size=3pt,
fill=gray,
inner sep = 0pt}}
\begin{tikzpicture}
[x={(-0.5cm,-0.5cm)}, y={(1cm,0cm)}, z={(0cm,1cm)}, scale=4]
\draw[thick](0,0,0)--(1.2,0,0) node[below right]{x} ;
\draw[thick](0,0,0)--(0,1.2,0) node[below right]{y} ;
\draw[thick](0,0,0)--(0,0,1.2) node[below right]{z} ;
% face bottom
\begin{scope}[canvas is xy plane at z=0,very thin]
\coordinate (A) at (0,0); \coordinate (C) at (-1,1);
\coordinate (B) at (-1,0); \coordinate (D) at (0,1);
\coordinate (O) at ($(A)!0.5!(C)$); % middle of A--C
\end{scope}
% face top
\begin{scope}[canvas is xy plane at z=1,very thin]
\coordinate (E) at (0,0); \coordinate (G) at (-1,1);
\coordinate (F) at (-1,0); \coordinate (H) at (0,1);
\coordinate (P) at ($(E)!0.5!(G)$); % middle of A--C
\end{scope}
\begin{scope}[canvas is yx plane at z=0]
\path[fill = yellow] (0,0) rectangle (1,-1);
\end{scope}
\foreach \vertex in {A,...,H} {\node[vertex] at (\vertex) {};}
\draw (A) -- (B) -- (C) -- (D) -- cycle; % bottom
\draw (E) -- (F) -- (G) -- (H) -- cycle; % top
\draw (A) -- (E) (B) -- (F) (C) -- (G) (D)--(H); % lateral
\fill [blue!50,fill opacity=.5] (P) -- (O) -- (C) -- (G) -- cycle;
\fill [red!50, fill opacity=.5] (H) -- (D) -- (B) -- (F) -- cycle;
\fill [blue!50,fill opacity=.5] (A) -- (O) -- (P) -- (E) -- cycle;
\end{tikzpicture}
\end{document}
For fun
I would like to avoid maximum of coordinates
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc,3d}
\begin{document}
\thispagestyle{empty}
\tikzset{vertex/.style={shape=circle, % style for a vertex
minimum size=8pt,
ball color=gray,
inner sep = 0pt}}
\begin{tikzpicture}
[x={(-0.5cm,-0.5cm)}, y={(1cm,0cm)}, z={(0cm,1cm)}, scale=4]
\foreach \z in {0,1} \foreach \y in {0,1} \foreach \x in {0,1}
{\coordinate (\x\y\z) at (\x,\y,\z) ;}
\coordinate (O) at ($(000)!0.5!(110)$);
\coordinate (P) at ($(001)!0.5!(111)$);
\fill[fill opacity=.5,blue!30] (O)
\foreach \pt in {P,011,010}{--(\pt.center)}--cycle;%
\fill[fill opacity=.5,red!30] (000)
\foreach \pt in {110,111,001}{--(\pt.center)}--cycle;%
\fill[fill opacity=.5,blue!30] (O)
\foreach \pt in {P,101,100}{--(\pt.center)}--cycle;%
\draw[thick,double] (000.center)
\foreach \pt in {010,011,001}{--(\pt.center)}--cycle;%
\foreach \y in {0,1} \foreach \z in {0,1}
{\node[vertex] (0\y\z) at (0\y\z) {};}
\draw[thick,double] (100.center)
\foreach \pt in {110,111,101}{--(\pt.center)}--cycle;%
\foreach \y in {0,1} \foreach \z in {0,1}
{\draw[thick,double] (0\y\z) -- (1\y\z);
\node[vertex] (1\y\z) at (1\y\z) {};}
\end{tikzpicture}
\end{document}
outer sep
option on page 176 in the tikz manual. -and use\draw [draw=black, ultra thick, fill=blue]
. -and read chapter 20 about transparency.outer sep
?outer sep = 0
would help to make the lines join nicely. -but I do not know enough.