在 TikZ 中绘制半圆

在 TikZ 中绘制半圆

如何在 中绘制半圆TikZAB是其直径的端点,并且我指定了另外两个点。我有一个无法编译的命令。我在它前面放了一个“%”。

\documentclass{amsart}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{calc}




\begin{document}

\begin{tikzpicture}[baseline=(current bounding box.north)]

%A semicircle is drawn.
\path (-1.5,0) coordinate (A) (1.5,0) coordinate (B) (60:1.5) coordinate (C) (120:1.5) coordinate (D);
%\draw (A) -- (B) arc (C) arc (D) arc (A) -- cycle;

%Labels for the vertices are typeset.
\node[anchor=north, inner sep=0] at ($(A) +(0,-0.15)$){$A$};
\node[anchor=north, inner sep=0] at ($(B) +(0,-0.15)$){$B$};
\node[anchor=240, inner sep=0] at ($(C) +(60:0.15)$){$C$};
\node[anchor=300, inner sep=0] at ($(D) +(120:0.15)$){$D$};


\end{tikzpicture}

\end{document}

答案1

由于所有坐标都是已知的,因此可以将circle具有定义半径的绘制到裁剪矩形中。结果是一个半圆。之后,只需添加底面和标签。

\documentclass{amsart}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[baseline=(current bounding box.north)]

% A clipped circle is drawn
\begin{scope}
    \clip (-1.5,0) rectangle (1.5,1.5);
    \draw (0,0) circle(1.5);
    \draw (-1.5,0) -- (1.5,0);
\end{scope}
%
%%Labels for the vertices are typeset.
\node[below left= 1mm of {(-1.5,0)}] {$A$};
\node[below right= 1mm of {(1.5,0)}] {$B$};
\node[above right= 1mm of {(60:1.5)}] {$C$};
\node[above left= 1mm of {(120:1.5)}] {$D$};
\end{tikzpicture}

\end{document}

在此处输入图片描述

更新:

为了避免 Tobi 在他的评论中提到的问题,对于这种特殊情况很容易写:

\documentclass{amsart}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[baseline=(current bounding box.north)]

\draw (-1.5,0) -- (1.5,0) arc(0:180:1.5) --cycle;
%
%%Labels for the vertices are typeset.
\node[below left= 1mm of {(-1.5,0)}] {$A$};
\node[below right= 1mm of {(1.5,0)}] {$B$};
\node[above right= 1mm of {(60:1.5)}] {$C$};
\node[above left= 1mm of {(120:1.5)}] {$D$};
\end{tikzpicture}

\end{document}

现在可以毫无问题地填充半圆,并且底面和圆弧之间存在连接,如下面的细节所示。

在此处输入图片描述

答案2

由于半圆未旋转且半径已知,因此无需进行明确计算即可进行绘图:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[baseline=(current bounding box.north)]
  % Define coordinates
  \def\Radius{1.5}
  \path
    (-\Radius, 0) coordinate (A)
    -- coordinate (M)
    (\Radius, 0) coordinate (B)
    (M) +(60:\Radius) coordinate (C)
    +(120:\Radius) coordinate (D)
  ;
  % Draw semicircle
  \draw
    (B) arc(0:180:\Radius) -- cycle
  ;
  % Annotations
  \path[inner sep=0pt]
    (A) node[below=.3333em] {$A$}
    (B) node[below=.3333em] {$B$}
    (C) node[above right=.2em] {$C$}
    (D) node[above left=.2em] {$D$}
  ;
\end{tikzpicture}
\end{document}

结果

相关内容