9

Im trying to make a square like this
enter image description here
but Im not able to do so.

The idea is to make a square an put 4 circles centered in the corners, but I dont know how to make the fill cover all the circle sector down to the border of the square
enter image description here

The MWE is

\documentclass[]{beamer}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[fill=gray,thick](0,0) rectangle (4,4);
\draw (4,1)[fill=white,thick] arc (90:180:1);
\draw (1,0)[fill=white,thick] arc (0:90:1);
\draw (3,4)[fill=white,thick] arc (180:270:1);
\draw (1,4)[fill=white,thick] arc (360:270:1);
\end{tikzpicture}
\hspace{2cm}
\begin{tikzpicture}
\draw[even odd rule,fill=gray,thick](0,0) rectangle (4,4) (2,2) circle (2cm);
\end{tikzpicture}
\end{document}

4 Answers 4

13

I'm not sure, which region of your image you like to fill by gray color. Like the following image? Please advice!

enter image description here

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
    \begin{center}
    \begin{tikzpicture}
\draw[fill=gray](0,0) rectangle (4,4);
\draw[fill=white]
        (4,1)   arc (90:180:1)  --
        (1,0)   arc (0:90:1)    --
        (0,3)   arc (270:360:1) --
        (3,4)   arc (180:270:1) -- cycle
        ;
    \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

Or you like to have the following inverse coloring like this?

enter image description here

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
    \begin{center}
    \begin{tikzpicture}
\draw   (0,0) rectangle (4,4);
\draw[fill=gray!30]
        (4,1)   arc (90:180:1)  --
        (1,0)   arc (0:90:1)    --
        (0,3)   arc (270:360:1) --
        (3,4)   arc (180:270:1) -- cycle
        ;
    \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}
3
  • 2
    Either its a good choice, since the color can be any order, I didnt know you could made the fill this way.
    – riccs_0x
    Jan 15, 2021 at 4:43
  • 1
    How can this be modified to have circles only in the bottom left and top right corners? Jun 28, 2021 at 12:34
  • 1
    @Zarathustra, just draw those arc. For complete code please ask new question where you can give link to this answer,
    – Zarko
    Jun 28, 2021 at 14:08
10

Two more options for such a figure. One uses a clipping path while the second draws the rectangle as a node which allows to use the auto clipping property of a path picture command.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[clip](0,0) rectangle (4,4);
\filldraw[fill=gray] (0,0) circle (1cm);
\filldraw[fill=gray] (0,4) circle (1cm);
\filldraw[fill=gray] (4,0) circle (1cm);
\filldraw[fill=gray] (4,4) circle (1cm);
\end{tikzpicture}
%
\begin{tikzpicture}
\node[draw, minimum size=4cm, fill=gray,
    path picture={\foreach \i in {north west, north east, south west, south east} 
        \filldraw[fill=white] (path picture bounding box.\i) circle (1cm);}]{};
\end{tikzpicture}
\end{document}

enter image description here

8

I understand that you just want the outline of this, so let it be straight but adjustable:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        
        \def\r{1.5} % Radius of corner circles
        \def\l{5}   % Square length
        
        \draw[orange,ultra thin] (0,0) grid (\l,\l);
        
        \draw[line width=3pt]
            (\l,\r)     arc (90:180:\r)  --
            (\r,0)      arc (0:90:\r)    --
            (0,\l-\r)   arc (270:360:\r) --
            (\l-\r,\l)  arc (180:270:\r) -- cycle
            ;
    \end{tikzpicture}
\end{document}

If you want to play with both \r and \l, you would draw some interesting pictures (especially if you select a radius that is greater than half the square length.

length=5 and radius=1.5:
v1

length=5 and radius=3:
v2

(orange grid is just to see dimensions).

7

Perhaps someone is interested in a solution with a configurable number of sides.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

  %%  Pentagon -------------------
\coordinate (o1) at (0,0);
\def\radius{1}   % Radius of corner circles
\def\side{3}      % length of sides
\def\nSides{5}  %  number of sides of the polygon

\pgfmathsetmacro\nSidesMo{\nSides-1}
\pgfmathsetmacro\ang{360/\nSides}
\draw[fill=white] (o1)  \foreach \x in {0,...,\nSidesMo}{-- ++(-\x*\ang*-1^\x:\side) } -- cycle;
\draw[fill=gray] (o1)  ++(0:\radius) \foreach \x in {0,...,\nSidesMo}{ arc (\x*\ang*-1^\x:\x*\ang*-1^\x+ 180-\ang:\radius) -- ++(\x*\ang*-1^\x+180-\ang:\side-2*\radius)} ;
\end{tikzpicture}
\end{document}

enter image description here

1
  • 1
    Thats pretty interesting, and in fact, it fits in the idea Im trying to do.
    – riccs_0x
    Jan 16, 2021 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .