# How to color a region?

The following code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,positioning}

\begin{document}

\draw (0,0) rectangle (5,5);
\draw[name path=c1] (0,0) arc[start angle=-90,end angle=0] -- (5,5);
\draw[name path=c2] (5,0) arc[start angle=0,end angle=90] -- (0,5);
\draw[name path=c3] (5,5) arc[start angle=90,end angle=180] -- (0,5);
\draw[name path=c4] (0,5) arc[start angle=180,end angle=270] -- (5,0);
\begin{scope}
\fill [name intersections={of=c1 and c2}]
(intersection-1) circle (2pt) node[label=right:$A$] {};
\fill [name intersections={of=c2 and c3}]
(intersection-1) circle (2pt) node[label=above:$B$] {};
\fill [name intersections={of=c3 and c4}]
(intersection-1) circle (2pt) node[label=left:$C$] {};
\fill [name intersections={of=c4 and c1}]
(intersection-1) circle (2pt) node[label=below:$D$] {};
\end{scope}
\end{tikzpicture}

\end{document}


produces

How can I apply color only to the central region limited by the arcs crossing at A, B, C and D?

-

If you don't mind to have the paths twice in your picture you can use clipping to only draw the inner area. Clipping is local to the scope and accumulates. So you can take the figure as two overlapping "leaves" and clip to both, then fill the whole rectangle.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,positioning}

\begin{document}

\begin{scope}
\clip (0,0) arc[start angle=-90,end angle=0]   -- (5,5)
arc[start angle=90,end angle=180]  -- (0,0);
\clip (0,5) arc[start angle=180,end angle=270] -- (5,0)
arc[start angle=0,end angle=90]    -- (0,5);
\fill [red] (0,0) rectangle (5,5);
\end{scope}
\draw (0,0) rectangle (5,5);
\draw[name path=c1] (0,0) arc[start angle=-90,end angle=0] -- (5,5);
\draw[name path=c2] (5,0) arc[start angle=0,end angle=90] -- (0,5);
\draw[name path=c3] (5,5) arc[start angle=90,end angle=180] -- (0,5);
\draw[name path=c4] (0,5) arc[start angle=180,end angle=270] -- (5,0);
\begin{scope}
\fill [name intersections={of=c1 and c2}]
(intersection-1) circle (2pt) node[label=right:$A$] {};
\fill [name intersections={of=c2 and c3}]
(intersection-1) circle (2pt) node[label=above:$B$] {};
\fill [name intersections={of=c3 and c4}]
(intersection-1) circle (2pt) node[label=left:$C$] {};
\fill [name intersections={of=c4 and c1}]
(intersection-1) circle (2pt) node[label=below:$D$] {};
\end{scope}
\end{tikzpicture}

\end{document}


-
Ah, if only I hadn't wasted 11 seconds trying to figure out why I couldn't convert a PDF to a PNG ... – Loop Space May 3 '11 at 20:56
@Andrew: Soon it will be \documentclass[png]{standalone} (if you have Image Magick or Ghostscript installed). – Martin Scharrer May 3 '11 at 21:19
Thanks, Martin. I'll accept your answer since it was the first one; it's a shame I can't accept @Andrew's and @Altermundus' answers as well. – Gonzalo Medina May 3 '11 at 23:26
@Martin: Can't wait! (But the problem was that I updated my system this weekend and now everything is broken. I'm seriously considering shifting to a new distribution.) – Loop Space May 4 '11 at 8:36
@Andrew: What distribution are you using? – Martin Scharrer May 4 '11 at 9:35

Use clips.

\documentclass{standalone}
% http://tex.stackexchange.com/q/17300/86
\usepackage{tikz}
\usetikzlibrary{intersections,positioning}

\begin{document}

\draw (0,0) rectangle (5,5);
\begin{scope}
\clip (0,0) arc[start angle=-90,end angle=0] arc[start angle=90,end angle=180];
\clip (5,0) arc[start angle=0,end angle=90] arc[start angle=180,end angle=270];
\fill[green] (0,0) rectangle (5,5);
\end{scope}
\draw[name path=c1] (0,0) arc[start angle=-90,end angle=0];
\draw[name path=c2] (5,0) arc[start angle=0,end angle=90];
\draw[name path=c3] (5,5) arc[start angle=90,end angle=180];
\draw[name path=c4] (0,5) arc[start angle=180,end angle=270];
\begin{scope}
\fill [name intersections={of=c1 and c2}]
(intersection-1) circle (2pt) node[label=right:$A$] {};
\fill [name intersections={of=c2 and c3}]
(intersection-1) circle (2pt) node[label=above:$B$] {};
\fill [name intersections={of=c3 and c4}]
(intersection-1) circle (2pt) node[label=left:$C$] {};
\fill [name intersections={of=c4 and c1}]
(intersection-1) circle (2pt) node[label=below:$D$] {};
\end{scope}
\end{tikzpicture}

