18

I'm trying to draw a little picture with TikZ. It should show an equilateral triangle with length 1 and circles with radius 1/2 on each corner of the triangle. Next, the intersections of the circles should be highlighted with a dot. This is what I tried so far:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
    \begin{tikzpicture}[scale=1.5]
    \coordinate (a) at (0,0);
    \coordinate (b) at (1,0);
    \coordinate (c) at (0.5,0.866);

    \draw[dashed] (a)--(b)--(c)--(a);
    \draw[name path=circleA] (a) circle (0.5);
    \draw[name path=circleB] (b) circle (0.5);
    \draw[name path=circleC] (c) circle (0.5);

    \fill (0.5,0) circle (1pt);
    \path [name intersections={of=circleA and circleC,name=AC}];
    \fill (AC-1) circle (1pt);
    \path[name intersections={of=circleB and circleC,name=BC}];
    \fill (BC-1) circle (1pt);
    \end{tikzpicture}
\end{document}

enter image description here

As one can see, the intersections aren't placed exactly where they should be, because the triangle isn't perfectly equilateral. How can I do that?

1
  • Try \coordinate (c) at (60:1); for coordinate c. Then the rest should work out by itself ;-) Commented Apr 5, 2015 at 18:57

7 Answers 7

19

Intersection computations rely on numerically sensitive mechanisms and it does not always give you the precision you are looking for especially if tangents are in question (they get very close and might trigger and early/late true signal). But since the problem is relatively easy geometrically you can get away with many options. Here is another one

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \draw[dashed](0,0) coordinate (a)--+(1,0) coordinate (b)--+(60:1) coordinate (c) --cycle;
  \foreach\x[remember=\x as \lastx (initially c)] in{a,b,c}{
    \node[fill,circle,inner sep=1pt] at($(\x)!0.5!(\lastx)$)  (\x-\lastx) {};
    \draw (\x)circle (0.5);
  }
\end{tikzpicture}
\end{document}

enter image description here

6
  • 2
    @Jeroen: Note the cycle , which gives a better corner. Commented Apr 5, 2015 at 19:39
  • @percusse: Is it necessary (\x-\lastx)? Great answer Commented Apr 5, 2015 at 20:34
  • @jpayansomet Thank you. I don't think so but I couldn't think of something else to, both, stay in the loop and find the midpoints. So I cooked this up. But I'm not really bright on Sunday evenings hence please let me know if I'm missing the obvious.
    – percusse
    Commented Apr 5, 2015 at 20:36
  • @jpayansomet Ah you mean the node names... Yes the question owner said they have to be referenced but after the edit it is gone... See I'm not that bright hahaha
    – percusse
    Commented Apr 5, 2015 at 20:55
  • @percusse: You're right. In my original question, I asked for the nodes to be named, but afterwards, I realised that I don't specifically use the intersections in my text, so it seemed a bit redundant to name them.
    – Jeroen
    Commented Apr 6, 2015 at 14:21
10

Not sure this is the best way, but...

circles at corners

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{shapes.geometric,calc,through}
\begin{document}
  \begin{tikzpicture}
    \node (tri) [regular polygon, regular polygon sides=3, draw, densely dashed, minimum width=50mm] {};
    \foreach \i/\j in {1/2,2/3,3/1}
    {
      \node [draw] at (tri.corner \i) [circle through={($(tri.corner \i)!1/2!(tri.corner \j)$)}, draw] {};
      \path [fill] ($(tri.corner \i)!1/2!(tri.corner \j)$) circle (2.5pt);
    }
  \end{tikzpicture}
\end{document}
6

One way among others of solving this, with MetaPost for whom it may interest. The equilateral triangle is built by rotating a unit side by 60°, and the intersections are found using the intersectionpoint operator. It is interesting to notice that this operator fails with MetaPost's default fixed-point arithmetic. Only after switching to floating-point numerics (\mplibnumbersystem{double}) it is able to find the intersection points.

