10

I need to draw these figures, in the same way of the pic. Unfortunately I can't. I post my code.

enter image description here

code 1:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\usetikzlibrary{arrows,arrows.meta}
\pagestyle{empty}
\newcommand{\degre}{\ensuremath{^\circ}}
% \renewcommand{\rmdefault}{phv}
\renewcommand{\sfdefault}{phv}

\usepackage{sansmath}

\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}
\tikzset{
    quote/.style={{|[width=2mm]}-{|[width=2mm]}}
}

\begin{document}
\begin{tikzpicture}[> = stealth]
\coordinate (a) at (0,0);
\coordinate (b) at (3,3);


\coordinate (c) at (3,0);
\coordinate (d) at (0,3);


\coordinate (g) at (6,3);
\coordinate (h) at (3,6);

\coordinate (i) at (6,6);


\coordinate (e) at (5,5);
\coordinate (f) at (5,1);


\draw[black,step=1cm] (0,0) grid +(6cm,6cm);

\draw[line width=0.3mm, red, -]  (b) -- node[above left] {\Huge \textbf{}} (a);

\draw[line width=0.3mm, red, -]  (c) -- node[right] {\Huge \textbf{}} (d);
%\draw[ultra thick,blue,->]  (a) -- node[below left] {\Large $\vec{d}$} (c);

\draw[line width=0.3mm, green, -]  (g) -- node[right] {\Huge \textbf{}} (h);

\draw[line width=0.3mm, green, -]  (b) -- node[right] {\Huge \textbf{}} (i);
\end{tikzpicture}
\end{document}

code 2:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\usetikzlibrary{arrows,arrows.meta}
\pagestyle{empty}
\newcommand{\degre}{\ensuremath{^\circ}}
% \renewcommand{\rmdefault}{phv}
\renewcommand{\sfdefault}{phv}

\usepackage{sansmath}

\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}
\tikzset{
    quote/.style={{|[width=2mm]}-{|[width=2mm]}}
}

\begin{document}
\begin{tikzpicture}[> = stealth]
\coordinate (a) at (5,1);
\coordinate (b) at (1,3);




\draw[black,step=1cm] (0,0) grid +(5cm,3cm);

\draw[line width=0.3mm, black, -]  (b) -- node[above left] {\Huge \textbf{}} (a);


\end{tikzpicture}
\end{document}

code 3:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\usetikzlibrary{arrows,arrows.meta}
\pagestyle{empty}
\newcommand{\degre}{\ensuremath{^\circ}}
% \renewcommand{\rmdefault}{phv}
\renewcommand{\sfdefault}{phv}

\usepackage{sansmath}

\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}
\tikzset{
    quote/.style={{|[width=2mm]}-{|[width=2mm]}}
}

\begin{document}
\begin{tikzpicture}[> = stealth]




\draw[white,step=1cm] (0,0) grid +(6cm,8cm); %white grid

\draw [line width=0.8mm, color=black,fill=white,fill opacity=0.3] (3.0,1.0) circle (1.0cm);

\draw [line width=0.8mm,color=black,fill=blue,fill opacity=1.0] (1.0,3.0) circle (1.0cm);
\draw [line width=0.8mm, color=black,fill=white,fill opacity=0.3] (3.0,3.0) circle (1.0cm);
\draw [line width=0.8mm, color=black,fill=blue,fill opacity=1.0] (5.0,3.0) circle (1.0cm);

\draw [line width=0.8mm, color=black,fill=white,fill opacity=0.3] (1.0,5.0) circle (1.0cm);
\draw [line width=0.8mm, color=black,fill=green,fill opacity=1.0] (3.0,5.0) circle (1.0cm);
\draw [line width=0.8mm, color=black,fill=white,fill opacity=0.3] (5.0,5.0) circle (1.0cm);

\draw [line width=0.8mm, color=black,fill=white,fill opacity=0.3] (3.0,7.0) circle (1.0cm);


\end{tikzpicture}
\end{document}

code 4:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\usetikzlibrary{arrows,arrows.meta}
\pagestyle{empty}
\newcommand{\degre}{\ensuremath{^\circ}}
% \renewcommand{\rmdefault}{phv}
\renewcommand{\sfdefault}{phv}

\usepackage{sansmath}

\definecolor{uququq}{rgb}{0.25098039215686274,0.25098039215686274,0.25098039215686274}
\tikzset{
    quote/.style={{|[width=2mm]}-{|[width=2mm]}}
}

\begin{document}
\begin{tikzpicture}[> = stealth]


\coordinate (a) at (0,0);
\coordinate (b) at (2,0);
\coordinate (c) at (4,0);
\coordinate (d) at (6,0);
\coordinate (e) at (8,0);


\coordinate (f) at (1,2);
\coordinate (g) at (3,2);
\coordinate (h) at (5,2);
\coordinate (i) at (7,2);

\coordinate (l) at (2,4);
\coordinate (m) at (4,4);
\coordinate (n) at (6,4);

\coordinate (o) at (3,6);
\coordinate (p) at (5,6);

\coordinate (q) at (4,8);


\draw[white,step=1cm] (0,0) grid +(8cm,8cm);




\draw[line width=1.3mm, black, -]  (e) -- node[above left] {\Huge \textbf{}} (a);

\draw[line width=1.3mm, black, -]  (i) -- node[above left] {\Huge \textbf{}} (f);

