3

I'm going straight to the point.

I have two different circles, with two different radii and centers, like shown below:

enter image description here

How can i obtain a complex figure like this one instead?

enter image description here

Here's the code which generates the two circles:

\documentclass{standalone}
\usepackage{tikz} 
\begin{document}
    \begin{tikzpicture}
        \coordinate (c1) at (0,0);
        \coordinate (c2) at (-1.3,0);
    \draw [ultra thick] (c1) circle (1.5);
    \draw [ultra thick] (c2) circle (0.5);
\end{tikzpicture}

\end{document}

I thank you all in advance!

frad
  • 571

2 Answers2

6

In this simply case where you final path only consists of arc segments, you can draw this diagram

  1. by finding the intersections of those two circles with the intersections library
  2. and then drawing the arcs to those points either
    1. by calculating the needed start and end angles for arc[…] (e.g. with let … in) or
    2. by using arcto which does this calculation for you. This needs the ext.paths.arcto library of my tikz-ext package.

Here I'm choosing ext.paths.arcto.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{
  intersections,  
  ext.paths.arcto,% https://ctan.org/pkg/tikz-ext
}
\begin{document}
\begin{tikzpicture}
\coordinate (c1) at (0,0);
\coordinate (c2) at (-1.3,0);

\path[name path=C1] (c1) circle [radius=1.5]; \path[name path=C2] (c2) circle [radius=0.5]; \draw[ultra thick, name intersections={of=C1 and C2}] ([shift=(0:1.5)]c1) arcto[radius=1.5] (intersection-1) arcto[radius=0.5] (intersection-2) arcto[radius=1.5] cycle; %\draw [red,thick] (c1) circle [radius=1.5]; %\draw [red,thick] (c2) circle [radius=0.5]; \end{tikzpicture} \end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
2

The spath3 library can do this (if it doesn't work with the version with your tex distribution, try the one from github).

\documentclass[border=5pt]{standalone}
%\url{https://tex.stackexchange.com/q/660906/86}
\usepackage{tikz}
\usetikzlibrary{spath3,intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (c1) at (0,0);
\coordinate (c2) at (-1.3,0);

\path[spath/save=large circle] circle[radius=1.5]; \path[spath/save=small circle] (c2) circle[radius=0.5];

\tikzset{ spath/remove empty components=large circle, spath/remove empty components=small circle, spath/split at intersections={large circle}{small circle}, spath/get components of={large circle}\largeCpts, spath/get components of={small circle}\smallCpts, }

\draw[ ultra thick, spath/use={\getComponentOf\largeCpts{2}}, spath/use={\getComponentOf\smallCpts{1},weld}, spath/adjust and close=current, ];

\end{tikzpicture} \end{document}

outer edge of two overlapping circles

(There's something a bit odd with the final junction - it isn't joining the end back to the beginning. I need to investigate that further.)

Added in edit: I've figured out the issue - the coordinates at the join are not quite the same. Fortunately, I'd already put in place a fix for that: the key adjust and close. I've changed the code but haven't updated the screenshot.

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