\documentclass[border=2bp]{standalone}
\usepackage{luamplib}
  \mplibnumbersystem{double}
\begin{document}
  \begin{mplibcode}
    numeric u; u = 5cm; path circle[];
    beginfig(1);
      z1 = origin; z2 = (u, 0); z3 = z2 rotatedaround (z1, 60);
      draw z1 -- z2 -- z3 -- cycle dashed evenly;
      for i= 1, 2, 3:
        circle[i] = fullcircle scaled u shifted z[i];
        draw circle[i];
      endfor;
      z12 = circle1 intersectionpoint circle2;
      z13 = circle1 intersectionpoint circle3;
      z23 = circle2 intersectionpoint circle3;
      for i = 12, 13, 23:
        drawdot z[i] withpen pencircle scaled 5bp;
      endfor 
    endfig;
  \end{mplibcode}
\end{document}

To be typeset with LuaLaTeX. Output:

enter image description here

3
  • You can make this work with the default number system, if you find the intersections before you scale them up. But it won't be very accurate. Then again, you really don't need to use intersectionpoint here - all you need is z12 = .5[z1,z2] etc.
    – Thruston
    Commented Apr 6, 2015 at 22:50
  • @Thruston I knew that, like everybody else here. But computing the intersections was part of the game. Thanks for the remark about the scaling. Previously I noticed (for a different problem) that the linear equation solver also could fail after scaling and succeed before. Commented Apr 6, 2015 at 23:11
  • Yes sure, and the discussion reveals that MP's intersection algorithm is not optimized for find the tangent points of two circles (which is not surprising since it's always the midpoint of the two centres). It's interesting to find out that the intersections work better with the new number system - but that may just be an accident of the way they are implemented.
    – Thruston
    Commented Apr 6, 2015 at 23:15
5

With tkz-euclide (made more verbose for clarity)

\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[scale=.8]
\tkzDefPoint(0,0){A}
\tkzDefPoint(5,0){B}
\tkzDefEquilateral(A,B)\tkzGetPoint{C}
\tkzDrawPolygon[color=magenta,dashed](A,B,C)
\tkzDefMidPoint(A,B) \tkzGetPoint{D}
\tkzDefMidPoint(B,C) \tkzGetPoint{E}
\tkzDefMidPoint(A,C) \tkzGetPoint{F}
\tkzDefCircle[radius](A,D)
\tkzDefCircle[radius](B,E)
\tkzDefCircle[radius](C,F)
\tkzDrawCircle(A,D)
\tkzDrawCircle(B,E)
\tkzDrawCircle(C,F)
\tkzDrawPoints[size=12,fill=green](D,E,F)
%\tkzCentroid(A,B,C)\tkzGetPoint{G}
%\tkzDrawPoint(G)
%\tkzDrawLines[add = 0 and 2/3](A,G B,G C,G)
\end{tikzpicture}
\end{document}

enter image description here

2

Without supplementary libraries:

\documentclass[tikz,margin=5pt]{standalone}
\begin{document}
    \begin{tikzpicture}[scale=3]
        \draw[gray!20,step=.5] (-1,-1) grid (1,1.5); %comment if You dont want a control grid
        \draw (-.5,0) circle(.5) node[below] (a) {$A$};
        \draw (.5,0) circle(.5) node[below] (b) {$B$};
        \path  (.5,0) --+(120:1) node[above] (c) {$C$};
        \draw (c.south) circle(.5);
        \draw[dashed] (a.north)--(b.north) node[pos=.5,red]{\large \textbullet}--(c.south) node[pos=.5,red] {\large \textbullet}--(a.north) node[pos=.5,red] {\large \textbullet};
    \end{tikzpicture}
\end{document}

Output:

enter image description here

2

You can treat the big circles as nodes (big circ/.style) at the ends of the segments and small dots as nodes (sm circ/.style) in the middle. Then you can draw this with one line of code.

