# How to draw a series of simple circle packing illustrations, possibly with Tikz?

For an industrial problem, I would like to be able to draw a series of layouts of the cross section of multistrand electrical wires. These can be simplified by packing in a circular envelope a given number of tangent circles of given diameters. A typical layout I would like to make would be the one with a number of circles (strands) of 19 and density of 8.03 as shown on this page: https://en.wikipedia.org/wiki/Circle_packing_in_a_circle Ideally I would like to change the number of circles, and their diameter, and regenerate easily new layouts at least originally for popular configurations, such as numbers of strands 7, 19, 37... (larger wires have a "roped" configuration, ie a bundle of smaller wire bundles, more complicated, but are not in scope). I cannot size the level of difficulty of this problem, that originally looked to me relatively simple, and even less decide how to start. Would someone provide a guideline?

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}
\begin{document}
\tiny
\begin{tikzpicture}[cable/.style={circle, draw, minimum size=5mm, inner sep=0pt, outer sep=0pt}]
\node[cable] (center) at (0,0) {};
\foreach \i in {1,...,6}
\node[cable] (0-\i) at (60*\i:5mm) {a\i};
% \foreach \i in {6}
% \node[cable] (1-\i) at (60*\i:5mm) {\i};
\foreach \i in {1,...,12}
\node[cable,red] (1-\i) at ({15+30*\i}:.97) {b\i};
\foreach \i in {1,...,12}
\node[cable, blue] (1-\i) at ({0+30*\i}:1.37) {c\i};
\begin{scope}[on background layer]
%\node[circle, draw, blue, fit=(2-1) (2-7), inner sep=-1.8pt] (envelope) {};
\end{scope}
\end{tikzpicture}
\end{document}

• other than drawing circles and making a pic out of it? – percusse Jul 25 '15 at 9:34
• The primary goal is to illustrate various design options. Ideally I would like to be able to define a diameter of strand and perhaps a number per layer, and let the code make the calculations and draw. I can leave with a bit of try and error and change. – Yves Jul 25 '15 at 12:09

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{fit,backgrounds}

\begin{document}

\begin{tikzpicture}[cable/.style={circle, fill=blue!30!black, minimum size=10mm, inner sep=0pt, outer sep=0pt}]

\node[cable] (center) at (0,0) {};
\foreach \i in {0,1,...,6}
\node[cable] (1-\i) at (60*\i:10mm) {};
\foreach \i in {0,1,...,12}
\node[cable] (2-\i) at ({15+30*\i}:1.9315) {};
\begin{scope}[on background layer]
\node[circle, fill=blue!30, fit=(2-1) (2-7), inner sep=-3pt] (envelope) {};
\end{scope}
\end{tikzpicture}
\end{document}


For 37, magic numbers from http://hydra.nat.uni-magdeburg.de/packing/cci/d4.html didn't work so nice. In this case, I've used circle instead of nodes.

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}
\fill[red!40] circle (1);
\fill[blue!40!red] circle (.1479559);
\foreach \i in {0,1,...,6}
\fill[blue!30!red] (60*\i:.2959118) circle (.1479559);
\foreach \i in {0,1,...,12}
\fill[blue!20!red] ({15+30*\i}:0.5715536) circle(.1479559);
\foreach \i in {0,1,...,18}
\fill[blue!10!red] ({10+20*\i}:0.852045) circle(.1479559);
\end{tikzpicture}
\end{document}


• +1. Nice! 1.9315 trick number! :-) – Sigur Jul 25 '15 at 10:36
• @Sigur: Not trick number: Wikipedia says diameter of outside circel is 4.863, then center position for last circles is 4.863/2-circle radius=1.9315. – Ignasi Jul 25 '15 at 11:50
• I have found a paper on the theoretical approach : www.geometrie.tuwien.ac.at/hoebinger/mhoebinger_files/circlepackings.pdf – Yves Jul 25 '15 at 12:58
• @Yves This paper is about circle packing by circles with variable radii. Here, all circles have the same radius. – Paul Gaborit Jul 25 '15 at 14:30
• @Paul Gaborit. Yes but I had imagined this could be handled as a simplified variant of the more general problem. I do have calculation to make, but wanted to be able to make some layouts before. I have also found the link supplied by Ignasi very useful, as all layouts have been drawn for 1 up to 5000 circles (strands), with the associated parameters. in case of wires, there is a tradeoff between the envelope diameter and the "conductor cumulated density" (area). I am exploring how rotating a layer can affect density and envelope diameter at the same time; this may be know already by others.. – Yves Jul 25 '15 at 15:42