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}

- 505,128
Here is a solution using a nonzero rule fill. The parameters are:
- the
centercoordinate, - the
\radiusdistance, - the
\angleof 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}
- 70,770
- 10
- 176
- 283
-
1
-
-
This is nice to see.. give the commands for this rotations..@PaulGaborit – David Oct 12 '14 at 14:31
-
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}

- 95,075
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}

- 36,086
-
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. – kiss my armpit Oct 12 '14 at 23:53
-
\begin{tikzpicture}[scale=0.5]...\end{tikzpicture}. – Gonzalo Medina Nov 06 '12 at 03:35\radius(initially set to 3). – Gonzalo Medina Nov 06 '12 at 03:39fill=yellow!40, you can usefill=gray!40(which means 40% gray and 60% white) or any other shade of the desired color. – Gonzalo Medina Nov 06 '12 at 04:00