# Shaded region between the area and a circle

How can I draw a square whose side is 6 inscribed in a circle and make the program display the shaded region between the square and the circle

-

## 4 Answers

Here's a simple option; the value for \side controls half the side of the square:

\documentclass{article}
\usepackage{tikz}

\def\side{3}

\begin{document}

\begin{tikzpicture}
\draw[fill=yellow!40] (0,0) circle (\side*1.4142);
\draw[fill=white] (-\side,-\side) rectangle (\side,\side);
\end{tikzpicture}

\end{document}


Another option using the intersections library; this time the value for \radius controls the radius of the circle:

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

\def\radius{2}

\begin{document}

\begin{tikzpicture}
\draw[name path=circle,fill=yellow!40] (0,0) circle (\radius);
\path[name path=line1] (-\radius,-\radius) -- (\radius,\radius);
\path[name path=line2] (-\radius,\radius) -- (\radius,-\radius);
\filldraw[draw=black,fill=white,
name intersections={of=circle and line1,by={a,b}},
name intersections={of=circle and line2,by={c,d}}]
(a) -- (c) -- (b) -- (d) -- cycle;
\end{tikzpicture}

\end{document}


-
thanks; I want to make it small. Any idea? –  user10 Nov 6 '12 at 3:33
@user10 sure: you can use a scaling factor: \begin{tikzpicture}[scale=0.5]...\end{tikzpicture}. –  Gonzalo Medina Nov 6 '12 at 3:35
@user10 in my updated answer you find another option: you can simply change the value of \radius (initially set to 3). –  Gonzalo Medina Nov 6 '12 at 3:39
how to use grey instead of yellow? –  user10 Nov 6 '12 at 3:56
@user10 in my code, instead of fill=yellow!40, you can use fill=gray!40 (which means 40% gray and 60% white) or any other shade of the desired color. –  Gonzalo Medina Nov 6 '12 at 4:00

Some complements :

With the code of Paul, you can use even odd rule if you draw the square with anticlockwise

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% parameters
\coordinate (center) at (2,3);
\def\radius{3cm}
\def\angle{15}
%
\path[fill=lime,draw=black,thick,even odd rule]
(center) circle (\radius)
+(\angle:\radius) --
+(\angle+90:\radius) --
+(\angle+180:\radius) --
+(\angle+270:\radius) --
cycle;
\end{tikzpicture}

\end{document}


If you want to fill the area between two circles, you have the next possibilites

\begin{tikzpicture}
\draw[fill=lime,even odd rule] (0,0) circle (2cm) circle (1cm) ;
\end{tikzpicture}

\begin{tikzpicture}
\draw[fill=lime,even odd rule] (0,0) circle (2cm) (0:1) arc (0:360:1) ;
\end{tikzpicture}

\begin{tikzpicture}
\draw[fill=lime] (0,0) circle (2cm) (0:1) arc (0:-360:1) ;
\end{tikzpicture}


About the construction

You can use Tikz with tkz-euclide. You give two points like you want with tikz or tkz-euclide with cartesian coordinates or polar coordinates. Then you define the square and you get the point C and you can define the circle with diameter A and C

\documentclass{scrartcl}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}

\begin{tikzpicture}
\tkzDefPoint(2,1){A}
\tkzDefPoint(5,2){B}
\tkzDefSquare(A,B) \tkzGetFirstPoint{C}
\tkzDrawCircle[diameter,fill=lime](A,C)
\tkzDrawSquare[fill=white](A,B)
\end{tikzpicture}

\end{document}


-

Here is a solution using a nonzero rule fill. The parameters are:

• the center coordinate,
• the \radius distance,
• the \angle of square into the circle.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% parameters
\coordinate (center) at (2,3);
\def\radius{3cm}
\def\angle{15}
%
\path[fill=lime,draw=black,thick]
(center) circle (\radius)
+(\angle:\radius) --
+(\angle-90:\radius) --
+(\angle-180:\radius) --
+(\angle-270:\radius) --
cycle;
\end{tikzpicture}
\end{document}


And just for fun (credits to Qrrbrbirlbel):

\documentclass[tikz]{standalone}
\begin{document}
\foreach \angle in {0,1,...,89}{
\begin{tikzpicture}
\coordinate (center) at (2,3);
\def\radius{3cm}
\fill[white] (center) +(-\radius,-\radius) rectangle +(\radius,\radius);
\path[fill=lime,draw=black,thick]
(center) circle (\radius) +(\angle:\radius) -- +(\angle-90:\radius)
--  +(\angle-180:\radius) --  +(\angle-270:\radius) --  cycle;
\end{tikzpicture}
}
\end{document}

-
Just for fun. –  Qrrbrbirlbel Nov 6 '12 at 7:29
@Qrrbrbirlbel Thanks. I add this picture to my answer... –  Paul Gaborit Nov 6 '12 at 7:33
This is nice to see.. give the commands for this rotations..@PaulGaborit –  David Oct 12 at 14:31
@David Done.... –  Paul Gaborit Oct 12 at 23:13

Save the earth by reducing the number of used keystrokes.

\documentclass[pstricks]{standalone}

\begin{document}
\foreach \ang in {0,15,...,345}{%
\begin{pspicture}(-4,-4)(4,4)
\pscustom[fillstyle=eofill,fillcolor=green]
{
\pscircle{3}
\rotate{\ang}
\psframe(3;-135)(3;45)
}
\end{pspicture}}
\end{document}


-
The rotation angle step is intentionally set to a greater value to reduce the number of frames which in turn to reduce the used bandwidth to view it on your browser. –  Who is crazy first Oct 12 at 23:53
Relevant answer is here(click). –  Who is crazy first Oct 13 at 0:02