pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
187 stars 33 forks source link

Incorrect path segments using intersection segments option from fillbetween library #459

Open jasperhabicht opened 1 year ago

jasperhabicht commented 1 year ago

Brief outline of the bug

When using the intersection segments option from the fillbetween library, sometimes the path segments are not calculated correctly, especially when applied to curved paths such as circles or arcs.

I was not able to find a rule for it, but sometimes segments are too large and they would overlap the previous segment even, sometimes the curve is not drawn properly at the end of the segment.

Why is this and how can one circumvent this behaviour?

(PGF Version: 2021/05/15 v3.1.9a)

Minimal working example (MWE)

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{fillbetween, spy}

\begin{document}
\begin{tikzpicture}
    [spy using outlines={circle, magnification=4, size=1cm, connect spies}]

\path[draw=green, name path=CircleA] 
    (120:1) circle[radius=0.25];

\path[draw=magenta, name path=ArcA] 
    (180:1) arc[start angle=180, end angle=0, radius=1];

\draw[cyan, intersection segments={of=CircleA and ArcA, sequence=R3}];

\spy[black!25] on (102.5:1)
    in node at (0,0);

\path[draw=green, name path=CircleB] 
    ([yshift=20pt]120:1) circle[radius=0.25];

\path[draw=magenta, name path=ArcB] 
    ([yshift=20pt]180:1) arc[start angle=180, end angle=0, radius=1];

\draw[yellow, intersection segments={of=CircleB and ArcB, sequence=R2}];

\spy[black!25] on ([yshift=20pt]102.5:1)
    in node at (0,2.5);

\end{tikzpicture}
\end{document}

image

I would expect the yellow segment to start at the intersection of the green circle and the magenta arc. Also, I would expect the cyan path to be exactly drawn over the magenta arc.

muzimuzhi commented 1 year ago

Using only tikz library intersection the output looks fine, so I think the problem comes from fillbetween, which is only available if pgfplots is loaded. Hence I'm transferring this issue to https://github.com/pgf-tikz/pgfplots.

An intersection-only example

```tex \documentclass[border=10pt]{standalone} \usepackage{tikz} \usetikzlibrary{intersections} \begin{document} \begin{tikzpicture} \path[draw=green, name path=CircleA] (120:1) circle[radius=0.25]; \path[draw=magenta, name path=ArcA] (180:1) arc[start angle=180, end angle=0, radius=1]; \draw[name intersections={of=CircleA and ArcA, name=x, total=\x}] (x-1) -| (x-2); \end{tikzpicture} \end{document} ``` ![image](https://user-images.githubusercontent.com/6376638/229128764-c3a38368-f37c-4c19-9125-ea3ca0a760dd.png)