1

I'm trying to draw a diagram with a curved line inside of the circle, attaching to the edges. What I want is similar to that described here. Here is my code:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\node[draw,circle,minimum size=40pt,red](circ){};
\draw[blue,looseness=1.5]
    (circ.west) to [out=70,in =110]
    (circ.center) to [out=-70,in=-110] (circ.east);

\end{tikzpicture}
\end{document}

The problem, is that the edges of the curve do not align in the way I would like with the edge of the circle. What I want is for the blue curve to extend only to the internal edge of the red circle. Now, I could simply draw the curve first, and use a invisible node, but the problem there is that some of it would still be visible since it extends past the outer edge of the circle. Also, it seems like a decidedly inelegant solution.

Output

2
  • Have a look at the \clip command. Oct 26, 2015 at 16:43
  • @Alain I'm looking at it, but one thing that is confusing is how to specify internal/external diameter. Is there some way to "reuse" the circ node for the clipping path?
    – junius
    Oct 26, 2015 at 16:52

2 Answers 2

1

Something like this?

enter image description here

I set the circle outside sep=0pt. By this coordinates of circle lie on the circle and not outside of circle anymore. Also in the first case put the blue line behind circle:

\documentclass[border=10pt,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}

\node[circle, draw=red,
      minimum size=40pt, outer sep=0pt](circ){};
\scoped[on background layer]
\draw[blue,looseness=1.5]
    (circ.west)   to [out =70,in =110]
    (circ.center) to [out=-70,in=-110] (circ.east);
\end{tikzpicture}
     \end{document}

Second example is with line in front, but line has rounded caps:

\documentclass[border=10pt,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}

\node[circle, draw=red,
      minimum size=40pt, outer sep=0pt](circ){};
 \draw[blue,cap=round,looseness=1.5]
    (circ.west)   to [out =70,in =110]
    (circ.center) to [out=-70,in=-110] (circ.east);
\end{tikzpicture}
     \end{document}

which gives:

enter image description here

2
  • I suppose that would work. Is there anyway to do this without fiddling around with the shorten option? If you'll notice, a few pixels are peaking through on the edges even still.
    – junius
    Oct 26, 2015 at 17:09
  • @KevinKeith, yes, it is, I will correct my answer. It is only need to add to circle option: outer sep=0pt ...:
    – Zarko
    Oct 26, 2015 at 17:14
3

Use the circle to clip everything outside it and draw it in the last place:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node[circle,minimum size=40pt](circ){};
\clip (0,0) circle (20pt);
\draw[blue,looseness=1.5]
    (circ.west) to [out=70,in =110]
    (circ.center) to [out=-70,in=-110] (circ.east);
\node[draw,circle,minimum size=40pt,red,thick] {};
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .