4

My code below generate some partial circles. how can I do a clip but discard the partial circles?

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
    \draw (0,0) circle (2cm);
    \draw (0,0) circle (2.5cm);
    \clip (0,0) circle (1.8cm);
    \foreach \i in {-2,-1.5,...,2} {
        \foreach \j in {-2,-1.5,...,2} {
            \draw (\i,\j) circle (0.2cm);
        }
    }
    \end{tikzpicture}
\end{document}

Current output: enter image description here

5

Here is a way:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
    \draw (0,0) circle (2cm);
    \draw (0,0) circle (2.5cm);
    %\clip (0,0) circle (1.8cm);
    \foreach \i in {-2,-1.5,...,2} {
        \foreach \j in {-2,-1.5,...,2} {
        \pgfmathsetmacro\distA{sqrt(max((\i+0.2)^2,(\i-0.2)^2)+max((\j+0.2)^2,(\j-0.2)^2)}
        \ifdim\distA cm<2cm
            \draw (\i,\j) circle (0.2cm);
        \fi
        }
    }
    \end{tikzpicture}
\end{document}

The idea is that the maximum distance from the point (0,0) of the inner circles, has to be less than 2cm. But this way you don't have to clip at all.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.