2

enter image description here

I want to draw circles like the above picture and I also want to draw mroe than two dots and more than two chords.

Can someone provide me with one simple example for the circle with two dots and one chords and I should be able to do the rest on my own.

4

For starting:

\documentclass[border=3mm,tikz]{standalone}
    \usetikzlibrary{positioning}

    \begin{document}
    \begin{tikzpicture}[
Circ/.style={draw,shape=circle,minimum size=12mm, node contents={}}
                        ]
\node (C1) [Circ];
%
\node (C2) [Circ,right=11mm of C1];
\draw[blue]     (C2.south west) -- (C2.north east);
\fill[black]    (C2.south west) circle (2pt)
                (C2.north east) circle (2pt);
%
\node (C3) [Circ,below=11mm of C1];
\draw[blue]     (C3.north west) -- (C3.north east);
\draw[red]      (C3.south west) -- (C3.south east);
\fill[black]    (C3.north west) circle (2pt)
                (C3.south west) circle (2pt)
                (C3.south east) circle (2pt)
                (C3.north east) circle (2pt);
%
\node (C4) [Circ,below=11mm of C2];
\draw[blue]     (C4.north west) -- (C4.south west);
\draw[red]      (C4.north east) -- (C4.south east);
\fill[black]    (C4.north west) circle (2pt)
                (C4.south west) circle (2pt)
                (C4.south east) circle (2pt)
                (C4.north east) circle (2pt);
    \end{tikzpicture}
\end{document}

For learn TikZ I suggest to read TikZ (really huge) manual. There are good introductions and overview (chapter: TikZ ist kein Zeichenprogram), which is beginning more than enough.

enter image description here

2

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

4 circles with chords

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

circles and chords

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}

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.