I want to draw this simple picture:

enter image description here

The shapes of points (blue circles) are not important, they are just for example.

The point is that I want to have smth like variable R inside {tikzpicture} drawing the picture. It will give an opportunity to generate automatically different pictures. I've found some examples of using variables, but they are not, what I want.

A pseudocode of what I expect:

double R = 10;
coordinate (A) at (0, 0);
coordinate (B) at (-R, 0);
coordinate (C) at (-R, R);
draw (A) circle (R);
draw (B) -- (C); 
fill[blue] (A) circle (1pt);
fill[blue] (B) circle (1pt);
fill[blue] (C) circle (1pt);

How can I do that in tex?

  • you could use tkz-euclide
    – js bibra
    Dec 3 '20 at 14:29
  • have a look at the answer below
    – js bibra
    Dec 3 '20 at 15:35

You can use your syntax almost literally except that you have to add backslashes. I also use circle[radius=R] instead of circle (R), but the latter would work, too, and use a loop for the blue circles.

\begin{tikzpicture}[declare function={R = 4;}]
\coordinate (A) at (0, 0);
\coordinate (B) at (-R, 0);
\coordinate (C) at (-R, R);
\draw (A) circle[radius=R];
\draw (B) -- (C); 
\foreach \X in {A,B,C}
{\fill[blue] (\X) circle[radius=1pt];}

enter image description here

  • wow, this looks cool! declare function={R = 4;} - what does it do? Why can we use R now like a number?)
    – Allok
    Dec 3 '20 at 15:48
  • 1
    @Allok Because TikZ parses these expressions (coordinates, radii, etc), so you can feed them with functions. Such functions can be just constants, as in this case, or more complicated beasts. \draw (1+R,0) -- ({R*sin(30)},2+1); also works because the components get parsed.
    – user229669
    Dec 3 '20 at 15:53

like this


\coordinate (A) at (0, 0);
\coordinate (B) at ({-\R}, 0);
\coordinate (C) at (-\R, \R);
\draw (A) circle ({\R});
\draw (B) -- (C); 
\fill[blue] (A) circle (1pt);
\fill[blue] (B) circle (1pt);
\fill[blue] (C) circle (1pt);


enter image description here

  • that's very close, thanks! but in that case R - smth like global variable, is there a way to make it local, only inside {tikzpicture}?
    – Allok
    Dec 3 '20 at 14:55

a rough approximation with tkz-euclide

enter image description here

    %arbitrary points
    %tangent to circle
    %mid point of tangent line
    \tkzDrawLine[add=0.8 and 0](A,P)
    %perpendicular to tangent
    \tkzDefLine[orthogonal =through P](A,B)\tkzGetPoint{X}\tkzDrawPoint(X)
    %draw circle with radius XP

  • thanks! is there a way to have a variable for 3 (which you use for A and B) using tikz or tikz-euclide instruments?
    – Allok
    Dec 3 '20 at 15:40
  • the answer by @rpapa does that
    – js bibra
    Dec 3 '20 at 15:49

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.