This solution demonstrates how to use a pic
to provide an easy way to specify circles of different sizes with or without chords.
To use the pic
in a picture, we specify the following syntax
circ={r=<radius>, d=<diameter>, chord colour=<chord colour>, circ colour=<circle colour>, chords=<list of chords>}
where the <list of chords>
is given as
from <angle> to <angle>, from <angle to <angle>, from ...
This means that, using a standard way of using a pic
in a picture, we can say, for example
\pic [<options>] {circ={r=<radius>, d=<diameter>, chord colour=<chord colour>, circ colour=<circle colour>, chords={from <angle> to <angle>, from <angle to <angle>, from ...}}};
Obviously there is no point in specifying both r
and d
. The last one will simply take precedence.
To create a pic
of this kind, we use the following settings:
\tikzset{%
circ/.pic={%
Our pic
is called circ
.
\tikzset{%
This allows us to pass circ={<options>}
and have them processed.
/circ/.cd,
Set some defaults:
r=.5,
chords={},
chord colour=black,
circ colour=black,
Now set the options passed to the pic
:
#1
}
First, we just draw the outer circle:
\path [pic actions, draw=circ colour] circle (\circradius);
Now we draw the chords by passing the list of chords to make chords
which makes the chords:
\tikzset{%
/circ/make chords/.list/.expand once=\circchords,
}
},
/circ/.search also={/tikz},
Now we need to make sure the keys we need exist and do what we want:
/circ/.cd,
r/.store in=\circradius,
Store the radius in the macro we use when drawing the circle and chords.
d/.code={%
\pgfmathsetmacro\circradius{.5*#1}
If diameter is used, instead, halve it.
},
Now for make chords
. This is the code used to draw a single chord specified in our designated syntax:
make chords/.code args={from #1 to #2}{%
\path [pic actions, draw=chord colour, fill=chord colour] (#1:\circradius) circle (1.5pt) -- (#2:\circradius) circle (1.5pt);
},
When we specify the chords as chords=<chord list>
, we store the value in \circchords
for later processing. This allows us to draw the circle before drawing the chords. So if we want to fill the circle, say, the chords will be on top.
chords/.store in=\circchords,
Default values are a radius of .5
and no chords:
r=.5,
chords={},
Now for the colours, defaulting to black in both cases:
chord colour/.code={\colorlet{chord colour}{#1}},
chord colour=black,
circ colour/.code={\colorlet{circ colour}{#1}},
circ colour=black,
}
And we are done! Now we can write, for example
\begin{tikzpicture}
\pic {circ};
\pic at (1.5,0) {circ={chords={from 45 to -135}, chord colour=blue}};
\pic at (1.5,-1.5) {circ={chords={from 45 to -45, from 135 to -135}, chord colour=red}};
\pic at (0,-1.5) {circ={chords={from 45 to 135, from -45 to -135}, chord colour=green}};
\end{tikzpicture}
to produce

or
\begin{tikzpicture}
\pic [ultra thick] {circ={d=5, chord colour=red, chords={from 45 to -100, from 100 to -135}}};
\pic [thick, double=blue] at (6,0) {circ={r=3}};
\pic [fill=cyan, fill opacity=.15, thick] at (12,0) {circ={r=2, chord colour=cyan!50!blue, circ colour=cyan!25!blue, chords={from -15 to -105, from 20 to 40, from 120 to 160} } };
\end{tikzpicture}
to obtain

Complete code:
\documentclass[tikz,border=10pt,multi]{standalone}
\begin{document}
\tikzset{%
circ/.pic={%
\tikzset{%
/circ/.cd,
r=.5,
chords={},
chord colour=black,
circ colour=black,
#1
}
\path [pic actions, draw=circ colour] circle (\circradius);
\tikzset{%
/circ/make chords/.list/.expand once=\circchords,
}
},
/circ/.search also={/tikz},
/circ/.cd,
r/.store in=\circradius,
d/.code={%
\pgfmathsetmacro\circradius{.5*#1}
},
make chords/.code args={from #1 to #2}{%
\path [pic actions, draw=chord colour, fill=chord colour] (#1:\circradius) circle (1.5pt) -- (#2:\circradius) circle (1.5pt);
},
chords/.store in=\circchords,
r=.5,
chords={},
chord colour/.code={\colorlet{chord colour}{#1}},
chord colour=black,
circ colour/.code={\colorlet{circ colour}{#1}},
circ colour=black,
}
\begin{tikzpicture}
\pic [ultra thick] {circ={d=5, chord colour=red, chords={from 45 to -100, from 100 to -135}}};
\pic [thick, double=blue] at (6,0) {circ={r=3}};
\pic [fill=cyan, fill opacity=.15, thick] at (12,0) {circ={r=2, chord colour=cyan!50!blue, circ colour=cyan!25!blue, chords={from -15 to -105, from 20 to 40, from 120 to 160} } };
\end{tikzpicture}
\begin{tikzpicture}
\pic {circ};
\pic at (1.5,0) {circ={chords={from 45 to -135}, chord colour=blue}};
\pic at (1.5,-1.5) {circ={chords={from 45 to -45, from 135 to -135}, chord colour=red}};
\pic at (0,-1.5) {circ={chords={from 45 to 135, from -45 to -135}, chord colour=green}};
\end{tikzpicture}
\end{document}