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}
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}
Best Answer
The problem seems to be that the
intersections
library (which is used by bothfillbetween
andspath3
) finds two intersection points between the circle and the green line: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 undocumentedintersection of
syntax without any extra library. Though, you could also useintersections
here.I'm using the
calc
library for a shorter syntaxCode
Output
For your updated problem, I've tried with
fillbetween
– it didn't work, so here's aspath3
solution.Instead of specifying which segments you want between the intersection of two paths, the approach is kind of the opposite:
In a recent answer of mine I provide (almost) the same picture once with
fillbetween
and once withspath3
.Code
Output