5

I want to draw the following figure:

enter image description here

The accepted answer of SebGlav from this post gives some code.

The code (due to SebGlav):

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\newcommand{\RadiusA}{8} %Define the radius of big-boundary circle
     \pgfmathsetmacro{\RadiusB}{\RadiusA/(1+2/sqrt(3))}
     \begin{tikzpicture}
         \draw[] (0,0) circle[radius=\RadiusA cm];
         \foreach \ang [count = \i from 1] in {90,210,330}
             \draw[] (\ang:\RadiusA-\RadiusB) coordinate (center-\i) circle[radius=\RadiusB cm];
         \pgfmathsetmacro{\RadiusC}{\RadiusB/(1+2/sqrt(3))}
         \foreach \i in {1,2,3}
             \foreach \ang in {90,210,330}
                 \draw[] ($(center-\i)+(\ang:\RadiusB-\RadiusC)$) circle[radius=\RadiusC cm];
         
         % Divide each small circle into 3 equal circles
         \foreach \i in {1,2,3}
             \foreach \ang in {90,210,330}
                 \foreach \j in {0,1,2}
                     \draw[] ($(center-\i)+(\ang:\RadiusB-\RadiusC)+(120*\j:\RadiusB/3)$) circle[radius=\RadiusB/6];
                     %this is the main governng equation for small circles
     \end{tikzpicture}
\end{document}

plotted the following figure:

enter image description here

But the above figure can further be improved by improving the last governing equation

\draw[] ($(center-\i)+(\ang:\RadiusB-\RadiusC)+(120*\j:\RadiusB/5)$) circle[radius=\RadiusB/7];

as follows:

enter image description here

The later figure is much better, but still not what I require. We need to make sure the three small circles touch each other, as in the image in my question above.

I think we have to adjust the main governing equation at the end of the code. I appreciate suggestions.

7
  • 1
    If you had to construct the relevant part on paper using a circle, to draw circles, what would you do? How would you formulate, e.g. by words, the process? Translate that into Tikz for a small drawing first, and later into aboves code.
    – MS-SPO
    Sep 8, 2023 at 4:54
  • 1
    Well, aren't the smallest circles just again a repetition of the bigger thing: one circle containing three circles that touch the larger one? Can't you just repeat and scale this? The ratio of the two radii should always be the same. Sep 8, 2023 at 5:06
  • @JasperHabicht, yes absolutely. I am trying to do it. But the last command \draw[] ($(center-\i)+(\ang:\RadiusB-\RadiusC)+(120*\j:\RadiusB/5)$) circle[radius=\RadiusB/7]; needs to be improved. I am unable to do it.
    – learner
    Sep 8, 2023 at 5:13
  • @MS-SPO, yes, I am doing that in the command \draw[] ($(center-\i)+(\ang:\RadiusB-\RadiusC)+(120*\j:\RadiusB/5)$) circle[radius=\RadiusB/7]; but it is not giving as expected. Maybe I am making something wrong in the division of the circle
    – learner
    Sep 8, 2023 at 5:15
  • From the formula of circle packing inside a circle, we know that three unit circles are covered by a circle of radius (1+2/\sqrt(3))
    – learner
    Sep 8, 2023 at 5:54

1 Answer 1

7

An approach to this could be:

  • calculate the ratio between the larger radius and the smaller radius of the circles, this happens to be 1/(1+(2/sqrt(3))).
  • define a function in order to simplify things in the code.
  • repeat and stick the function inside itself for smaller circles.

It should be possible to simplify this even further by self-referential (recursive) code, but I leave it as it is to make the approach more visible:

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

\begin{document}

\begin{tikzpicture}[
        declare function={
            sr(\r) = \r/(1+2/sqrt(3));
        }
    ]

    \draw (0:0) circle[radius=5];
    
    \foreach \a in {90,210,330} {
        \draw (\a:{5-sr(5)}) circle[radius={sr(5)}];

        \begin{scope}[shift={(\a:{5-sr(5)})}]
        \foreach \a in {90,210,330} {
            \draw (\a:{sr(5)-sr(sr(5))}) circle[radius={sr(sr(5))}];

            \begin{scope}[shift={(\a:{sr(5)-sr(sr(5))})}]
            \foreach \a in {90,210,330} {
                \draw (\a:{sr(sr(5))-sr(sr(sr(5)))}) circle[radius={sr(sr(sr(5)))}];
            }
            \end{scope}
            
        }
        \end{scope}
    
    }

\end{tikzpicture}

\end{document}

enter image description here


As stated above, it is possible to create a recursive function here (thanks to Qrrbrbirlbel for their input):

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

\begin{document}

\begin{tikzpicture}[
        declare function={
            sr(\r,\i) = \r/((1+2/sqrt(3))^\i);
        }
    ]

    \draw (0:0) circle[radius=5];
    
    \NewDocumentCommand{\DrawThreeCircles}{ m O{0:0} O{0} m }{
        \begin{scope}[shift={(#2)}]
            \foreach \a in {90,210,330} {
                \draw (\a:{sr(#1,#3)-sr(#1,{#3+1})}) circle[radius={sr(#1,{#3+1})}];
                \ifnum#3<#4
                    \pgfmathtruncatemacro{\x}{#3}
                    \pgfmathtruncatemacro{\y}{#3+1}
                    \DrawThreeCircles{#1}[\a:{sr(#1,\x)-sr(#1,\y)}][\y]{#4}
                \fi
            }
        \end{scope}
    }

    % first argument: radius of largest circle
    % second argument: number of iterations
    \DrawThreeCircles{5}{3}

\end{tikzpicture}

\end{document}

enter image description here

7
  • 3
    sr(\r,\i) = \r/((1+2/sqrt(3))^\i) for sr(5, 0), sr(5, 1), sr(5, 2) might be easier to handle and dynamically to adjust … Sep 8, 2023 at 8:21
  • @Qrrbrbirlbel Yes, this is a nice addition actually! Sep 8, 2023 at 9:28
  • @JasperHabicht, unfortunately, there are error message at the end Package tikz Error: Giving up on this path. Did you forge t a semicolon? and Package tikz Error: Cannot parse this coordinate. I think there is sutle error
    – learner
    Sep 8, 2023 at 9:45
  • @learner You may need to use a proper and up to date LaTeX distribution. I copied and executed the above code and it compiled absolutely fine. So the issue is on your hand. Please don't assume that helpers and very well known members of TeX-SE made errors in the first place.
    – SebGlav
    Sep 8, 2023 at 11:27
  • @SebGlav, agree it might be the problem in MikTeX, which I am saying since my last question. Regarding your last sentence, I don't agree with because anybody can make mistake and there can be error while copying and paste in general. I think the only gateway is your approach from my previous question
    – learner
    Sep 8, 2023 at 11:31

You must log in to answer this question.

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