Intersection between tangent and circle

intersectionstangenttikz-pgf

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

Best Answer

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