8

this is my first question in this forum. I want to draw something like a picture from the Wikipedia article about the circle.

This is the picture.

enter image description here

This is what I want to achieve:

  • The circle chord should be in blue. The endpoints of the circle chord (which are on the circle) should be named A and B and shall be written in blue like the chord.
  • The circle arc between A and B shall be red.
  • The line segments from the midpoint to A and midpoint to B shall be dashed and green.
  • Additionally there shall be a short arc which shall picture the angle alpha both in green.
  • The circle chord and the circle arc shall be named and the names colored.
  • I'm unsure how to specify points A and B. In my attempt, I simply drew a line and then calculated the intersection points with the circle. Maybe there are better programming solutions that are less random.
  • And I don't like the solution with \def which is a LaTeX primitive, I don't want to risk and redefine an existing command. Maybe there is an alternative solution for that. I had to do that because it is not possible to use the color{}{} command within the (name intersections ... by)-part.
\documentclass[border=0.5cm]{standalone}
    
% PGF/TikZ
\usepackage{tikz}
\usetikzlibrary{positioning, arrows, shapes, trees, intersections}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
\begin{document}
    
\begin{tikzpicture}[
       help lines/.style = {very thin, color=gray!50}, 
       dot/.style = {circle, fill, inner sep=0pt, radius=2cm}
        ]
    
