Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw a graph (the data structure) such that certain subgraphs form a sunflower (a notion from combinatorics).

enter image description here

In other words I want to indicate that the sets overlap in the middle (1,2,3,4). The idea is that all the colors combined result in white (is that clear enough?). The problem is the spaces where exactly two colors overlap. I could use for example yellow!20!green!20 for the bottom shape but I do not know how to draw a shape like this.

In a mathematical sense there is no overlapping of the green and yellow set which does not also contain blue and red but it looks a bit ugly. Any ideas? Maybe a different way to depict it?

    \begin{tikzpicture}[scale=1]
    \tikzstyle{rect}=[rectangle, thick, 
    draw=black, rounded corners, node distance = 2cm]
    \tikzstyle{diedge}=[->,thick,shorten <=2pt, shorten >=2pt]
    \tikzstyle{udiedge}=[thick,shorten <=2pt, shorten >=2pt]
    \tikzstyle{circ}=[circle, thick, 
    draw=black, rounded corners, node distance = 1cm,
    font=\tiny]

    \fill[blue!20] (-2.4,2.4) circle (1.2cm);
    \fill[red!20] (2.4,2.4) circle (1.2cm);
    \fill[green!20] (2.4,-2.4) circle (1.2cm);
    \fill[yellow!20] (-2.4,-2.4) circle (1.2cm);

    \draw[blue!20,line width=2.4cm] (-2.4,2.4) -- (0,0);
    \draw[red!20,line width=2.4cm] (2.4,2.4) -- (0,0);
    \draw[green!20,line width=2.4cm] (2.4,-2.4) -- (0,0);
    \draw[yellow!20,line width=2.4cm] (-2.4,-2.4) -- (0,0);

    \fill[white] (0,0) circle (1.2cm);

    \node[circ] at (-0.5,0.5) (1) {$1$};
    \node[circ, below of = 1] (2) {$2$};
    \node[circ, right of = 1] (3) {$3$};
    \node[circ, right of = 2] (4) {$4$};

    \path (1) edge[udiedge] (2);
    \path (1) edge[udiedge] (3);
    \path (2) edge[udiedge] (4);
    \path (3) edge[udiedge] (4);

    \node[circ, node distance = 2cm, above right of = 3] (5) {$5$};
    \node[circ, right of = 5] (6) {$6$};
    \node[circ, above of = 5] (7) {$7$};

    \path (5) edge[udiedge] (7);
    \path (5) edge[udiedge] (6);
    \path (7) edge[udiedge] (6);    


    \node[circ, node distance = 2cm, above left of = 1] (8) {$8$};
    \node[circ, left of = 8] (9) {$9$};
    \node[circ, above of = 8] (10) {$10$};

    \path (9) edge[udiedge] (10);
    \path (10) edge[udiedge] (8);
    \path (9) edge[udiedge] (8);    


    \node[circ, node distance = 2cm, below right of = 4] (11) {$11$};
    \node[circ, below of = 11] (12) {$12$};
    \node[circ, right of = 11] (13) {$13$};
    \node[circ, right of = 12] (14) {$14$};

    \path (11) edge[udiedge] (12);
    \path (11) edge[udiedge] (13);
    \path (12) edge[udiedge] (14);
    \path (13) edge[udiedge] (14);

    \node[circ, node distance = 2cm, below left of = 2] (15)
    {$15$};

    \path (3) edge[udiedge] (5);
    \path (1) edge[udiedge] (8);
    \path (4) edge[udiedge] (11);
    \path (2) edge[udiedge] (15);
\end{tikzpicture}
share|improve this question

2 Answers 2

up vote 2 down vote accepted

Another option is the use of clip command to fill the particular areas, displayed below. Need the scope environment to limit the operation of filling, or it will take effect from thereafter.

EDIT: Well, a much simpler way is to fill the shape directly as such. Replace the scope codes with the following code. the coordinate 1.7 is determined by \sqrt(1.2^2+1.2^2).

\fill[blue!20!red!20]     (0,1.7)  -- (45:1.2)   arc (45:135:1.2)    -- cycle;
\fill[green!20!red!20]    (1.7,0)  -- (-45:1.2)  arc (-45:45:1.2)    -- cycle;
\fill[green!20!yellow!20] (0,-1.7) -- (-45:1.2)  arc (-45:-135:1.2)  -- cycle;
\fill[black]              (-1.7,0) -- (-135:1.2) arc (-135:-225:1.2) -- cycle;



\clip (-1.7,0) --  (-135:1.2) arc (-135:-225:1.2)-- cycle;  % shown by the black area

enter image description here

Code

\documentclass[a4paper]{article}

