Anonymous 1123
I rarely draw with 2D. I am trying to draw this figure.
![ScreenHunter 21.png](/image?hash=05234fd5186cfa38c5b3d36bad581ec967943d8d4ff43bd4058fda1a4ab794aa)
I tried.
```
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,declare function={r=2;}]
\draw (0,0) circle[radius=r];
\draw (r,{r*sqrt(3)}) circle[radius=r];
\draw (2*r,0) circle[radius=r];
\draw (0,0)--(2*r,0)--(r,{sqrt(3)*r})--cycle;
\draw (r,{2*r +sqrt(3)*r} )--(-{r*sqrt(3)},-r)--({2*r +r*sqrt(3)} ,-r)--cycle;
\end{tikzpicture}
\end{document}
```
How can I reduce this code?
Top Answer
user 3.14159
There are many possibilities. Here we let Ti*k*Z find the corners. We know that the inner triangle has edge length `2*r`, and the outer ones are the intersections of the tangents to two circles each.
```
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[declare function={r=1;},
c/.style={circle,draw,inner sep=0pt,minimum size=r*2cm}]
\draw foreach \X in {1,2,3}
{++ (-120+120*\X:2) node[c](c\X){}}
(c1.center)-- (c2.center) -- (c3.center) -- cycle
(intersection of c1.30--c2.30 and c2.150--c3.150) --
(intersection of c2.150--c3.150 and c3.-90--c1.-90) --
(intersection of c1.30--c2.30 and c3.-90--c1.-90)
-- cycle;
\end{tikzpicture}
\end{document}
```
![Screen Shot 2021-03-02 at 7.48.50 PM.png](/image?hash=f6d3749c0db6019476b581bb5c514ccc274b268e5feab4d4bd578eb6758dff12)
One can also just compute the relevant coordinates.
```
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[declare function={r=1;},
pics/tricircl/.style={code={%
\path foreach \YY in {1,...,#1}
{foreach \XX in {1,...,\YY}
{({2*r*(\XX-\YY/2-1/2)},{-2*\YY*r*sin(60)}) node[c](c-\XX-\YY){}}};
\draw (c-1-1.center) -- (c-#1-#1.center) -- (c-1-#1.center) -- cycle
({2*r*(1/2-#1/2)-r/tan(30)},{-2*r*#1*sin(60)-r}) --
({2*r*(#1/2-1/2)+r/tan(30)},{-2*r*#1*sin(60)-r}) --
(0,{-2*r*sin(60)+r/sin(30)}) --cycle;
}},pics/tricircl/.default=2,
c/.style={circle,draw,inner sep=0pt,minimum size=r*2cm}]
\path pic{tricircl=2} (8,0) pic{tricircl=3}
(4,-8) pic{tricircl=4};
\end{tikzpicture}
\end{document}
```
![Screen Shot 2021-03-02 at 9.01.27 PM.png](/image?hash=01415797456176f986f9311f2f34b8858bc89d6fc5b8a5163a5928d0968bfc67)