\def\Ca{\textcolor{blue}{$C$}}
\def\Cb{\textcolor{blue}{$C'$}}
    
\draw[help lines] (-2.5,-2.5) grid (2.5,2.5);
    
\draw[name path=Circle] (0,0) circle[radius=2cm];
\coordinate[label=below:$M$] (M) at (0,0);
\node[draw,fill,circle,inner sep=0pt] at (M) {};
    
\path[name path={Sekante1}] (-2.5,-0.5) -- (2.5,2);
    
\path[name intersections={of=Sekante1 and Circle, by={[label=right:\Cb]C2, [label=left:\Ca]C1}}];
    
    
\draw[blue!50, thick] (C1) -- (C2);
\draw[green, dashed] (M) -- (C1);
\draw[green, dashed] (M) -- (C2);
    
\node[dot] at (C1) {};
\end{tikzpicture}
    
\end{document}

Result:

result

2
  • 1
    Welcome to TeX:SE!
    – Zarko
    Jul 14 at 4:00
  • Welcome. // +1 for your nice first question, providing all we like to see here : )
    – MS-SPO
    Jul 14 at 6:08

5 Answers 5

7

The minimum (no labels) like this:

enter image description here

Code:

\documentclass[border=0.5cm]{standalone}

% PGF/TikZ
\usepackage{tikz}


\begin{document}
    
    \begin{tikzpicture}
        \draw[red,thick] (50:2.5) arc (50:170:2.5) ;
        \draw[thick] (-190:2.5) arc (-190:50:2.5);
        \draw[blue] (50:2.5)--(170:2.5);
        \draw[green,dashed] (0,0)--(50:2.5);
        \draw[green,dashed] (0,0)--(170:2.5);
        \draw[thin] (50:.5) arc (50:170:.5) node[midway, above] () {$\alpha$};

    \end{tikzpicture}
    
\end{document}

EDIT (with some label):

enter image description here

Code (very minimal):

\documentclass[border=0.5cm]{standalone}

\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \path[draw,red,thick,name=a] (50:2.5) arc (50:170:2.5) node[midway,above,sloped] () {arco};
        \draw[thick] (-190:2.5) arc (-190:50:2.5);
        \path[draw,blue,thick,name=b] (50:2.5)--(170:2.5) node[midway,sloped,above] () {corda};
        \draw[green,dashed] (0,0)--(50:2.5);
        \draw[green,dashed] (0,0)--(170:2.5);
        \draw[thin] (50:.5) arc (50:170:.5) node[midway, above,sloped] () {$\alpha$};
    \end{tikzpicture}
\end{document}
6

An alternative approach using Metapost instead of TikZ, just for comparison.

enter image description here

You need to compile this with lualatex.

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
numeric a, b;
a = 1.618; b = 4.2;  % arbitrary "points" round the circle - 8 points in all
path C; 
C = fullcircle scaled 180;

draw subpath (a, b) of fullcircle scaled 42 withpen pencircle scaled 1/4;
draw point a of C -- origin -- point b of C dashed evenly withcolor 2/3 green;
draw point a of C -- point b of C withcolor 1/4[blue, white];
draw subpath (a, b) of C withcolor 3/4 red;
draw subpath (b, a+8) of C;

dotlabel.urt("$A$", point a of C);
dotlabel.llft("$B$", point b of C);
label("$\alpha$", 10 unitvector(point 1/2(a+b) of C)); 
label.ulft("\textsf{Kreissehne}", 1/3[point a of C, point b of C]) withcolor 3/4 blue;
label.ulft("\textsf{Kreisbogen}", point a + 1 of C) withcolor 1/2 red;

endfig;
\end{mplibcode}
\end{document}

Notes

  • The path C is a copy of the built-in fullcircle path scaled to 180 pt (63.5 mm).

  • The path has eight "points" equally spaced around it starting at 3 o'clock, so that point 2 of C is at the top, and point 6 of C at the bottom, and so on.

  • subpath (a, b) of C is the part of C from point a of C to point b of C, moving anti-clockwise, providing a < b. To run anti-clockwise from b to a you add 8 to a.

1
  • Great,when i grow up i need to be like,I have troubles using METAPOST Jul 19 at 18:15
5

Sometimes the longer code can be easier to understand and to modify. So here we go: just an other way to do it. Basic idea:

  • define coordinates first, as this problem allows to do it
  • use A, B and M to draw all relevant geometries
  • finally place labels etc.
  • use polar coordinates almost always

The code below followed this route, and applied just some gentle refactoring to remove duplicates in code. It turned out that using green would have little contrast, so I replaced it by green!50!black!100; perceive !50 and !100 as sliders when mixing green and black.

Some alternatives:

  • you could replace absolute positions, e.g. for the labels, by relative ones
  • you could predefine label coordinates, like \coordinate (LB) at ( 95:2.8); and later put a node there: \node[brown] (KB) {Kreisbogen};
  • you could define and use different arrow-symbols for the pointers and the angles arc
  • you could introduce some \def statements to further predefine the various coordinates and the relationship amongst them: following the paradigm change all in one place only makes adjustments very flexible
  • etc.

result

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}% to draw angle and use greek letters
\usetikzlibrary{arrows.meta}% to change the arrow symbol

\begin{document}
 \begin{tikzpicture}[
        grn/.style=green!50!black!100,% a stronger green
        > = {Stealth}% replacing all standard arrow symbols
    ]
    % ~~~ set coordinates ~~~
    \coordinate (M) at (0,0);   % center
    \coordinate (A) at (170:2); % A
    \coordinate (B) at ( 70:2); % B
        
    % ~~~ arcs ~~~~~~~~~~~~~
    \draw[red]  (B) arc (70:170:2);
    \draw       (B) arc (70:-190:2);% negative, to reverse drawing direction
    
    % ~~~ chords ~~~~~~~
    \draw[blue]         (B) -- (A);
    \draw[grn,dashed]   (B) -- (M) -- (A);
    
    % ~~~ marking the angle ~~~
    \pic["$\alpha$",draw,<->,grn] {angle = B--M--A};% see ch. 41
    
    % ~~~ labels (one way to do it) ~~~
    \node[blue,xshift=-3mm]             at (A) {A};
    \node[blue,xshift=2mm, yshift=2mm]  at (B) {B};
    
    \node[brown] (KB) at (95:2.8) {Kreisbogen};
    \node[brown] (KS) at (140:2.8) {Kreissehne};
    \draw[->] (KB) -- (95:2.1);
    \draw[->] (KS) -- (140:1.5);
 \end{tikzpicture}
\end{document}
3
  • I have noticed that some piece of code of your example gets in conflict with the babel package and ngerman option. This particuar line produces a conflict: ` \pic["$\alpha$",draw,<->,grn] {angle = B--M--A}; ` Why does this happen? And how to solve this with using the babel[ngerman] package. Jul 15 at 2:06
  • Packages do have side effects every now and then. For this drawing no language package is needed, strictly speaking: so leave it out. // Unfortunately I have no idea what kind of conflict you encounter. Please consider posting a new question, where you reference to my code and describe your observation in more detail.
    – MS-SPO
    Jul 15 at 4:58
  • 2
    BTW, @Zarko gave an excellent answer in his EDIT to the language question in his answer. So I suggest NOT to raise another question, as it will have been answered many times already (leading to a close), UNLESS you encounter a problem unknown to this community so far.
    – MS-SPO
    Jul 15 at 6:01
5

Like this:

enter image description here

With use of the angle, arrows.meta and quotes libraries. Sizes of radius and angles are (so far) hard coded, but can be simple replaced by defining \pgfmathsetmacro for them.

Edit:
If you use babel package for support some other languages as are German, Spanish, my native languages, than English, they redefine meaning of some letters used in programing tikz. For such a case is defined tikz library babel, which in the most of cases resolve this issues. Now added to MWE below:

\documentclass[border=0.5cm]{standalone}
\usepackage[ngerman]{babel}  % <--- added

% PGF/TikZ
\usepackage{tikz}
\usetikzlibrary{angles, arrows.meta,
                quotes,
                babel        % <--- added
                }
 %%%%%%%%%%%%%%%%%%%% 

\begin{document}

    \begin{tikzpicture}[
              > = Straight Barb,
ang/.style = {draw, <->,
              angle eccentricity=0.5},
dot/.style = {circle, fill, inner sep=1pt},
help lines/.style = {very thin, color=gray!50},
                        ]
\draw[help lines] (-2.5,-2.5) grid (2.5,2.5);
% drawing red arc
\draw[thick, red]   ( 60:2) arc (60: 180:2cm);
% drawing black arc
\draw[thick]        ( 60:2) arc (60:-180:2cm);
% drawing  secant with labels at the end
\draw[thick,blue]   ( 60:2) coordinate[label=above right:$C'$] (c') --
                    (180:2) coordinate[label=left:$C$] (c);
% center of circle
\node[dot, label=below:$M$] (m) {};
% mark angle
\draw[densely dashed]   (c) -- (m) -- (c');
%  descriptions
\draw[<-] (120:2)-- ++(150:1)  node[left] {Kreisbogen};
\draw[<-] (130:1.5) -- ++ (150:1) node[left] {Kreissehne};
% mark angle
\pic [ang, "$\alpha$"]     {angle = c'--m--c};
\end{tikzpicture}

\end{document}
3
  • I have noticed that some piece of code of your example gets in conflict with the babel package and ngerman option. This particuar line produces a conflict: < \pic [ang, "$\alpha$"] {angle = c'--m--c}; > Why does this happen? And how to solve this with using the babel[ngerman] package. Jul 15 at 0:11
  • 2
    @Texfriend23, if adding library babel resolve your problem. See edited answer.
    – Zarko
    Jul 15 at 3:40
  • Yes, babel resolves the problem. For more details see the TikZ manual and the section about Babel library . There it is explained that Babel makes certain punctuation marks like " to active characters, which then leads to conflicts with the Tikz code, especially when using the quotes library and the charakter " (quotation marks). Just use \usetikzlibrary{babel} . babel library is specially made for this type of conflict. Jul 15 at 21:41
0

Using tzplot:

enter image description here

\documentclass{standalone} 

\usepackage{tzplot}

\begin{document}

\begin{tikzpicture}[font=\scriptsize]
\tzcoor(0,0)(M){$M$}[-90] % center

%% defining A and B: using intersections
\tzline[draw=none]"Sekante1"(-2.5,-0.5)(2.5,2)
\tzcircle[draw=none]"Circle"(M)(2cm)
\tzXpoint{Circle}{Sekante1}(A){$A$}[45]
\tzXpoint{Circle}{Sekante1}(B)[2]{$B$}[180]

%%% alternative way of defining A and B: simple
%\tzcoors(60:2cm)(A){$A$}[45](170:2cm)(B){$B$}[180];

%% arcs
\tzpointangle(M)(A){\angA}
\tzpointangle(M)(B){\angB}
\tzarc'[thick](M)(\angB:\angA:2cm)
\tzarc[thick,red](M)(\angA:\angB:2cm){Kreisbogen}[pos=.3,a]
%% chord
\tzline[thick,blue](A){Kreissehne}[sloped,a](B)
%% dashed lines
\tzline[green,dashed](M)(A)
\tzline[green,dashed](M)(B)
%% dots
\tzdots*(M)(A)(B);
%% angle mark
\tzanglemark[green](A)(M)(B){$\alpha$}[pos=.6]
\end{tikzpicture}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .