5

I have a question about intersection segments in package pgfplots. I want to intersect circle (named mypath) with another circle and would like to draw the intersection segments L1,L2,L3 of the the mypath with the colours yellow,red,green respectively. but L2,L3 segments aren't computed as expected. Why?

\documentclass{standalone}

\usepackage{tikz} \usepackage{pgfplots} \usetikzlibrary{fillbetween}

\begin{document}

\begin{tikzpicture} \path [name path=mypath] (0,0) circle (1); \node[draw,circle,name path=node2] at ( 30:1 ) {2}; \draw[green,intersection segments={of=mypath and node2,sequence={L3}}]; \draw[red,intersection segments={of=mypath and node2,sequence={L2}}]; \draw[yellow,intersection segments={of=mypath and node2,sequence={L1}}]; \end{tikzpicture}

\end{document}

enter image description here

NivMan
  • 161
  • Which segments do you want to draw? The one inside the node? – Alenanno Jan 13 '16 at 12:22
  • @Alenanno I wanted to split the circle mypath to 3 segments. L1 segment L2 segment and L3 segment collored yellow red and green respectively. – NivMan Jan 13 '16 at 13:34
  • 3 segments? I see only two: the circle (green) and the small arc inside the node (red) – Alenanno Jan 13 '16 at 13:35
  • @Alenanno theres aslo a short yellow segment starting at (1,0) and ending at the lower intersection point of the circles. – NivMan Jan 13 '16 at 13:54

1 Answers1

2

I must confess to being slightly confused as to why the extra line appears (I suspect a stray closepath in the underlying soft path), but anyway here's code using version 2.0 of the spath3 package that splits the paths in the right places.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/287401/86}

\usepackage{tikz}

\usetikzlibrary{intersections, spath3}

\begin{document}

\begin{tikzpicture} \path [spath/save=mypath] (0,0) circle (1); \node[draw,circle,spath/save global=node2] at ( 30:1 ) {2};

\tikzset{ spath/split at intersections={mypath}{node2}, every mypath component/.style={draw}, mypath component 1/.style={yellow}, mypath component 2/.style={red}, mypath component 3/.style={green}, spath/render components=mypath, } \end{tikzpicture}

\end{document}

Circle coloured where it intersects with another circle


Editted Feb 2021:

Version 2.2 (now on TL) handles closed paths correctly and the above code produces the following picture.

Circle split where it intersects with another circle.

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751