# Semicircle from a circle in TikZ

Referring to the \clip answer in Drawing a semicircle in TikZ, I wanted to draw a semicircle. But the approach doesn't work here.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (8,0);
\coordinate[label=above:C] (C) at ($(A)!.5!(B)$);
\coordinate[label=above:D] (D) at ($(A)!.5!(C)$);
\coordinate[label=above:E] (E) at ($(B)!.5!(C)$);

\draw[dashed] (A) -- (B);
\draw (D) let \p1 = ($(C) - (D)$) in circle ({veclen(\x1,\y1)});
\clip (A) rectangle (8,8);
\end{tikzpicture}
\end{document}


Also, when using relative points like C, D and E, how to determine the end point of the rectangle while clipping in \clip (A) rectangle (8,8);.

If you want to draw a semicircle, why not to use an arc?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (8,0);
\coordinate[label=above:C] (C) at ($(A)!.5!(B)$);
\coordinate[label=above:D] (D) at ($(A)!.5!(C)$);
\coordinate[label=above:E] (E) at ($(B)!.5!(C)$);

\draw[dashed] (A) -- (B);
\draw (A) let \p1 = ($(C) - (D)$), \n1={veclen(\x1,\y1)} in arc[start angle=180, end angle=0, radius=\n1];
\end{tikzpicture}
\end{document}


Put \clip before the things to be clipped.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (8,0);
\coordinate[label=above:C] (C) at ($(A)!.5!(B)$);
\coordinate[label=above:D] (D) at ($(A)!.5!(C)$);
\coordinate[label=above:E] (E) at ($(B)!.5!(C)$);
\clip (A) rectangle (8,8);

\draw[dashed] (A) -- (B);
\draw (D) let \p1 = ($(C) - (D)$) in circle ({veclen(\x1,\y1)});
\end{tikzpicture}
\end{document}

• Can you also help with the second query. Apr 18, 2019 at 12:23

Better yet, put the clip inside a scope for safety.

As for the clipping rectangle, obviously (A) is one corner and the other corner should be high enough without adding space to the image (bounding box).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (8,0);
\coordinate[label=above:C] (C) at ($(A)!.5!(B)$);
\coordinate[label=above:D] (D) at ($(A)!.5!(C)$);
\coordinate[label=above:E] (E) at ($(B)!.5!(C)$);
\draw[dashed] (A) -- (B);
\path (D) let \p1 = ($(C) - (D)$) in circle ({veclen(\x1,\y1)});% set bounding box
\begin{scope}
\clip (A) rectangle (current bounding box.north east);
\draw (D) let \p1 = ($(C) - (D)$) in circle ({veclen(\x1,\y1)});
\end{scope}
\end{tikzpicture}
\end{document}