An optimized set of tikz code?

One path for everything. EDIT: Because AndréC accused me of copying from "his" answer, this the original answer:

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[rotate=45]  foreach \Y in {1,2} 
   {(0,0) circle[radius=\Y]
    ({-\Y/sqrt(2)},{-\Y/sqrt(2)}) rectangle ({\Y/sqrt(2)},{\Y/sqrt(2)})
   foreach \X in {45,135,225,315}
   { (\X:\Y) circle[radius=\Y]}};
\end{tikzpicture}
\end{document}

To put things into perspective:

  1. Paul Gaborit's answer is also one path. I should have mentioned this above.
  2. Paul Gaborit had the first answer here, which I upvoted, and which uses polar coordinates.
  3. As one can see, I used polar coordinates right from the start.
  4. The new features of this answer are two nested foreach loops and drawing the rotated rectangles as rotated rectangles.
  5. On the other hand AndréC's answer copies the two loops from mine. (I became only aware of "his" answer long after the following code was written.)

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[rotate=45]  foreach \Y in {1,2} 
   {(0,0) circle[radius=\Y]
    (45:\Y) rectangle (225:\Y)
   foreach \X in {45,135,225,315}
   { (\X:\Y) circle[radius=\Y]}};
\end{tikzpicture}
\end{document}

enter image description here


Here is a solution (not the shortest):

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw
  circle (1) circle(2)
  (0:1) --(90:1) -- (180:1) -- (270:1) -- cycle
  (0:1) circle(1) (90:1) circle(1) (180:1) circle(1) (270:1) circle(1)
  (0:2) --(90:2) -- (180:2) -- (270:2) -- cycle
  (0:2) circle(2) (90:2) circle(2) (180:2) circle(2) (270:2) circle(2);
\end{tikzpicture}
\end{document}

Just for fun:

\documentclass[tikz,margin=5mm]{standalone}
\begin{document}
\begin{tikzpicture}

\draw (0,0) circle (1) circle (2);

\foreach \t/\n in {0/1,90/2,180/3,270/4}{
  \draw (\t:1)coordinate(\n) circle (1)  ;}

\foreach \t/\m in {0/5,90/6,180/7,270/8}{
  \draw (\t:2)coordinate(\m) circle (2) ;}

\draw (1)--(2)--(3)--(4)--cycle;
\draw (5)--(6)--(7)--(8)--cycle;  


\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf