2

I am wondering if intersections can be used to extract a subpath from a circle/ellipse path. I have two ellipses, and I am trying to plot only the perimeter of the union. Considering the following code and the associated figure. Is there a way to build a path going from 1 to 2 following the green arc, then from 2 to 3 following the red arc, etc. ?

Ellipses

\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}
 \draw[name path=e1,green] (0,0) ellipse [x radius=1, y radius=2,
 rotate=30];
 \draw[name path=e2,red] (0,0) ellipse [x radius=.8, y radius=3, rotate=-30];
 \fill [name intersections={of=e1 and e2, name=i, total=\t}]
 [every node/.style={left}]
 \foreach \s in {1,...,\t}{(i-\s) circle (2pt) node {\footnotesize\s}};
\end{tikzpicture}
\end{document}```
2
2

My spath3 TikZ library can handle this. It's not clear if you want the components put together into a single path or you want them to stay separate (so that, for example, they can be differently coloured). In this code, I've put them together.

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

\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{intersections,spath3}

\begin{document}
\begin{tikzpicture}
 \draw[spath/save=e1,green, line width=4pt] (0,0) ellipse [x radius=1, y radius=2,
 rotate=30];
 \draw[spath/save=e2, red, line width=4pt] (0,0) ellipse [x radius=.8, y radius=3, rotate=-30];
 \draw [name intersections={of=e1 and e2, name=i, total=\t}]
 [every node/.style={left}]
 \foreach \s in {1,...,\t}{(i-\s) circle[radius=6pt] +(-6pt,0) node {\footnotesize\s}};
 \tikzset{
   spath/split at intersections={e1}{e2},
   spath/get components of={e1}\Acpts,
   spath/get components of={e2}\Bcpts,
 }
 \draw[
   ultra thick,
   spath/use=\getComponentOf\Acpts{2},
   spath/use={\getComponentOf\Bcpts{4},weld},
   spath/use={\getComponentOf\Acpts{4},weld},
   spath/use={\getComponentOf\Bcpts{2},weld},
   ] -- cycle;
 ;
\end{tikzpicture}
\end{document}`

The result of this is:

Spliced and diced ellipses

I've changed your intersection decorations to hollow circles so that you can see the effect of the weld parameter in joining the path seamlessly.

There's a slight artefact at location 1. That's where the path starts and ends and there is a slight difference between the start point and the end point so the PDF viewer puts a tiny line segment in there and that causes the spur. I've thought of an idea of how to fix it, and I'll add that to the next version (the development version can be found at github).

2
  • This is really great and it is exactly what I was looking for. Nevertheless, the code you posted does not compile on my installation With the CTAN version. I get ! Missing number, treated as zero. <to be read again> \tikz@lastmovetoy l.27 ] -- cycle; and with the github version, I have an error at installation ! Package doc Error: Checksum not passed (8929<>8324) and another while compiling the example ! Missing number, treated as zero. <to be read again> \tikz@lastmovetoy l.20 }.
    – Marc Boyer
    Mar 1 at 11:23
  • @MarcBoyer Firstly, ignore the Checksum warning - that's something I only bother with when I upload to CTAN (also, if you install with tex spath3_code.dtx you won't get that warning and it'll be quicker). The other error is strange - I'm not getting that with either the ctan or github versions. Any chance you can send me your log file? My email is in the spath3 documentation. Mar 1 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.