0

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} 

enter image description here

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);.

3

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} 

enter image description here

| improve this answer | |
1

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} 
| improve this answer | |
  • Can you also help with the second query. – subham soni Apr 18 '19 at 12:23
1

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} 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.