\end{document}


(Sadly, in upgrading my machine, I appear to have lost the ability to easily convert pdfs to images so you'll have to wait for the picture!)

Note that I filled the region before drawing it. Otherwise, the fill goes over (half) the lines and doesn't look so good.

(Your syntax for the arcs was a little odd ... did you mean to put in the --s afterwards? I wasn't sure why they were there.)

-
Thanks, Andrew. I like the idea of filling the region before drawing it. As for the use of --s in the arc, I was reusing some old code and forgot to delete them. – Gonzalo Medina May 3 '11 at 23:12
@Gonzalo: If you read the TikZ manual carefully, you'll see that when PGF draws and fills a region then it fills it first and draws it afterwards, so I was only copying what TikZ does! – Loop Space May 4 '11 at 8:36
\documentclass{scrartcl}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(0,0){A} \tkzDefPoint(8,0){B}
\tkzDefPoint(8,8){C} \tkzDefPoint(0,8){D}
\tkzDrawPolygon(A,B,C,D)
\begin{scope}
\tkzClipCircle(B,C) \tkzClipCircle(D,C)
\tkzClipCircle(A,B) \tkzClipCircle(C,D)
\tkzDrawPolygon[fill=magenta!40](A,B,C,D)
\end{scope}
\tkzClipPolygon(A,B,C,D)
\tkzDrawCircle(B,C) \tkzDrawCircle(D,C)
\tkzDrawCircle(A,B) \tkzDrawCircle(C,D)
\tkzInterCC(A,B)(B,A) \tkzGetFirstPoint{I}
\tkzInterCC(B,A)(C,B) \tkzGetFirstPoint{J}
\tkzInterCC(C,B)(D,C) \tkzGetFirstPoint{K}
\tkzInterCC(D,C)(A,B) \tkzGetFirstPoint{H}
\tkzDrawPoints(I,J,K,H)
\tkzLabelPoint[above](I){$I$}
\tkzLabelPoint[below](K){$K$}
\tkzLabelPoint[right](H){$H$}
\tkzLabelPoint[left](J){$J$}
\end{tikzpicture}
\end{document}


-
Please don't post just code and an image, but also some explanation. Thanks. – Martin Scharrer May 3 '11 at 21:56
It's something like your solution. The syntax is not the same but I just "clip" four circles and I use the macros from my package to get the intersections. – Alain Matthes May 3 '11 at 22:34
Thanks, Altermundus. I like this solution but apparently tkz-euclide is not yet available from CTAN (at least not with TeX Live's tlmgr); it's a shame! – Gonzalo Medina May 3 '11 at 23:14
It' available from CTAN but not with TeXLive because K Berry waits the sorces of the documentation. I think that I can upload the last files very soon. But the files are on CTAN et on MikTeX ! – Alain Matthes May 4 '11 at 4:32

I know a solution has already been accepted, but here is another solution. This one uses the even odd rule to fill regions. Another available rule is the nonzero rule. Note that I have to use a preaction to color the whole thing blue, then color the tips white.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,positioning}

\begin{document}

\begin{tikzpicture}

\draw[name path=c1] (0,0) to[out=0,in=-90] (5,5) to [out=180,in=90]  (0,0) ;
\draw[name path=c2] (5,0) to[out=180,in=-90] (0,5) to[out=0,in=90] (5,0);

\fill[even odd rule,white,preaction={fill=blue}]
(0,0) to[out=0,in=-90] (5,5) to [out=180,in=90]  (0,0)
(5,0) to[out=90,in=0] (0,5) to[out=-90,in=180] (5,0);

\path[name intersections={of=c1 and c2},fill=red]
\foreach \i/\name/\pos in {1/$D$/below,2/$A$/right,3/$C$/left,4/$B$/above}{
(intersection-\i) circle (2pt) node[\pos] {\name}
};
\end{tikzpicture}
\end{document}


The output is

-
Very elegant approach! – Jake May 23 '11 at 5:23