# Understanding the code and trying to learn

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?

\documentclass[tikz,margin=2mm,5pt]{standalone}
\usetikzlibrary {angles,quotes}
\usetikzlibrary{calc,positioning}
\pgfmathsetseed{\pdfuniformdeviate 10000000}

\usepackage{scrextend}
\changefontsizes[10pt]{5pt}

\pgfdeclarelayer{back}
\pgfdeclarelayer{front}
\pgfsetlayers{back,main,front}

\begin{document}
\foreach \p in {{A/2,B/2,C/4,D/5},{A/2,B/3,C/4,D/6,E/9}}{
\begin{tikzpicture}
\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};}
\end{tikzpicture}
}
\end{document}


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

• 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? Jun 18 at 12:57
• 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.) Jun 18 at 12:59
• Thanks for your help Jun 18 at 13:02
• Seriously, making sense of this code is probably harder than starting from scratch. Jun 18 at 13:02

• 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.
\documentclass[border=3.141592=12mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning,
quotes}
\pgfmathsetseed{\pdfuniformdeviate 10000000}

\begin{document}
\begin{tikzpicture}[
dot/.style = {circle, fill, inner sep=1pt, outer sep=0pt},
ang/.style = {draw=red, <->,
angle eccentricity=1.2,
}
]
\pgfmathsetmacro{\r}{2}
\pgfmathsetmacro{\R}{\r+0.3}
% circle
% 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
\draw[cyan]
(A) -- (B) -- (C) -- (A);           % draw trangle
\end{tikzpicture}
\end{document}


An random result is (it is different after each compilation, is this what you after?): • Thank you so much, and your comments have helped me understand what is going on. I owe you a drink. Jun 18 at 20:14

Another pedagogical (I hope) example:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=1.5]
% 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)}]
(0,0)--(4,4)--(8,0)--(4,-4)--(0,0);
% fix a circular zone where to place the Euler picture
\begin{scope}
\path [clip] (4,0) circle (2.9);
\node at (4,0) () {\includegraphics[width=10cm]{Euler.png}};
\end{scope}
%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$};
\end{tikzpicture}
\end{document}


The output: Two more examples:

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc,snakes}
\usetikzlibrary{ decorations.markings}

\begin{document}
\begin{tikzpicture}[scale=.6]
%muretto
\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);
\end{tikzpicture}

\vspace{3cm}

\begin{tikzpicture}[scale=1.1]
\filldraw[snake=snake,blue,line width=1pt]
(0,0)--(4,4)--(8,0)--(4,-4)--(0,0);
\filldraw[blue] (4,0) circle(3.25);
\node[blue] at (4,0) () {\Huge \bfseries $e^{i\pi}+1=0$}; 