3

I am trying to define the tangent line of a circle at a given azimuth then use this intersection to define segment. The MWE here shows that intersection seems badly computed using [turn]90: command to draw the tangent because it create some random intersections with the circle. Thus, I cannot fill the area defined by the intersection of tangents and circle.

\documentclass[tikz,border=5]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{intersections,calc,positioning,quotes,fillbetween}
%
\begin{document}
\begin{tikzpicture}
    \def\R{1}
    \def\angle{30}
    \draw[name path=C,blue] circle[radius=\R];
    \node at (60:\R) {\tiny Fill here};
    \draw[name path=L,green] (30:\R) -- ([turn]90:\R) ;
    \draw[name path=L2,yellow] (90:\R) -- ([turn]-90:\R) ;
    \draw[red,ultra thick,intersection segments={of=L and C,
         sequence={B1}}];
\end{tikzpicture}
\end{document}

enter image description here

Update with full problem

I need to fill the area between 2 circles and 2 tangents of internal circle. I used to use intersection segments to compute the intersection of circles and lines but as far as the intersections library have erronous intersection computation with tangent lines, I didn't manage to create such picture without code duplication. Here is an example based on @Qrrbrbirlbel solution but the filled area has to be reduced by computed intersections of the second circle and tangents. Also, I need to draw the internal arc with a different color than other lines.

\begin{tikzpicture}
    \def\RA{1} \def\RB{2} \def\angleA{75} \def\angleB{-65}
    \filldraw[red,fill opacity=0.3] (\angleA:\RA) coordinate (start)
      arc[start angle=\angleA, end angle=\angleB, radius=\RA] coordinate[at end] (end)
      -- (intersection of start--{$(start)+(\angleA+90:\RB)$}
                        and end--{$(end)  +(\angleB-90:\RB)$})
      -- cycle;
    \draw[red,overlay] (\angleA:\RB) arc[start angle=\angleA, end angle=\angleB, radius=\RB]; % this should limit the fill area and be drawn in red
    \draw[green] (start) arc[start angle=\angleA, end angle=\angleB, radius=\RA]; % this is because I need this segment to be in green
    \end{tikzpicture}
\end{document}

enter image description here

2
  • Can you clarify: "Any idea of how I can split the circle correctly, meaning in the present case that the red segment show go up to 360°?" with more text or an image of the desired result?
    – dexteritas
    Commented Sep 12, 2023 at 14:59
  • @dexteritas In fact, my question was not clear. Is it better now?
    – Sigmun
    Commented Sep 12, 2023 at 15:29

1 Answer 1

3

The problem seems to be that the intersections library (which is used by both fillbetween and spath3) finds two intersection points between the circle and the green line:

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[name path=C]circle[radius=1];
\draw[name path=L](30:1) -- ([turn]90:1);
\path[name intersections={of=C and L, total=\t}]
  node foreach \i in {1, ..., \t} at (intersection-\i) {x};
\end{tikzpicture}
\end{document}

enter image description here

This messes everything up.

In this case, you don't really need fillbetween. You know the angles (30° and 60°) and the intersection between straight lines can be found via the undocumented intersection of syntax without any extra library. Though, you could also use intersections here.

I'm using the calc library for a shorter syntax

Code

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\R{1} \def\angle{30}

\fill[red] (\angle:\R) coordinate (start)
  arc[start angle=\angle, end angle=90, radius=\R] coordinate[at end] (end)
  -- (intersection of start--{$(start)+(\angle+90:1)$} and end--{$(end)+(0:1)$})
  -- cycle;
\end{tikzpicture}

\begin{tikzpicture}
\def\R{1} \def\angleA{75} \def\angleB{-75}

\fill[red] (\angleA:\R) coordinate (start)
  arc[start angle=\angleA, end angle=\angleB, radius=\R] coordinate[at end] (end)
  -- (intersection of start--{$(start)+(\angleA+90:1)$}
                    and end--{$(end)  +(\angleB-90:1)$})
  -- cycle;
\end{tikzpicture}
\end{document}

Output

enter image description here
enter image description here


For your updated problem, I've tried with fillbetween – it didn't work, so here's a spath3 solution.

Instead of specifying which segments you want between the intersection of two paths, the approach is kind of the opposite:

  1. Split the paths at their intersections.
  2. Remove the parts we don't want.
  3. Concatenate the paths in the proper order and direction.

In a recent answer of mine I provide (almost) the same picture once with fillbetween and once with spath3.

Code

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{calc, spath3, intersections}
\begin{document}
\begin{tikzpicture}[spath/save/.append style=overlay]
\def\RA{1} \def\RB{2} \def\angleA{-60} \def\angleB{85}

\path[spath/save=RA] (\angleA:\RA) coordinate (start)
  arc[start angle=\angleA, end angle=\angleB, radius=\RA] coordinate[at end] (end)
  -- (intersection of start--{$(start)+(\angleA+90:1)$}
                    and end--{$(end)  +(\angleB-90:1)$})
  -- cycle;
\path[spath/save=RB]
  (\angleA:\RB) arc[start angle=\angleA, end angle=\angleB, radius=\RB];

\fill[
  red, spath/.cd,
  split at intersections={RA}{RB},
  remove components={RB}{1, 3},
  remove components={RA}{1},
  use=RB,
  append reverse no move=RA];
\end{tikzpicture}
\end{document}

Output

enter image description here

3
  • Thanks for your answer. In fact, I didn't knew the intersection of syntax! I know that was not my initial question, but as far as I simplified my real problem to have this kind of answer, your solution make my real solution a bit complicated. Actually, I need to fill an area between 2 circles of radius RA and RB and the two tangent you've drawn on the second picture. I've manage to do so with intersection segments but with code duplication. Any idea of how to solve my updated problem?
    – Sigmun
    Commented Sep 14, 2023 at 9:16
  • @Sigmun Here, I'd mix the already given solution with the usual find-intersection-and-build-new-paths approach. However, I couldn't get the proper segment with fillbetween which is why I've opted for a spath3 aproach. Commented Sep 14, 2023 at 23:05
  • Thanks @Qrrbrbirlbel
    – Sigmun
    Commented Sep 21, 2023 at 13:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.