enter image description here

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1.5, big circ/.style={draw, circle, minimum size=1cm, solid, transform shape}, sm circ/.style={fill, circle, minimum size=2pt, inner sep=0, transform shape}]
\draw[dashed] (0,0)node[big circ]{}--node[sm circ]{}++(1,0)node[big circ]{}--node[sm circ]{}++(120:1)node[big circ]{}--node[sm circ]{}cycle;
\end{tikzpicture}

\end{document}
0

Also with Mathcha Editor it is possible to draw an equilateral triangle with TikZ.

\documentclass[a4paper,12pt]{article}

\usepackage{tikz}
\begin{document}
\begin{center}
     \tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300

%Shape: Circle [id:dp4307697957160219] 
\draw   (164.2,180.9) .. controls (164.2,151.13) and (188.33,127) .. (218.1,127) .. controls (247.87,127) and (272,151.13) .. (272,180.9) .. controls (272,210.67) and (247.87,234.8) .. (218.1,234.8) .. controls (188.33,234.8) and (164.2,210.67) .. (164.2,180.9) -- cycle ;
%Shape: Circle [id:dp20367667987458704] 
\draw   (272,180.9) .. controls (272,151.13) and (296.13,127) .. (325.9,127) .. controls (355.67,127) and (379.8,151.13) .. (379.8,180.9) .. controls (379.8,210.67) and (355.67,234.8) .. (325.9,234.8) .. controls (296.13,234.8) and (272,210.67) .. (272,180.9) -- cycle ;
%Shape: Circle [id:dp42947116518999584] 
\draw   (217.2,86.9) .. controls (217.2,57.13) and (241.33,33) .. (271.1,33) .. controls (300.87,33) and (325,57.13) .. (325,86.9) .. controls (325,116.67) and (300.87,140.8) .. (271.1,140.8) .. controls (241.33,140.8) and (217.2,116.67) .. (217.2,86.9) -- cycle ;
%Shape: Circle [id:dp072838174083109] 
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (240.2,132.9) .. controls (240.2,130.75) and (241.95,129) .. (244.1,129) .. controls (246.25,129) and (248,130.75) .. (248,132.9) .. controls (248,135.05) and (246.25,136.8) .. (244.1,136.8) .. controls (241.95,136.8) and (240.2,135.05) .. (240.2,132.9) -- cycle ;
%Shape: Circle [id:dp006054378748896028] 
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (268.1,180.9) .. controls (268.1,178.75) and (269.85,177) .. (272,177) .. controls (274.15,177) and (275.9,178.75) .. (275.9,180.9) .. controls (275.9,183.05) and (274.15,184.8) .. (272,184.8) .. controls (269.85,184.8) and (268.1,183.05) .. (268.1,180.9) -- cycle ;
%Shape: Circle [id:dp6162653282895219] 
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (294.2,133.9) .. controls (294.2,131.75) and (295.95,130) .. (298.1,130) .. controls (300.25,130) and (302,131.75) .. (302,133.9) .. controls (302,136.05) and (300.25,137.8) .. (298.1,137.8) .. controls (295.95,137.8) and (294.2,136.05) .. (294.2,133.9) -- cycle ;
%Straight Lines [id:da9010293490310708] 
\draw  [dash pattern={on 4.5pt off 4.5pt}]  (271.1,86.9) -- (218.1,180.9) ;
%Straight Lines [id:da8300036776244188] 
\draw  [dash pattern={on 4.5pt off 4.5pt}]  (325.9,180.9) -- (271.1,86.9) ;
%Straight Lines [id:da31380714189451986] 
\draw  [dash pattern={on 4.5pt off 4.5pt}]  (218.1,180.9) -- (325.9,180.9) ;
\end{tikzpicture}

\end{center}

\end{document}

enter image description here

You must log in to answer this question.

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