11

The following code

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

\begin{document}

\begin{tikzpicture}[radius=5]
\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?

doncherry
  • 54,637
Gonzalo Medina
  • 505,128

4 Answers4

11

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{tikzpicture}[radius=5]
\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}

Image

Martin Scharrer
  • 262,582
  • Ah, if only I hadn't wasted 11 seconds trying to figure out why I couldn't convert a PDF to a PNG ... – Andrew Stacey May 03 '11 at 20:56
  • @Andrew: Soon it will be \documentclass[png]{standalone} (if you have Image Magick or Ghostscript installed). – Martin Scharrer May 03 '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 03 '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.) – Andrew Stacey May 04 '11 at 08:36
  • @Andrew: What distribution are you using? – Martin Scharrer May 04 '11 at 09:35
  • @Martin: Ubuntu. The "everything" is not TeX-related as I installed TL manually afterwards. The "everything" so far is: can't rebuild emacs due to some funny business with configure, keyboard remapping seems weird (xmodmap is reading the wrong column, haven't dug deep in this though), can't use the existing emacs due to a silly bug. Given that most of what I do is using Emacs with a modified keyboard, that's enough for me! I use debian on a different computer so I'll probably shift to that until Ubuntu sorts itself out. – Andrew Stacey May 04 '11 at 09:38
  • @Andrew: Yeah, Ubuntu 11.04 does change quite a bit and the thing with TL is a pain with it. I'm using VIM with a normal keyboard so I'm not that much affected. The new menu is something I have to get used to. – Martin Scharrer May 04 '11 at 09:42
9

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

enter image description here

Frédéric
  • 11,087
  • 3
  • 37
  • 43
6

Use clips.

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

\begin{document}

\begin{tikzpicture}[radius=5]
\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.)

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
  • 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 03 '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! – Andrew Stacey May 04 '11 at 08:36
5
\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}

enter image description here

Alain Matthes
  • 95,075
  • 1
    Please don't post just code and an image, but also some explanation. Thanks. – Martin Scharrer May 03 '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 03 '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 03 '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 04 '11 at 04:32