I want to make a short article explaining the origin of the Golden Number (1+sqrt(5))/2
and I need to draw a very simple segment like the picture I've uploaded. Any suggestions?
[Tex/LaTex] How to do a simple TikZ picture of the golden ratio
tikz-pgf
Related Solutions
You can do that with two loops: one running from 1 to n-1, the other from the current value of the first to n. Here an example for six:
Code
\documentclass[tikz,convert=false]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5,auto=left,every node/.style={circle,fill=black!20}]
\foreach \x in {1,...,6}
{ \node (n\x) at (\x*60:3) {\x};
}
\foreach \x in {1,...,5}
{ \pgfmathtruncatemacro{\lowerbound}{\x+1}
\foreach \y in {\lowerbound,...,6}
{ \draw (n\x) -- (n\y);
% for labelled edges
%\draw (n\x) -- (n\y) node[sloped,pos=0.39,fill=white,fill opacity=0.3,above=0.1mm,rectangle, inner sep=0.1mm] {\tiny \x-\y};
}
}
\end{tikzpicture}
\end{document}
Output
Output with labels
Bonus homework: adapted for 36 nodes
With arc
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw[dashed] (0,0) arc (170:10:2cm and 0.4cm)coordinate[pos=0] (a);
\draw (0,0) arc (-170:-10:2cm and 0.4cm)coordinate (b);
\draw[densely dashed] ([yshift=4cm]$(a)!0.5!(b)$) -- node[right,font=\footnotesize] {$h$}coordinate[pos=0.95] (aa)($(a)!0.5!(b)$)
-- node[above,font=\footnotesize] {$r$}coordinate[pos=0.1] (bb) (b);
\draw (aa) -| (bb);
\draw (a) -- ([yshift=4cm]$(a)!0.5!(b)$) -- (b);
\end{tikzpicture}
\end{document}
With ellipse
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-2,0) rectangle (2,1cm);
\draw[dashed] (0,0) circle(2cm and 0.35cm);
\end{scope}
\begin{scope}
\clip (-2,0) rectangle (2,-1cm);
\draw (0,0) circle(2cm and 0.35cm);
\end{scope}
\draw[densely dashed] (0,4) -- node[right,font=\footnotesize] {$h$}coordinate[pos=0.95] (aa)(0,0)
-- node[above,font=\footnotesize] {$r$}coordinate[pos=0.1] (bb) (2,0);
\draw (aa) -| (bb);
\draw (-2,0) -- (0,4) -- (2,0);
\end{tikzpicture}
\end{document}
Gonzalo has kindly provided the shadings to the cylinder and I am reproducing his code (with thanks):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadings}
\begin{document}
\begin{tikzpicture}
\fill[
top color=gray!50,
bottom color=gray!10,
shading=axis,
opacity=0.25
]
(0,0) circle (2cm and 0.5cm);
\fill[
left color=gray!50!black,
right color=gray!50!black,
middle color=gray!50,
shading=axis,
opacity=0.25
]
(2,0) -- (0,6) -- (-2,0) arc (180:360:2cm and 0.5cm);
\draw
(-2,0) arc (180:360:2cm and 0.5cm) -- (0,6) -- cycle;
\draw[dashed]
(-2,0) arc (180:0:2cm and 0.5cm);
\draw[dashed]
(2,0) -- node[below] {$r$} (0,0) -- node[left] {h} (0,6) ;
\draw
(0,8pt) -- ++(8pt,0) -- (8pt,0);
\end{tikzpicture}
\end{document}
Best Answer
Two TikZ suggestions.