2

I have following code in TiKZ:

\documentclass[border=.5cm]{standalone}

\usepackage{tikz}

\usetikzlibrary{positioning,calc,decorations.text}

\begin{document}
\begin{tikzpicture}

\draw (0, 0) circle (1cm);

\draw[rounded corners = .1cm] (200:1.2cm) arc (200:-20:1.2cm) -- (-20:2.2cm) arc (-20:200:2.2cm) -- cycle;
\draw[] (0,1.25cm) -- (0,2.15cm);

\draw[gray] (-.1cm,2.3cm) -- (-.1cm,3.5cm);
\draw[gray] (200:2.4cm) arc (200:90:2.4cm);
\draw[gray] (90:3.4cm) arc (90:200:3.4cm);

\draw[rounded corners = .1cm, red] (200:2.4cm) arc (200:90:2.4cm) -- (90:3.4cm) arc (90:200:3.4cm) -- cycle;

\end{tikzpicture}
\end{document}

Which result in the following picture: enter image description here

But I need a slightly different image. I need red figure to follow gray vertical line (not at 90 degrees).

Any suggestions will highly appreciate.

bronislav
  • 493

1 Answers1

6

Is this what you want? I use \pgfgetlastxy to get the x and y coordinates of the intersection points. Then I use pgfmath package to compute the polar angle of the intersection points. enter image description here

\documentclass[border=.5cm]{standalone}

\usepackage{pgfmath,tikz}

\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}

\draw (0, 0) circle (1cm);

\draw[rounded corners = .1cm] (200:1.2cm) arc (200:-20:1.2cm) -- (-20:2.2cm) arc (-20:200:2.2cm) -- cycle;
\draw[] (0,1.25cm) -- (0,2.15cm);

\draw[gray,name path=ver] (-.1cm,2.3cm) -- (-.1cm,3.5cm);
\draw[gray,name path=bot] (200:2.4cm) arc (200:90:2.4cm);
\draw[gray,name path=top] (90:3.4cm) arc (90:200:3.4cm);
\path[name intersections={of=top and ver,by=T}];
\path[name intersections={of=bot and ver,by=B}];
\path (T);\pgfgetlastxy{\XT}{\YT};
\path (B);\pgfgetlastxy{\XB}{\YB};
\pgfmathparse{atan2(\YT,\XT)}
\edef\topangle{\pgfmathresult}
\pgfmathparse{atan2(\YB,\XB)}
\edef\botangle{\pgfmathresult}

\draw[thick,rounded corners = .1cm, red] 
(200:2.4cm) arc (200:\botangle:2.4cm) -- (\topangle:3.4cm) arc (\topangle:200:3.4cm) -- cycle;

\end{tikzpicture}
\end{document}