13

How do I draw a semicircle in TikZ? A and B are the endpoints of its diameter, and I have two other points specified. I have a command that is not able to be compiled. I put a "%" in front of it.

\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}
  • Look here : http://tex.stackexchange.com/questions/15972/whats-the-easiest-way-to-draw-the-arc-defined-by-three-points-in-tikz The semicircle is easy. The hard or tedious part is finding start and end angles. For such, tkz-euclide gives really handy macros. – percusse Sep 21 '16 at 01:07
  • @percusse All the codes at this website involve a lot of code for just drawing a semicircle. And I am not familiar with pgfmathsetmacro and \newcommand. – A gal named Desire Sep 21 '16 at 01:19
  • @percusse I know that I can draw the semicircle with the commands and \draw(A) -- (B); and \draw (1.5,0) arc (0:180:1.5);. I thought it would be nice to have one command for it. – A gal named Desire Sep 21 '16 at 01:19
  • as i said drawing is the easy part you need the angles and the radius. That's why they go through the hoops – percusse Sep 21 '16 at 01:43
  • 1
    You can always make a node if you really want a simple semicircle-maker. \usetikzlibrary{shapes.geometric} ... \node [semicircle] {}; .... – cfr Sep 21 '16 at 03:29
  • A semicircle is a special case of an arc. Drawing arcs is explained in Section 2.10 of the TikZ/pgf manual. –  Sep 21 '16 at 05:34

2 Answers2

19

Since all coordinates are known, it's possible to draw a circle with defined radius into a clipping rectangle. The result is a semicircle. After that, only base and labels should be added.

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

enter image description here

Update:

To avoid the problems that Tobi mention in his comment, for this particular case is easy to write:

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

Now the semicircle can be filled without problems and exist connections between base and arc as can be seen in following detail.

enter image description here

Ignasi
  • 136,588
  • 1
    But in that case half of the line width in the left and right part of the circle gets cropped too and furthermore there is no connection between the base and the arc. – Tobi Sep 21 '16 at 09:13
  • @Tobi. You're right. I hope the second solution solves both problems. – Ignasi Sep 21 '16 at 09:25
  • @Ignasi Yes, that is the simple command that I wanted. Instead of typing -- as I would for drawing a line segment between two points, I type arc to indicate that I want a circular path from the point before arc to the point after arc. – A gal named Desire Sep 21 '16 at 13:35
  • @Tobi Thanks for the comment. Yes, I am sure that I will use the option fill in a draw command to fill a circular sector. – A gal named Desire Sep 21 '16 at 13:35
11

Since the semicircle is not rotated and the radius is known, the drawing can be done without explicit calculations:

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

Result

Heiko Oberdiek
  • 271,626