1

It is in tikz possible to fill area inside a cycle, right?

I am having issues with it and I can't figure out what I am messing up:

\documentclass[center]{article}
\usepackage{tikz}

\begin{document}

\centering
\begin{tikzpicture}[>=latex]
\node[circle, fill, inner sep = 0, minimum size = 2mm] (a) at (3,0,0) {};
\node[left of = a] {$a$};
\node[circle, fill, inner sep = 0, minimum size = 2mm] (b) at (5,0,4) {};
\node[left of = b] {$b$};
\node[circle, fill, inner sep = 0, minimum size = 2mm] (apb) at (8,0,1) {};
\node[right of = apb] {$a + b$};

\draw[->, very thin] (a) -- node[below] {$i_1$} (apb);
\draw[->, very thin] (b) -- node[below] {$i_2$} (apb);

\node[circle, fill, inner sep = 0, minimum size = 2mm] (fa) at (3,3,0) {};
\node[right of = fa, circle, minimum size = 6cm] {};
\node[left of = fa] {$f(a)$};
\node[circle, fill, inner sep = 0, minimum size = 2mm] (fb) at (5,3,4) {};
\node[right of = fb, circle, minimum size = 3cm] {};
\node[left of = fb] {$f(b)$};
\node[circle, fill, inner sep = 0, minimum size = 2mm] (fapb) at (8,3,1) {};
\node[right of = fapb, circle, minimum size = 3cm] {};
\node[right of = fapb] {$f(a + b)$};

\draw[very thin, dashed, blue, ->] (a) -- (fa);
\draw[very thin, dashed, blue, ->] (b) -- (fb);
\draw[very thin, dashed, blue, ->] (apb) -- (fapb);


\draw[very thin, ->] (fa) -- node[below] {$j_1$} (fapb);
\draw[very thin, ->] (fb) -- node[below] {$j_2$} (fapb);


\fill[red] (b) -- (apb) -- (a) -- cycle;
\end{tikzpicture}

\end{document}

enter image description here

As you can see the bottom two arrows are red, but I want the triangle between the bottom three point to be red. The triangle is described by the path (b) -- (apb) -- (a) --cycle however. So... what is problem?

3
  • 1
    a, b and apb are nodes. They have a size. The red lines connect only the borders of the nodes. You could use (b.center)--(apb.center)--(a.center)--cycle. – esdd Nov 30 '17 at 19:34
  • I didn't realise that my vote to close as duplicate would be binding. Please do check to see if that question answers yours. If not, please do edit your question to explain why and it'll get re-opened. – Andrew Stacey Nov 30 '17 at 19:37
  • It does answer it, as well as esdd's comment. – lo tolmencre Nov 30 '17 at 19:44
0
\documentclass[center]{article}
\usepackage{tikz}

\begin{document}

\centering
\begin{tikzpicture}[>=latex]
\node[circle, fill,red, inner sep = 0, minimum size = 2mm] (a) at (3,0,0) {};
\node[left of = a] {$a$};
\node[circle, fill,red, inner sep = 0, minimum size = 2mm] (b) at (5,0,4) {};
\node[left of = b] {$b$};
\node[circle, fill,red, inner sep = 0, minimum size = 2mm] (apb) at (8,0,1) {};
\node[right of = apb] {$a + b$};

\draw[->, very thin,red] (a) -- node[below] {\color{black}$i_1$} (apb);
\draw[->, very thin,red] (b) -- node[below] {\color{black}$i_2$} (apb);

\node[circle, fill, inner sep = 0, minimum size = 2mm] (fa) at (3,3,0) {};
\node[right of = fa, circle, minimum size = 6cm] {};
\node[left of = fa] {$f(a)$};
\node[circle, fill, inner sep = 0, minimum size = 2mm] (fb) at (5,3,4) {};
\node[right of = fb, circle, minimum size = 3cm] {};
\node[left of = fb] {$f(b)$};
\node[circle, fill, inner sep = 0, minimum size = 2mm] (fapb) at (8,3,1) {};
\node[right of = fapb, circle, minimum size = 3cm] {};
\node[right of = fapb] {$f(a + b)$};

\draw[very thin, dashed, blue, ->] (a) -- (fa);
\draw[very thin, dashed, blue, ->] (b) -- (fb);
\draw[very thin, dashed, blue, ->] (apb) -- (fapb);


\draw[very thin, ->] (fa) -- node[below] {$j_1$} (fapb);
\draw[very thin, ->] (fb) -- node[below] {$j_2$} (fapb);


\fill[red] (b) -- (apb) -- (a) -- cycle;

\end{tikzpicture}

\end{document}

enter image description here

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