I have used the following code to create triangles inside a circle which works really well. Can anybody point me in the direction to somewhere I can learn to adapt this code so for example creating the double angle rule or cyclic quadrilaterals?

\usetikzlibrary {angles,quotes}
\pgfmathsetseed{\pdfuniformdeviate 10000000}



\foreach \p in {{A/2,B/2,C/4,D/5},{A/2,B/3,C/4,D/6,E/9}}{
    \pgfmathsetmacro\r{2cm} \pgfmathsetmacro\ld{3mm}
    \foreach \l/\v[evaluate=\v as \s using \s + \v,remember=\s as \s (initially 0),
    remember=\l as \ls,remember=\v as \lv] in \p{}
    \pgfmathsetmacro\unit{360/\s} \pgfmathsetmacro\ai{rnd*360}
    \fill circle(1pt) coordinate (I); \draw circle(\r pt);
    \draw (\ai:\r pt)
    \foreach \l/\v[evaluate=\v as \s using \psum + \v, remember=\s as \psum (initially 0)]
    in \p {-- ({\unit*\psum+\ai}:\r pt) coordinate (\l)} -- cycle;
    \foreach \l/\v in \p {
      \draw (I) -- (\l); \fill (\l) circle (1pt);
      \node at ($(I)!\r pt+\ld pt!(\l)$) {$\l$};
    \node[circle,inner sep=0.1pt] at ($(I) + (\ai:3mm)$) {$O$}; %labeled O But     Referenced I
    \foreach \l/\v[remember=\l as \pl (initially \ls),remember=\v as \pv (initially \lv)]
    in \p {\node at ($(I)!\r pt+\ld pt!($(\pl)!.5!(\l)$)$) {\pv};}

I don't know if this out of the purview of this site, I am asking for help on where to learn (but obviously any help would be nice). Thanks

  • 2
    My first response to seeing that code is a desire to simplify it, as it is far more complicated than it needs to be. Jun 18 at 12:54
  • Sorry to bother you but can you give me an indication of why? Or point me in a direction for help?
    – Paul A
    Jun 18 at 12:57
  • 1
    This is TikZ, you can look for documentation of commands in texdoc pgfmanual (look up \foreach, \pgfmathsetmacro etc. to see what they do) If something doesn't make sense you might have to resort to learn how the underlying engine work, read TeXbook/TeX by topic etc.)
    – user202729
    Jun 18 at 12:59
  • Thanks for your help
    – Paul A
    Jun 18 at 13:02
  • 1
    Seriously, making sense of this code is probably harder than starting from scratch. Jun 18 at 13:02

3 Answers 3


Your code:

  • contain error(s), therefore we cannot test it;
  • is very -- to my opinion unnecessary -- complex and unclear (I must confes, that I went lost in it);
  • is not entirely clear, what should your code produce.
  • If your code should draw circle around (any) triangle, then this can be done on far more simple way to do this:
    • first draw circle,
    • then on circle define three (random) points for triangle corners coordinates
    • draw lines between defined coordinates.
\pgfmathsetseed{\pdfuniformdeviate 10000000} 

trig format=rad,
dot/.style = {circle, fill, inner sep=1pt, outer sep=0pt},
ang/.style = {draw=red, <->,
              angle radius = 3mm,
              angle eccentricity=1.2,
% circle
\draw (0,0) coordinate (O) circle[radius=\r];
% triangles' corners coordinates and labels
\foreach \c/\l in {rand/A, rand/B, rand/C}  % define random coefficients 
                                            % for calculations of triangle's 
                                            % corners coordinates on circle
                                            % and define corners names
\pgfmathsetmacro{\C}{2*pi*\c}               % calculate triangle coordinates
  \node (\l) [dot] at (\C:\r) {};           % draw dots at triangle corners
  \draw[-Stealth, gray, very thin]          % draw arrows from circle center 
                                            % to triangle's corners, 
                                            % if not needed, just delete this line 
        (0,0)   -- (\l);
  \path (\l) -- (\C:\R) node {\l};          % define corners labels coordinates,
                                            % they are in direction of vector 
                                            % from circle origin to dot node
% triangle
        (A) -- (B) -- (C) -- (A);           % draw trangle

An random result is (it is different after each compilation, is this what you after?):

enter image description here

  • Thank you so much, and your comments have helped me understand what is going on. I owe you a drink.
    – Paul A
    Jun 18 at 20:14

Another pedagogical (I hope) example:


    % rotate (six time) a square around hi center
         \foreach \i in {15,30,...,90}
         \filldraw[blue!60!brown,line width=1pt,rotate around={\i:(4,0)}]
         % fix a circular zone where to place the Euler picture
         \path [clip] (4,0) circle (2.9);
         \node at (4,0) () {\includegraphics[width=10cm]{Euler.png}};
         %the circle atound the picture
         \draw[white,line width=4pt] (4,0) circle(2.9);
         %some text on top snd on bottom of the picture
         \node[white] at (4,3.15) () {\LARGE \bfseries L. Euler};
         \node[white] at (4,-3.2) () {\huge \bfseries $e^{i\pi}+1=0$};

The output:

enter image description here


Two more examples:

\usetikzlibrary{ decorations.markings}

        \filldraw[gray!60] (0.25,.25)--(0,0)--(11.75,0)--(12,.25);
        \filldraw[gray] (0,0) rectangle (11.75,-.5);
        \filldraw[gray!40] (11.75,0)--(11.75,-.5)--(12,-.25)--(12,.25);
        % lance
        \foreach \i in {1,1.5,...,6}
            \draw[line width=3pt,-latex] (\i,0.1)--(\i,\i-.1);
        \foreach \i in {.5,1,...,5}
        \draw[line width=3pt,-latex] (\i+6,0.1)--(\i+6,5.9-\i);
         \filldraw[snake=snake,blue,line width=1pt]
         \filldraw[blue] (4,0) circle(3.25);
         \shade[ball color=gray!5] (4,0) circle (2);
         \foreach \i in {2,2.417,2.824,3.25}
         \draw[yellow!30,line width=2.5pt] (4,0) circle(\i);
         \node[blue] at (4,0) () {\Huge \bfseries $e^{i\pi}+1=0$};
         \filldraw[white] (4,3.5) circle(2pt);


enter image description here

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.