# Tikz: joining points on a circle

I have the following figure

I would like to draw portions of circles between some of the red points. More explicitly, I would like to go from ac1 to ab1 and then to ac2 following circle A, then go to bc1 following circle C and to ab2 following circle B and back to ac1 following circle A.

There is probably a solution using the arc operation, but this would require computing the angles for every portion of circle, which can get tedious. Is there a simple way to do that ?

(I was thinking maybe drawing circles with \clip, but I can't figure out how to do it)

Here is my example code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (-1,-1);
\coordinate (c) at (1,-1);

\draw[name path=circleA] (a) circle (1.5cm);
\draw[name path=circleB] (b) circle (1.5cm);
\draw[name path=circleC] (c) circle (1.5cm);

\fill [red, name intersections={of=circleA and circleB,name=intAB}]
(intAB-1) circle (2pt) node[above left] {ab1}
(intAB-2) circle (2pt) node[below right] {ab2};
\fill [red, name intersections={of=circleA and circleC,name=intAC}]
(intAC-1) circle (2pt) node[above right] {ac1}
(intAC-2) circle (2pt) node[below left] {ac2};
\begin{scope}
\clip (a) circle (1.5cm);
\fill [red, name intersections={of=circleB and circleC,name=intBC}]
(intBC-1) circle (2pt) node[below] {bc1}
(intBC-2) circle (2pt) node {bc2};
\end{scope}

\node (A) at ($(a)+(0,1)$) {$A$};
\node (B) at ($(b)+(-1,0)$) {$B$};
\node (C) at ($(c)+(1,0)$) {$C$};
\end{tikzpicture}

\end{document}

-
 Clips are certainly an easy way to do this, how "clean" do you want the joins to be? – Andrew Stacey Sep 14 '12 at 15:16 In the final document I may not draw the intersection points, so it would be nice if the joints were clean enough so that the line appears continuous. – Corentin Sep 14 '12 at 15:34 In which case clipping is not the best option. That's useful to know. – Andrew Stacey Sep 14 '12 at 15:42 @AndrewStacey With \pgfpatharcto the joints are perfectly clean, so from a practical point of view I am happy with this solution. However, if you have another method with clips, even if joints do not match so well, I would be glad to have a look at the difference and learn something new.. – Corentin Sep 14 '12 at 21:21 Always worth learning! If no-one else beats me to it (and, everyone else, please do!) then I'll add a clip solution next time I'm on a "proper" computer. – Andrew Stacey Sep 14 '12 at 22:43

Here's a solution that uses the nodes that you have defined and the commands

\pgfpointanchor{<node>}{<anchor>}
\pgfpathmoveto{<coordinate>}


The idea is to use \pgfpointanchor to get the coordinates of one the points of intersection. You then use pgfpathmoveto to move there, and then use \pgfpatharcto to draw an arc to the other point of intersection (which you find the coordinates of using \pgfpointanchor again). All of these commands are detailed in the pgf manual.

% new bit
\pgfsetlinewidth{2pt}
% path between ac1 and ab1
\pgfsetstrokecolor{blue}
\pgfpathmoveto{\pgfpointanchor{intAC-1}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{1}{\pgfpointanchor{intAB-1}{south}}
\pgfusepath{stroke}
% path between ab1 and ac2
\pgfsetstrokecolor{red}
\pgfpathmoveto{\pgfpointanchor{intAB-1}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{1}{\pgfpointanchor{intAC-2}{south}}
\pgfusepath{stroke}
% path between ac2 and bc1
\pgfsetstrokecolor{green}
\pgfpathmoveto{\pgfpointanchor{intAC-2}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{0}{\pgfpointanchor{intBC-1}{south}}
\pgfusepath{stroke}
% path between bc1 and ab2
\pgfsetstrokecolor{yellow}
\pgfpathmoveto{\pgfpointanchor{intBC-1}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{0}{\pgfpointanchor{intAB-2}{south}}
\pgfusepath{stroke}
% path between ab2 and ac1
\pgfsetstrokecolor{orange}
\pgfpathmoveto{\pgfpointanchor{intAB-2}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{1}{\pgfpointanchor{intAC-1}{south}}
\pgfusepath{stroke}


Note that some of the paths are traversed clockwise, and some counter clockwise, determined by the 5th argument to \pgfpatharcto

Here's the complete MWE

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (-1,-1);
\coordinate (c) at (1,-1);

\draw[name path=circleA] (a) circle (1.5cm);
\draw[name path=circleB] (b) circle (1.5cm);
\draw[name path=circleC] (c) circle (1.5cm);

\fill [red, name intersections={of=circleA and circleB,name=intAB}]
(intAB-1) circle (2pt) node[above left] {ab1}
(intAB-2) circle (2pt) node[below right] {ab2};
\fill [red, name intersections={of=circleA and circleC,name=intAC}]
(intAC-1) circle (2pt) node[above right] {ac1}
(intAC-2) circle (2pt) node[below left] {ac2};
\begin{scope}
\clip (a) circle (1.5cm);
\fill [red, name intersections={of=circleB and circleC,name=intBC}]
(intBC-1) circle (2pt) node[below] {bc1}
(intBC-2) circle (2pt) node {bc2};
\end{scope}
% new bit
\pgfsetlinewidth{2pt}
% path between ac1 and ab1
\pgfsetstrokecolor{blue}
\pgfpathmoveto{\pgfpointanchor{intAC-1}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{1}{\pgfpointanchor{intAB-1}{south}}
\pgfusepath{stroke}
% path between ab1 and ac2
\pgfsetstrokecolor{red}
\pgfpathmoveto{\pgfpointanchor{intAB-1}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{1}{\pgfpointanchor{intAC-2}{south}}
\pgfusepath{stroke}
% path between ac2 and bc1
\pgfsetstrokecolor{green}
\pgfpathmoveto{\pgfpointanchor{intAC-2}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{0}{\pgfpointanchor{intBC-1}{south}}
\pgfusepath{stroke}
% path between bc1 and ab2
\pgfsetstrokecolor{yellow}
\pgfpathmoveto{\pgfpointanchor{intBC-1}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{0}{\pgfpointanchor{intAB-2}{south}}
\pgfusepath{stroke}
% path between ab2 and ac1
\pgfsetstrokecolor{orange}
\pgfpathmoveto{\pgfpointanchor{intAB-2}{south}}
\pgfpatharcto{1.5cm}{1.5cm}{0}{0}{1}{\pgfpointanchor{intAC-1}{south}}
\pgfusepath{stroke}

\node (A) at ($(a)+(0,1)$) {$A$};
\node (B) at ($(b)+(-1,0)$) {$B$};
\node (C) at ($(c)+(1,0)$) {$C$};
\end{tikzpicture}

\end{document}

-
 Thanks a lot for your answer, this is what I was looking for. I wasn't aware of the command \pgfpatharcto, which is very useful indeed. – Corentin Sep 14 '12 at 21:13

Edit: a new version with better jonctions...

This is not the first question that asks how to draw an arc between two points on a circle with known center. So I decided to create two new styles to meet this need. Here is an example of use:

\draw (a) to[clockwise arc centered at=c] (b);


This command draws an arc starting at a, ending at b, and centered at c (in fact, ending is on a line through c and b if b is not on the circle centered at c and that goes through a).

There are two styles: clockwise arc centered at and anticlockwise arc centered at.

(Due to rounding errors, always use line join=round to get better connections between some arcs.)

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\tikzset{
anticlockwise arc centered at/.style={
to path={
let \p1=(\tikztostart), \p2=(\tikztotarget), \p3=(#1) in
\pgfextra{
\pgfmathsetmacro{\anglestart}{atan2(\x1-\x3,\y1-\y3)}
\pgfmathsetmacro{\angletarget}{atan2(\x2-\x3,\y2-\y3)}
\pgfmathsetmacro{\angletarget}%
{\angletarget < \anglestart ? \angletarget+360 : \angletarget}
}
},
},
clockwise arc centered at/.style={
to path={
let \p1=(\tikztostart), \p2=(\tikztotarget), \p3=(#1) in
\pgfextra{
\pgfmathsetmacro{\anglestart}{atan2(\x1-\x3,\y1-\y3)}
\pgfmathsetmacro{\angletarget}{atan2(\x2-\x3,\y2-\y3)}
\pgfmathsetmacro{\angletarget}%
{\angletarget > \anglestart ? \angletarget - 360 : \angletarget}
}
},
},
}

\begin{document}
\begin{tikzpicture}
% 3 centers (a, b, c)
\coordinate (a) at (0,0);
\coordinate (b) at (-1,-1);
\coordinate (c) at (1,-1);

% 3 circles
\draw[name path=circleA] (a) circle (1.5cm);
\draw[name path=circleB] (b) circle (1.5cm);
\draw[name path=circleC] (c) circle (1.5cm);

% label of circles
\node (A) at ($(a)+(0,1)$) {$A$};
\node (B) at ($(b)+(-1,0)$) {$B$};
\node (C) at ($(c)+(1,0)$) {$C$};

% intersections of circles (A) and (B)
\path [name intersections={of=circleA and circleB,name=AB}];
% show them
\fill[red] (AB-1) circle (2pt) node[above left] {AB-1};
\fill[red] (AB-2) circle (2pt) node[below right] {AB-2};

% intersections of circles (A) and (C)
\path [name intersections={of=circleA and circleC,name=AC}];
% show them
\fill[red] (AC-1) circle (2pt) node[above right] {AC-1};
\fill[red] (AC-2) circle (2pt) node[below left] {AC-2};

% intersections of circles (B) and (C)
\path[name intersections={of=circleB and circleC,name=BC}];
% show them
\fill[red] (BC-1) circle (2pt) node[above] {BC-1};
\fill[red] (BC-2) circle (2pt) node[below] {BC-2};

\draw[line join=round,orange,fill=orange,fill opacity=.5,line width=1pt]
(AC-2)
to[clockwise arc centered at=a] (AB-2)
to[anticlockwise arc centered at=b] (BC-1)
to[anticlockwise arc centered at=c] (AC-2);

\end{tikzpicture}
\end{document}

-
 I like this, nice work :) – cmhughes Sep 14 '12 at 21:59 Very elegant, thank you very much ! – Corentin Sep 14 '12 at 22:04