33

I would like to use LaTeX to draw a spiral like the one below, but it's way out of my league. Any help would be much appreciated. original image

NEW EDIT: (now with a better 3d look!) after playing a bit with Jasper Habicht's solution, this was the best I could get up to now. I'm pretty happy. Thank you!

spiral-final

My customized version of Jasper Habicht's solution! (Give him a “up” vote!)

% Credits to Jasper Habicht (See below)
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
  
\definecolor{mygreencolor}{RGB}{133,196,96}  

\begin{tikzpicture}

\pgfmathsetmacro\maxradius{.3}
\pgfmathsetmacro\inner{10}
\pgfmathsetmacro\outer{40}
\pgfmathsetmacro\range{\outer-\inner}

\foreach \stepy in {\inner, ..., \outer}
    \pgfmathsetmacro\stepstart{60/\stepy}
    \pgfmathsetmacro\steplast{360-\stepstart}
    \pgfmathsetmacro\stepcount{floor(360/\stepstart)} 
    \foreach \stepx in {0, \stepstart, ..., \steplast}
        \pgfmathsetmacro\stepsingle{floor(\stepx/\stepstart)}
        \pgfmathsetmacro\stepradius{(\maxradius/2)*sin(deg(\stepsingle*pi/(\stepcount/2) - pi - (\stepy/5))) + (\maxradius/2)+0.13}
        \pgfmathsetmacro\mybase{90*(\stepy-\inner)/\range)}
        \pgfmathsetmacro\mycoef{((1-cos(\mybase)+sin(\mybase))/2}
        \pgfmathsetmacro\mystepy{\inner+\range*\mycoef}
        \fill[mygreencolor] ({-(\stepx+.25*\stepcount)}:-\mystepy mm) circle (\stepradius mm);

\end{tikzpicture}

\end{document}
1
  • 1
    +1: Nice question. Many of your questions do not have an accepted answer. Please consider to accept answers if your question was answered. – Dr. Manuel Kuehner Apr 11 at 0:01
50
+50

A different approach that also needs a lot of fine tuning.

What does it do? It draws several rings consisting of a varying number of small circles and increases the number of small circles as the radii of the rings grow in such a way that the distribution of the small circles is eventually relatively even. The radii of the small circles are calculated using a sine-wave function that commutes between a radius of zero and 0.5 mm. The sine wave also gets a shift for each of the rings in order to produce the spiral effect.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

\pgfmathsetmacro\maxradius{.5}

\foreach \stepy in {10, ..., 30}
    \pgfmathsetmacro\stepstart{60/\stepy}
    \pgfmathsetmacro\steplast{360-\stepstart}
    \pgfmathsetmacro\stepcount{floor(360/\stepstart)}
    \foreach \stepx in {0, \stepstart, ..., \steplast}
        \pgfmathsetmacro\stepsingle{floor(\stepx/\stepstart)}
        \pgfmathsetmacro\stepradius{(\maxradius/2)*cos(deg(\stepsingle*pi/(\stepcount/2) - pi - (\stepy/5))) + (\maxradius/2)}
        \fill[green] (\stepx:\stepy mm) circle (\stepradius mm);

\end{tikzpicture}

\end{document}

enter image description here


Edited to give it a more of a 3D effect:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

\pgfmathsetmacro\maxradius{.5}

\foreach \stepy in {10, ..., 30}
    \pgfmathsetmacro\stepstart{60/\stepy}
    \pgfmathsetmacro\steplast{360-\stepstart}
    \pgfmathsetmacro\stepcount{floor(360/\stepstart)}
    \foreach \stepx in {0, \stepstart, ..., \steplast}
        \pgfmathsetmacro\stepsingle{floor(\stepx/\stepstart)}
        \pgfmathsetmacro\stepradius{(\maxradius/2)*cos(deg(\stepsingle*pi/(\stepcount/2) - pi - (\stepy/5))) + (\maxradius/2)}
        \fill[green] ({\stepx+.25*\stepcount}:\stepy mm) circle (\stepradius mm);

\end{tikzpicture}

\end{document}

enter image description here

In the original picture, the inner circles are smaller and closer together. I guess, it is not too difficult to achieve this effect.

3
  • Jasper Habicht, thanks a lot for your solution. it is almost perfect for me. How can I make the inner radius smaller? – João Lourenço Feb 22 at 20:02
  • You can change \foreach \stepy in {10, ..., 30} to \foreach \stepy in {5, ..., 30}, that is, decrease the first number or increase the last one. The more steps (or circles) there are, the longer it will take to compile though. – Jasper Habicht Feb 22 at 20:04
  • Very nice. Excellent. +1 – Sebastiano Feb 22 at 21:08
22

Here is a brief example that will probably require several adjustments. I add a commented spiral that I use as a reference.

\documentclass[tikz, border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}[line cap=round]
  \foreach\a in {0,2,...,359}       % angle to put each cricle (polar coordinates)
  {
    \pgfmathsetmacro\s{2.5+\a/90}   % theoretical point of the spiral (radius, polar coordinates)
    \foreach\r in {2.5,2.6,...,6.5} % radius to put each circle (polar coordinates)
    {
      \pgfmathsetmacro\w{0.1+0.5/(1+abs(\s-\r))} % width of the circles
      \fill[green] (\a:\r) circle (\w mm);
    }
    % Reference spiral:
    %\fill (\a:\s) circle (0.05);
  }
\end{tikzpicture}
\end{document}

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.