\draw[line width=1.3mm, black, -]  (n) -- node[above left] {\Huge \textbf{}} (l);

\draw[line width=1.3mm, black, -]  (p) -- node[above left] {\Huge \textbf{}} (o);




\draw[line width=1.3mm, black, -]  (f) -- node[above left] {\Huge \textbf{}} (b);
\draw[line width=1.3mm, black, -]  (l) -- node[above left] {\Huge \textbf{}} (c);
\draw[line width=1.3mm, black, -]  (o) -- node[above left] {\Huge \textbf{}} (d);
\draw[line width=1.3mm, black, -]  (q) -- node[above left] {\Huge \textbf{}} (e);


\draw[line width=1.3mm, black, -]  (i) -- node[above left] {\Huge \textbf{}} (d);
\draw[line width=1.3mm, black, -]  (n) -- node[above left] {\Huge \textbf{}} (c);
\draw[line width=1.3mm, black, -]  (p) -- node[above left] {\Huge \textbf{}} (b);
\draw[line width=1.3mm, black, -]  (q) -- node[above left] {\Huge \textbf{}} (a);

\end{tikzpicture}
\end{document}
  • What's wrong with the third one? Only the colours are slightly different. – Torbjørn T. Nov 25 '17 at 15:58
  • I would like the light blue not the blue. – ryuk Nov 25 '17 at 16:02
  • 2
    blue!20 instead of blue, or reduce the fill opacity, as you for some reason have done for the white circles. – Torbjørn T. Nov 25 '17 at 16:08
14

Mostly, just use \fill with appropriate coordinates, and do that before you draw the lines, so that the filling doesn't cover up the lines. I tidied up some of the code, though I'm sure there are things that could be done more efficiently.

Not sure if there are much that needs explaining, it should be fairly clear how coordinates are chosen. Can mention that the -|/|- syntax is explained in TikZ: What EXACTLY does the the |- notation for arrows do?, and that cycle means to draw a line back to the first point on the path.

output of code

\documentclass[margin=20pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (3,3);
\coordinate (c) at (3,0);
\coordinate (d) at (0,3);
\coordinate (g) at (6,3);
\coordinate (h) at (3,6);
\coordinate (i) at (6,6);
\coordinate (e) at (5,5);
\coordinate (f) at (5,1);

\fill [blue!20] (0,6) rectangle +(2,-2);
\fill [blue!20] (a) -- (1.5,1.5) -- (c) -- cycle;
\fill [blue!20] (6,0) rectangle +(-1,1);
\fill [blue!20] (6,6) -- ++(-1,-1) -| cycle;
\fill [blue!20] (4,5) -- (5,5) -- (4.5,4.5) -- cycle;
\fill [blue!20] (4,4) -- (5,4) -- (4.5,4.5) -- cycle;
\fill [blue!20] (4,4) -- (3,3) -| cycle;
\fill [blue!20] (3,3) -- (2,2) |- cycle;


\draw[black,step=1cm] (0,0) grid +(6,6);
\draw[line width=0.3mm, red]  (b) -- (a);
\draw[line width=0.3mm, red]  (c) -- (d);
\draw[line width=0.3mm, green]  (g) -- (h);
\draw[line width=0.3mm, green]  (b) -- (i);
\end{tikzpicture}

\begin{tikzpicture}
\coordinate (a) at (5,1);
\coordinate (b) at (1,3);

\fill [green!40] (0,0) rectangle (5,3);
\draw[black,step=1cm] (0,0) grid +(5,3);
\filldraw [fill=yellow,draw=black] (b) -- (a) |- cycle;
\draw[line width=0.3mm, black, -]  (b) -- (a);

\end{tikzpicture}

\begin{tikzpicture}[
  Circle/.style={
    circle,
    minimum size=2cm,
    fill=#1,
    draw=black,
    thick,
    node contents={}
  },
  Circle/.default=white,
  node distance=0
]
\node [Circle,name=a];
\node [Circle=green!30,below=of a,name=b];
\node [Circle,left=of b];
\node [Circle,right=of b];
\node [Circle,below=of b,name=c];
\node [Circle=blue!30,left=of c];
\node [Circle=blue!30,right=of c];
\node [Circle,below=of c];

\end{tikzpicture}

\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (2,0);
\coordinate (c) at (4,0);
\coordinate (d) at (6,0);
\coordinate (e) at (8,0);
\coordinate (f) at (1,2);
\coordinate (g) at (3,2);
\coordinate (h) at (5,2);
\coordinate (i) at (7,2);
\coordinate (l) at (2,4);
\coordinate (m) at (4,4);
\coordinate (n) at (6,4);
\coordinate (o) at (3,6);
\coordinate (p) at (5,6);
\coordinate (q) at (4,8);

\fill [green!30] (q) -- (p) -- (o) -- cycle;
\fill [green!30] (l) -- (m) -- (h) -- (g) -- cycle;
\fill [blue!30]  (a) -- (b) -- (f) -- cycle;

\draw [line width=1.3mm] (e) -- (a) -- (q) -- cycle;
\foreach \i/\j in {i/f,n/l,p/o,f/b,l/c,o/d,i/d,n/c,p/b}
  \draw [line width=1.3mm] (\i) -- (\j);

\end{tikzpicture}
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.