如何用 TikZ 绘制等边三角形?

如何用 TikZ 绘制等边三角形?

我正在尝试用 TikZ 画一幅小图。它应该显示一个长度为 1 的等边三角形,三角形的每个角上都有半径为 1/2 的圆。接下来,圆的交点应该用 突出显示dot。这是我到目前为止尝试过的:

\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}

在此处输入图片描述

可以看出,由于三角形不是完全等边的,所以交点的位置并不准确。我该怎么做呢?

答案1

交叉口计算依赖于数值敏感机制,它并不总是能提供您想要的精度,尤其是在切线问题上(它们非常接近,可能会触发早期/晚期真实信号)。但由于问题在几何上相对简单,因此您可以采用多种选择。这是另一个

\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}

在此处输入图片描述

答案2

不确定这是否是最好的方法,但是......

角落处的圆圈

\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}

答案3

解决这个问题的方法之一是使用 MetaPost,你可能会感兴趣。等边三角形是通过将单位边旋转 60° 来构建的,并使用运算符找到交点intersectionpoint。有趣的是,这个运算符在 MetaPost 的默认定点算法中失败了。只有切换到浮点数值(\mplibnumbersystem{double})后,它才能找到交点。

\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}

使用 LuaLaTeX 排版。输出:

在此处输入图片描述

答案4

没有补充库:

\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}

输出:

在此处输入图片描述

相关内容