\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}[scale=1]
    \tikzstyle{rect}=[rectangle, thick, 
    draw=black, rounded corners, node distance = 2cm]
    \tikzstyle{diedge}=[->,thick,shorten <=2pt, shorten >=2pt]
    \tikzstyle{udiedge}=[thick,shorten <=2pt, shorten >=2pt]
    \tikzstyle{circ}=[circle, thick, 
    draw=black, rounded corners, node distance = 1cm,
    font=\tiny]

    \fill[blue!20] (-2.4,2.4) circle (1.2cm);
    \fill[red!20] (2.4,2.4) circle (1.2cm);
    \fill[green!20] (2.4,-2.4) circle (1.2cm);
    \fill[yellow!20] (-2.4,-2.4) circle (1.2cm);

    \draw[blue!20,line width=2.4cm] (-2.4,2.4) -- (0,0);
    \draw[red!20,line width=2.4cm] (2.4,2.4) -- (0,0);
    \draw[green!20,line width=2.4cm] (2.4,-2.4) -- (0,0);
    \draw[yellow!20,line width=2.4cm] (-2.4,-2.4) -- (0,0);
    \fill[white] (0,0) circle (1.2cm);

\begin{scope}
\clip (0,1.7) --  (45:1.2) arc (45:135:1.2)-- cycle;
\fill[blue!20!red!20]  (0,0) circle [radius=2cm];
\end{scope}

\begin{scope}
\clip (1.7,0) --  (-45:1.2) arc (-45:45:1.2)-- cycle;
\fill[green!20!red!20]  (0,0) circle [radius=2cm];
\end{scope}

\begin{scope}
\clip (0,-1.7) --  (-45:1.2) arc (-45:-135:1.2)-- cycle;
\fill[green!20!yellow!20]  (0,0) circle [radius=2cm];
\end{scope}

\begin{scope}
\clip (-1.7,0) --  (-135:1.2) arc (-135:-225:1.2)-- cycle;
\fill[black]  (0,0) circle [radius=2cm];
\end{scope}

    \node[circ] at (-0.5,0.5) (1) {$1$};
    \node[circ, below of = 1] (2) {$2$};
    \node[circ, right of = 1] (3) {$3$};
    \node[circ, right of = 2] (4) {$4$};

    \path (1) edge[udiedge] (2);
    \path (1) edge[udiedge] (3);
    \path (2) edge[udiedge] (4);
    \path (3) edge[udiedge] (4);

    \node[circ, node distance = 2cm, above right of = 3] (5) {$5$};
    \node[circ, right of = 5] (6) {$6$};
    \node[circ, above of = 5] (7) {$7$};

    \path (5) edge[udiedge] (7);
    \path (5) edge[udiedge] (6);
    \path (7) edge[udiedge] (6);    


    \node[circ, node distance = 2cm, above left of = 1] (8) {$8$};
    \node[circ, left of = 8] (9) {$9$};
    \node[circ, above of = 8] (10) {$10$};

    \path (9) edge[udiedge] (10);
    \path (10) edge[udiedge] (8);
    \path (9) edge[udiedge] (8);    


    \node[circ, node distance = 2cm, below right of = 4] (11) {$11$};
    \node[circ, below of = 11] (12) {$12$};
    \node[circ, right of = 11] (13) {$13$};
    \node[circ, right of = 12] (14) {$14$};

    \path (11) edge[udiedge] (12);
    \path (11) edge[udiedge] (13);
    \path (12) edge[udiedge] (14);
    \path (13) edge[udiedge] (14);

    \node[circ, node distance = 2cm, below left of = 2] (15)
    {$15$};

    \path (3) edge[udiedge] (5);
    \path (1) edge[udiedge] (8);
    \path (4) edge[udiedge] (11);
    \path (2) edge[udiedge] (15);
\end{tikzpicture}

\end{document}
share|improve this answer

You can do this using a blend group (c.f. Section 23.3 of the pgf manual v3.0.0), which mixes the colors according to a specified blending mode. The possible modes are outlined in the manual, but screen or lighten are probably most appropriate for your desired output.

This approach flattens items drawn inside the group, so I used a slightly different drawing procedure since we don't need to hide the intersections near the center of the image.

Here's the basic setup:

\documentclass[tikz,border=12pt]{standalone}
\begin{document}
\begin{tikzpicture}
    \begin{scope}[%
      blend group=screen, % see Section 23.3 of PGF Manual (v3.0.0)
      radius=1.2, delta angle=180, % common settings for arc commands
    ]
    \path[fill=  blue!50] (225:1.2) arc[start angle=225] -- ++(-2.4,+2.4) arc[start angle= 45] -- cycle;
    \path[fill=   red!50] (135:1.2) arc[start angle=135] -- ++(+2.4,+2.4) arc[start angle=315] -- cycle;
    \path[fill= green!50] ( 45:1.2) arc[start angle= 45] -- ++(+2.4,-2.4) arc[start angle=225] -- cycle;
    \path[fill=yellow!50] (315:1.2) arc[start angle=315] -- ++(-2.4,-2.4) arc[start angle=135] -- cycle;
    \end{scope}
\end{tikzpicture}
\end{document}

And the rendered output (note that not all PDF viewers/printers handle all blend modes correctly):

enter image description here

The result looks slightly "odd" because the inclusion of yellow means the mixing is not really "symmetric" (if that makes any sense). For RGB only, you'd get the following:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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